Skip to content

Commit 9df769d

Browse files
committed
Fix submenus not syncing with main context menu appearance
- Add updateMenuAppearance() helper to recursively update menu and all submenus - Replace direct appearance assignments with recursive updates - Ensures all submenu levels match the system theme Fixes issue where submenus remained in the wrong appearance when the system theme changed.
1 parent 07275e8 commit 9df769d

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

maclib/tray.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private class MenuBarAppearanceObserver {
116116
// Update menu appearance for all contexts
117117
if let ptr = trayPtr, let ctx = contexts[ptr] {
118118
if let menu = ctx.contextMenu {
119-
menu.appearance = systemAppearance()
119+
updateMenuAppearance(menu, to: systemAppearance())
120120
}
121121
}
122122
}
@@ -146,7 +146,7 @@ private class MenuBarAppearanceObserver {
146146

147147
// Update menu appearance to match the system theme (not menu bar)
148148
if let menu = ctx.contextMenu {
149-
menu.appearance = systemAppearance()
149+
updateMenuAppearance(menu, to: systemAppearance())
150150
}
151151
}
152152

@@ -188,6 +188,18 @@ private func systemAppearance() -> NSAppearance {
188188
let appearanceName: NSAppearance.Name = isDarkMode ? .darkAqua : .aqua
189189
return NSAppearance(named: appearanceName) ?? NSApp.effectiveAppearance
190190
}
191+
192+
/// Updates the appearance of a menu and all its submenus recursively
193+
private func updateMenuAppearance(_ menu: NSMenu, to appearance: NSAppearance) {
194+
menu.appearance = appearance
195+
196+
// Recursively update all submenus
197+
for item in menu.items {
198+
if let submenu = item.submenu {
199+
updateMenuAppearance(submenu, to: appearance)
200+
}
201+
}
202+
}
191203
private func nativeMenu(from menuPtr: UnsafeMutableRawPointer, statusItem: NSStatusItem? = nil) -> NSMenu {
192204
let menu = NSMenu()
193205
menu.autoenablesItems = false

0 commit comments

Comments
 (0)