Skip to content

Commit

Permalink
🐛 [win] [Linux] Icon displays poorly in the taskbar (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang authored Jun 15, 2024
1 parent af935d7 commit 38be979
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ interface ThemeDetector {
isFollowSystem: Boolean,
isUserInDark: Boolean = false,
)

fun addListener(listener: (Boolean) -> Unit)
}

fun Color.darken(amount: Float): Color {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}

Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,23 @@ object LinuxTrayView {
exitApplication: () -> Unit,
) {
val appWindowManager = koinApplication.koin.get<AppWindowManager>()
val themeDetector = koinApplication.koin.get<ThemeDetector>()
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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ fun WindowsTray() {
val current = LocalKoinApplication.current

val appWindowManager = current.koin.get<AppWindowManager>()
val themeDetector = current.koin.get<ThemeDetector>()
val notificationManager = current.koin.get<NotificationManager>()

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) }

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 38be979

Please sign in to comment.