Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call Library.load() before calling native getCurrentSystemTheme() #866

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions skiko/src/awtMain/kotlin/org/jetbrains/skiko/SystemTheme.awt.kt
Original file line number Diff line number Diff line change
@@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be called on each call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say "shouldn't" (Library.load protects against being called multiple times), but yes, it's slightly faster not to.

return when (getCurrentSystemTheme()) {
0 -> SystemTheme.LIGHT
1 -> SystemTheme.DARK
else -> SystemTheme.UNKNOWN
}
}

// Common
Expand Down
13 changes: 13 additions & 0 deletions skiko/src/awtTest/kotlin/org/jetbrains/skiko/LibraryLoadedTest.kt
Original file line number Diff line number Diff line change
@@ -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
}
}