Skip to content

Commit 8181742

Browse files
committed
Fix tray icon not appearing on Windows 10 (#350)
- Guard tray_enable_dark_mode() with SEH in native code to catch access violations from the undocumented uxtheme.dll ordinal 135 - Catch Throwable (not just Exception) in WindowsTrayManager tray thread - Move initLatch.countDown() into finally block so the calling thread is never deadlocked and can fall back to AWT gracefully
1 parent 9639a29 commit 8181742

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/commonMain/kotlin/com/kdroid/composetray/lib/windows/WindowsTrayManager.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,21 @@ internal class WindowsTrayManager(
107107
tray.set(newTray)
108108
initialized.set(true)
109109

110-
// Signal that initialization is complete
110+
// Signal that initialization is complete before entering the loop
111111
initLatch.countDown()
112112

113113
// Run the blocking message loop on this thread
114114
runMessageLoop()
115115

116-
} catch (e: Exception) {
116+
} catch (e: Throwable) {
117117
log("Error in tray thread: ${e.message}")
118118
e.printStackTrace()
119-
initLatch.countDown() // Ensure latch is released even on error
120119
} finally {
120+
// Safety net: release latch in case an Error prevented the
121+
// countDown above from being reached. CountDownLatch.countDown()
122+
// is a no-op when the count is already 0, so calling it twice
123+
// on the success path is harmless.
124+
initLatch.countDown()
121125
cleanupTray()
122126
}
123127
}.apply {

winlib

0 commit comments

Comments
 (0)