```plugins { id "org.jetbrains.kotlin.jvm" ver...
# compose-desktop
u
Copy code
plugins {
    id "org.jetbrains.kotlin.jvm" version "2.2.20"
    id "org.jetbrains.kotlin.plugin.compose" version "2.2.20"
    id "org.jetbrains.compose" version "1.9.1"
}

//
//
//
fun main(args: Array<String>) = singleWindowApplication {
    AppTheme {
        ...
    }
}

@Composable
fun AppTheme(content: @Composable () -> Unit) {
    MaterialTheme(
        colors = if (isSystemInDarkTheme()) { <-----------------------
            darkColors()
        } else {
            lightColors()
        },
    ) {
        Surface(color = MaterialTheme.colors.background, content = content)
    }
}
Why is the compose desktop app not reacting to dark mode changes? I'm testing on
mac os
and
windows
, and when I toggle the system setting it does nothing. After restart it picks up the current setting but not during runtime. Is this known?
z
Long standing issue and I'd encourage you to check the issue tracker: https://youtrack.jetbrains.com/issue/CMP-6028/Implement-isSystemInDarkTheme-for-desktop
a
You can use something like
Copy code
@Composable
fun isSystemThemeDark() = produceState(initialValue = currentSystemTheme == org.jetbrains.skiko.SystemTheme.DARK) {
    launch(<http://Dispatchers.IO|Dispatchers.IO>) {
        while (true) {
            delay(1000)
            value = currentSystemTheme == org.jetbrains.skiko.SystemTheme.DARK
        }
    }
}.value
K 1
u
If you may, the underlying issue that the such seemingly trivial feature is missing is due to swing not exposing a listener-shaped api?
a
Swing doesn’t provide anything here, it’s all native calls.
u
okay so the underlying window tech (?) or is it just a matter of time/priorities?
a
Priority, mostly, as there’s a simple workaround.
u
yes but it's polling, more resources than needed, IF there is a callback based api available but thanks!
u