diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/ui/ClipeveryTheme.kt b/composeApp/src/commonMain/kotlin/com/clipevery/ui/ClipeveryTheme.kt index 56867705b..cf225ed5b 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/ui/ClipeveryTheme.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/ui/ClipeveryTheme.kt @@ -61,6 +61,8 @@ interface ThemeDetector { isFollowSystem: Boolean, isUserInDark: Boolean = false, ) + + fun addListener(listener: (Boolean) -> Unit) } fun Color.darken(amount: Float): Color { diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/ui/DesktopThemeDetector.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/ui/DesktopThemeDetector.kt index 5facfa15f..cbb790514 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/ui/DesktopThemeDetector.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/ui/DesktopThemeDetector.kt @@ -16,9 +16,15 @@ class DesktopThemeDetector(private val configManager: ConfigManager) : ThemeDete private var _isUserInDark: Boolean by mutableStateOf(configManager.config.isDarkTheme) + private val listeners: MutableList<(Boolean) -> Unit> = mutableListOf() + init { detector.registerListener { isDark: Boolean -> _isSystemInDark = isDark + + for (listener in listeners) { + listener(isCurrentThemeDark()) + } } } @@ -41,5 +47,12 @@ class DesktopThemeDetector(private val configManager: ConfigManager) : ThemeDete _isFollowSystem = isFollowSystem _isUserInDark = isUserInDark configManager.updateConfig { it.copy(isFollowSystemTheme = isFollowSystem, isDarkTheme = isUserInDark) } + for (listener in listeners) { + listener(isCurrentThemeDark()) + } + } + + override fun addListener(listener: (Boolean) -> Unit) { + listeners.add(listener) } } diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/ui/LinuxTrayView.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/ui/LinuxTrayView.kt index 3ca680294..7eb639e32 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/ui/LinuxTrayView.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/ui/LinuxTrayView.kt @@ -21,9 +21,23 @@ object LinuxTrayView { exitApplication: () -> Unit, ) { val appWindowManager = koinApplication.koin.get() + val themeDetector = koinApplication.koin.get() val resourceUtils = getResourceUtils() - systemTray.setImage(resourceUtils.resourceInputStream("icon/clipevery.tray.linux.png")) + themeDetector.addListener { + if (it) { + systemTray.setImage(resourceUtils.resourceInputStream("icon/clipevery.tray.linux.dark.png")) + } else { + systemTray.setImage(resourceUtils.resourceInputStream("icon/clipevery.tray.linux.light.png")) + } + } + + if (themeDetector.isCurrentThemeDark()) { + systemTray.setImage(resourceUtils.resourceInputStream("icon/clipevery.tray.linux.dark.png")) + } else { + systemTray.setImage(resourceUtils.resourceInputStream("icon/clipevery.tray.linux.light.png")) + } + systemTray.setTooltip("Clipevery") systemTray.menu?.add( MenuItem("Open Clipevery") { diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/ui/WindowsTrayView.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/ui/WindowsTrayView.kt index f134b8139..de82bdafa 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/ui/WindowsTrayView.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/ui/WindowsTrayView.kt @@ -48,9 +48,15 @@ fun WindowsTray() { val current = LocalKoinApplication.current val appWindowManager = current.koin.get() + val themeDetector = current.koin.get() val notificationManager = current.koin.get() - val trayIcon = painterResource("icon/clipevery.tray.win.png") + val trayIcon = + if (themeDetector.isCurrentThemeDark()) { + painterResource("icon/clipevery.tray.win.dark.png") + } else { + painterResource("icon/clipevery.tray.win.light.png") + } var showMenu by remember { mutableStateOf(false) } diff --git a/composeApp/src/desktopMain/resources/icon/clipevery.tray.linux.dark.png b/composeApp/src/desktopMain/resources/icon/clipevery.tray.linux.dark.png new file mode 100644 index 000000000..714b35b4e Binary files /dev/null and b/composeApp/src/desktopMain/resources/icon/clipevery.tray.linux.dark.png differ diff --git a/composeApp/src/desktopMain/resources/icon/clipevery.tray.linux.png b/composeApp/src/desktopMain/resources/icon/clipevery.tray.linux.light.png similarity index 100% rename from composeApp/src/desktopMain/resources/icon/clipevery.tray.linux.png rename to composeApp/src/desktopMain/resources/icon/clipevery.tray.linux.light.png diff --git a/composeApp/src/desktopMain/resources/icon/clipevery.tray.win.dark.png b/composeApp/src/desktopMain/resources/icon/clipevery.tray.win.dark.png new file mode 100644 index 000000000..714b35b4e Binary files /dev/null and b/composeApp/src/desktopMain/resources/icon/clipevery.tray.win.dark.png differ diff --git a/composeApp/src/desktopMain/resources/icon/clipevery.tray.win.png b/composeApp/src/desktopMain/resources/icon/clipevery.tray.win.light.png similarity index 100% rename from composeApp/src/desktopMain/resources/icon/clipevery.tray.win.png rename to composeApp/src/desktopMain/resources/icon/clipevery.tray.win.light.png