From 1e54d27ffedff36a45d5664f4f742a99ada2385e Mon Sep 17 00:00:00 2001 From: 90 Date: Sun, 24 Mar 2024 14:04:26 +0000 Subject: [PATCH 1/2] Switch from ~/.skiko directory to OS-specific locations (%LOCALAPPDATA%, $XDG_DATA_HOME etc.) --- .../org/jetbrains/skiko/SkikoProperties.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt index cf06a066c..b6f742b16 100644 --- a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt +++ b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt @@ -1,5 +1,6 @@ package org.jetbrains.skiko +import java.lang.System.getenv import java.lang.System.getProperty // TODO maybe we can get rid of global properties, and pass SkiaLayerProperties to Window -> ComposeWindow -> SkiaLayer @@ -29,8 +30,22 @@ object SkikoProperties { * The path where to store data files. * * It is used for extracting the Skiko binaries (if `libraryPath` isn't null) and logging. + * + * TODO: Use $XDG_STATE_HOME (Unix) / ~/Library/Logs (macOS) for logging instead? */ - val dataPath: String get() = getProperty("skiko.data.path") ?: "${getProperty("user.home")}/.skiko/" + val dataPath: String get() { + return getProperty("skiko.data.path") ?: when (hostOs) { + OS.Windows -> "${getenv("LOCALAPPDATA")}/Skiko" + OS.MacOS, OS.Ios -> "${getProperty("user.home")}/Library/Application Support/Skiko" + else -> { + var dataHome = getenv("XDG_DATA_HOME") + if (dataHome == null || !dataHome.startsWith('/')) { + dataHome = "${getProperty("user.home")}/.local/share" + } + return "${dataHome}/skiko" + } + } + } val vsyncEnabled: Boolean get() = getProperty("skiko.vsync.enabled")?.toBoolean() ?: true @@ -54,7 +69,7 @@ object SkikoProperties { val fpsLongFramesMillis: Double? get() = getProperty("skiko.fps.longFrames.millis")?.toDouble() val renderApi: GraphicsApi get() { - val environment = System.getenv("SKIKO_RENDER_API") + val environment = getenv("SKIKO_RENDER_API") val property = getProperty("skiko.renderApi") return parseRenderApi(environment ?: property) } From fdb37fca225c560bed70ae9dd9b12e0d898531a7 Mon Sep 17 00:00:00 2001 From: 90 Date: Sun, 24 Mar 2024 16:57:51 +0000 Subject: [PATCH 2/2] Separate log files according to XDG spec and macOS dir names --- .../skiko/RenderExceptionsHandler.kt | 2 +- .../org/jetbrains/skiko/SkikoProperties.kt | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/skiko/src/awtMain/kotlin/org/jetbrains/skiko/RenderExceptionsHandler.kt b/skiko/src/awtMain/kotlin/org/jetbrains/skiko/RenderExceptionsHandler.kt index f14b1ece5..ad1a1606e 100644 --- a/skiko/src/awtMain/kotlin/org/jetbrains/skiko/RenderExceptionsHandler.kt +++ b/skiko/src/awtMain/kotlin/org/jetbrains/skiko/RenderExceptionsHandler.kt @@ -18,7 +18,7 @@ internal class RenderExceptionsHandler { try { if (output == null) { output = File( - "${SkikoProperties.dataPath}/skiko-render-exception-${ProcessHandle.current().pid()}.log" + "${SkikoProperties.logPath}/skiko-render-exception-${ProcessHandle.current().pid()}.log" ) output!!.parentFile.mkdirs() } diff --git a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt index b6f742b16..636d509b9 100644 --- a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt +++ b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt @@ -29,9 +29,7 @@ object SkikoProperties { /** * The path where to store data files. * - * It is used for extracting the Skiko binaries (if `libraryPath` isn't null) and logging. - * - * TODO: Use $XDG_STATE_HOME (Unix) / ~/Library/Logs (macOS) for logging instead? + * It is used for extracting the Skiko binaries (if `libraryPath` isn't null). */ val dataPath: String get() { return getProperty("skiko.data.path") ?: when (hostOs) { @@ -47,6 +45,23 @@ object SkikoProperties { } } + /** + * The path where to store log files. + */ + val logPath: String get() { + return getProperty("skiko.data.path") ?: when (hostOs) { + OS.Windows -> "${getenv("LOCALAPPDATA")}/Skiko" + OS.MacOS, OS.Ios -> "${getProperty("user.home")}/Library/Logs/Skiko" + else -> { + var stateHome = getenv("XDG_STATE_HOME") + if (stateHome == null || !stateHome.startsWith('/')) { + stateHome = "${getProperty("user.home")}/.local/state" + } + return "${stateHome}/skiko" + } + } + } + val vsyncEnabled: Boolean get() = getProperty("skiko.vsync.enabled")?.toBoolean() ?: true /**