profiles: print message on profile save

This commit is contained in:
Bixilon 2023-05-23 20:48:43 +02:00
parent cb121b115b
commit 5b4da9c4f1
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -181,6 +181,7 @@ interface ProfileManager<T : Profile> {
profile.ignoreReloads.incrementAndGet() profile.ignoreReloads.incrementAndGet()
FileUtil.safeSaveToFile(file, jsonString) FileUtil.safeSaveToFile(file, jsonString)
profile.saved = true profile.saved = true
Log.log(LogMessageType.PROFILES, LogLevels.VERBOSE) { "Saved profile ${profile.name} ($namespace)" }
} catch (exception: Exception) { } catch (exception: Exception) {
exception.printStackTrace() exception.printStackTrace()
exception.crash() exception.crash()
@ -257,13 +258,14 @@ interface ProfileManager<T : Profile> {
} }
fun watchProfile(profileName: String, path: File = getPath(profileName).toFile()) { fun watchProfile(profileName: String, path: File = getPath(profileName).toFile()) {
FileWatcherService.register(FileWatcher(path.toPath(), arrayOf(StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE)) { _, it -> FileWatcherService.register(FileWatcher(path.toPath(), arrayOf(StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE)) { a, _ ->
val profile = profiles[profileName] ?: return@FileWatcher val profile = profiles[profileName] ?: return@FileWatcher
if (profile.ignoreReloads.get() > 0) { if (profile.ignoreReloads.get() > 0) {
profile.ignoreReloads.decrementAndGet() profile.ignoreReloads.decrementAndGet()
return@FileWatcher return@FileWatcher
} }
try { try {
profile.reloading = true
val data = readAndMigrate(path.toPath()).second val data = readAndMigrate(path.toPath()).second
updateValue(profile, data) updateValue(profile, data)
} catch (exception: Exception) { } catch (exception: Exception) {
@ -272,7 +274,7 @@ interface ProfileManager<T : Profile> {
} finally { } finally {
profile.reloading = false profile.reloading = false
} }
Log.log(LogMessageType.PROFILES, LogLevels.INFO) { "Reloaded profile: $profileName ($it)" } Log.log(LogMessageType.PROFILES, LogLevels.INFO) { "Reloaded profile: $profileName ($namespace);" }
}) })
} }