From a95eb8c111c65e10efcd3617eb1265673e44a523 Mon Sep 17 00:00:00 2001 From: Alexander Maryanovsky Date: Wed, 7 Feb 2024 13:31:57 +0200 Subject: [PATCH] Call `Library.load()` before calling native getCurrentSystemTheme function. (#866) --- .../kotlin/org/jetbrains/skiko/SystemTheme.awt.kt | 11 +++++++---- .../kotlin/org/jetbrains/skiko/LibraryLoadedTest.kt | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 skiko/src/awtTest/kotlin/org/jetbrains/skiko/LibraryLoadedTest.kt diff --git a/skiko/src/awtMain/kotlin/org/jetbrains/skiko/SystemTheme.awt.kt b/skiko/src/awtMain/kotlin/org/jetbrains/skiko/SystemTheme.awt.kt index 5f727b289..174f2679f 100644 --- a/skiko/src/awtMain/kotlin/org/jetbrains/skiko/SystemTheme.awt.kt +++ b/skiko/src/awtMain/kotlin/org/jetbrains/skiko/SystemTheme.awt.kt @@ -1,10 +1,13 @@ package org.jetbrains.skiko actual val currentSystemTheme: SystemTheme - get() = when (getCurrentSystemTheme()) { - 0 -> SystemTheme.LIGHT - 1 -> SystemTheme.DARK - else -> SystemTheme.UNKNOWN + get() { + Library.load() + return when (getCurrentSystemTheme()) { + 0 -> SystemTheme.LIGHT + 1 -> SystemTheme.DARK + else -> SystemTheme.UNKNOWN + } } // Common diff --git a/skiko/src/awtTest/kotlin/org/jetbrains/skiko/LibraryLoadedTest.kt b/skiko/src/awtTest/kotlin/org/jetbrains/skiko/LibraryLoadedTest.kt new file mode 100644 index 000000000..76ab1b412 --- /dev/null +++ b/skiko/src/awtTest/kotlin/org/jetbrains/skiko/LibraryLoadedTest.kt @@ -0,0 +1,13 @@ +package org.jetbrains.skiko + +import org.junit.Test + +/** + * Verifies that the native Skiko library is correctly loaded in various scenarios. + */ +class LibraryLoadedTest { + @Test + fun getSystemTheme() { + currentSystemTheme + } +} \ No newline at end of file