Skip to content

Commit ee42b17

Browse files
authored
Merge pull request #354 from kdroidFilter/fix/macos-menu-bar-dark-mode-detection
Fix macOS isMenuBarInDarkMode returning true in light mode
2 parents 3b32c9f + 511fcf2 commit ee42b17

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

maclib/tray.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,18 @@ public func tray_set_theme_callback(_ cb: @escaping ThemeCallback) {
303303

304304
@_cdecl("tray_is_menu_dark")
305305
public func tray_is_menu_dark() -> Int32 {
306+
if !Thread.isMainThread {
307+
return DispatchQueue.main.sync { tray_is_menu_dark() }
308+
}
306309
let ctx = trayInstance.flatMap { contexts[$0] } ?? contexts.values.first
307-
guard let button = ctx?.statusItem.button else { return 1 }
308-
guard let name = button.effectiveAppearance.bestMatch(from: [NSAppearance.Name.darkAqua, NSAppearance.Name.aqua]) else {
309-
return 1 // assume dark if unknown
310+
let appearance: NSAppearance
311+
if let button = ctx?.statusItem.button {
312+
appearance = button.effectiveAppearance
313+
} else {
314+
appearance = NSApp.effectiveAppearance
315+
}
316+
guard let name = appearance.bestMatch(from: [.darkAqua, .aqua]) else {
317+
return 1
310318
}
311319
return name == .darkAqua ? 1 : 0
312320
}

0 commit comments

Comments
 (0)