isSystemInDarkTheme() this composable not work in ...
# multiplatform
m
isSystemInDarkTheme() this composable not work in desktop. i have mac os i try change mac system theme but can not be observe change isSystemInDarkTheme(). it issue.
current i use this library for desktop version it work it https://github.com/Dansoftowner/jSystemThemeDetector
m
Ok
I made a special module for this, you can use it directly. It is easier to use than jsystemthemedetector but above all, it does not relay on polling under Linux
m
yes thanks for sharing
👍 1
currently i use this. but i know it not work linux . its ok
Copy code
@Composable
actual fun isSystemInDarkThemeMode(): Boolean {
    val detector by remember {
        mutableStateOf(
            OsThemeDetector.getDetector()
        )
    }
    val isSupported by remember(detector) {
        derivedStateOf {
            OsThemeDetector.isSupported()
        }
    }
    val isDark by remember(detector.isDark) {
        derivedStateOf {
            detector.isDark
        }
    }
    val isSystemThemeByFoundationLib = isSystemInDarkTheme()

    var isSystemInDarkTheme by rememberSaveable(isDark,isSystemThemeByFoundationLib) {
        mutableStateOf(
            if (isSupported) {
                detector.isDark
            } else {
                isSystemThemeByFoundationLib
            }
        )
    }

    DisposableEffect(isSystemInDarkTheme) {
        val listener = Consumer<Boolean> {
            if (isSupported) {
                isSystemInDarkTheme = it
            }
        }
        detector.registerListener(listener)
        onDispose {
            detector.removeListener(listener)
        }
    }
    return isSystemInDarkTheme
}
u
Try my module, i've checked it on KDE and Gnome
m
yes i see it your code great job
🙏 1
@אליהו הדס just one suggestion in any repo try to add screenshot or video. developer atleast see it how looks like which platform work it.
@zsmb Thanks for sharing link
u
@Meet I should take the time to do it.
👍 1