Skip to content

Commit

Permalink
Improve logging [save/load componets]
Browse files Browse the repository at this point in the history
  • Loading branch information
sghpjuikit committed Dec 7, 2024
1 parent d89c4b2 commit 775a9e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/player/main/sp/it/pl/layout/ComponentStates.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package sp.it.pl.layout

import io.github.oshai.kotlinlogging.KotlinLogging
import java.io.File
import java.util.UUID
import javafx.geometry.Orientation
import javafx.geometry.Pos
import sp.it.pl.core.logger
import sp.it.pl.main.APP
import sp.it.pl.main.AppError
import sp.it.pl.main.ifErrorNotify
Expand All @@ -14,6 +16,7 @@ import sp.it.util.file.writeTextTry
import sp.it.util.functional.orNull
import sp.it.util.text.splitNoEmpty

private val logger = KotlinLogging.logger { }
private val json = APP.serializerJson.json

/**[Component.toDb] or [NoComponentDb] */
Expand All @@ -27,6 +30,7 @@ fun Component?.toDb(): ComponentDb = this?.toDb() ?: NoComponentDb
* See [File.loadComponentFxwlJson]
*/
fun Component?.exportFxwl(f: File) = runVT {
logger.info { "Exporting component to file=$f" }
APP.serializerJson.toJson(toDb(), f).ifErrorNotify {
AppError(
"Unable to export component launcher for ${this?.name} into ${f}.",
Expand All @@ -37,6 +41,7 @@ fun Component?.exportFxwl(f: File) = runVT {

/** Creates a launcher for this widget with default (none predefined) settings. */
fun Widget.exportFxwlDefault(f: File) = runVT {
logger.info { "Exporting default widget launcher to file=$f" }
f.writeTextTry(factory.id).ifErrorNotify {
AppError(
"Unable to export default widget launcher for $name into $f.",
Expand All @@ -50,6 +55,7 @@ fun Widget.exportFxwlDefault(f: File) = runVT {
* See [Component.exportFxwl]
*/
fun File.loadComponentFxwlJson() = runVT {
logger.info { "Loading component from file=$this" }
json.fromJson<ComponentDb>(this).ifErrorNotify {
AppError(
"Unable to load component launcher from $this.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import sp.it.pl.layout.WidgetIoManager
import sp.it.pl.layout.WidgetUse.NEW
import sp.it.pl.layout.deduplicateIds
import sp.it.pl.layout.exportFxwl
import sp.it.pl.layout.loadComponentFxwlJson
import sp.it.pl.main.APP
import sp.it.pl.main.AppSettings.plugins.screenDock as confDock
import sp.it.pl.main.AppSettings.ui.window as confWindow
Expand Down Expand Up @@ -83,6 +84,7 @@ import sp.it.util.action.IsAction
import sp.it.util.animation.Anim.Companion.anim
import sp.it.util.async.coroutine.FX
import sp.it.util.async.coroutine.VT
import sp.it.util.async.coroutine.await
import sp.it.util.async.coroutine.launch
import sp.it.util.async.future.Fut
import sp.it.util.async.runFX
Expand Down Expand Up @@ -716,7 +718,7 @@ class WindowManager: GlobalSubConfigDelegator(confWindow.name) {

when (id) {
null -> null
"" -> APP.serializerJson.fromJson<ComponentDb>(launcher).orNull()?.deduplicateIds()?.toDomain()?.apply { fileDeserializing = launcher }
"" -> launcher.loadComponentFxwlJson().await()?.apply { fileDeserializing = launcher }
else -> instantiateComponent(id)
}
}
Expand Down

0 comments on commit 775a9e0

Please sign in to comment.