fix: menu state in macOS dock menus (#49574)

This commit is contained in:
Shelley Vohr
2026-02-02 23:01:34 +01:00
committed by GitHub
parent db5606b4b3
commit 3776731f4a
3 changed files with 12 additions and 3 deletions

View File

@@ -109,7 +109,14 @@ static NSDictionary* UNNotificationResponseToNSDictionary(
}
- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
return menu_controller_ ? menu_controller_.menu : nil;
if (!menu_controller_)
return nil;
// Manually refresh menu state since menuWillOpen: is not called
// by macOS for dock menus for some reason before they are displayed.
NSMenu* menu = menu_controller_.menu;
[menu_controller_ refreshMenuTree:menu];
return menu;
}
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename {

View File

@@ -57,6 +57,10 @@ class ElectronMenuModel;
// Whether the menu is currently open.
- (BOOL)isMenuOpen;
// Recursively refreshes the menu tree starting from |menu|, applying the
// model state (enabled, checked, hidden etc) to each menu item.
- (void)refreshMenuTree:(NSMenu*)menu;
// NSMenuDelegate methods this class implements. Subclasses should call super
// if extending the behavior.
- (void)menuWillOpen:(NSMenu*)menu;

View File

@@ -493,8 +493,6 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
: NSControlStateValueOff;
}
// Recursively refreshes the menu tree starting from |menu|, applying the
// model state to each menu item.
- (void)refreshMenuTree:(NSMenu*)menu {
for (NSMenuItem* item in menu.itemArray) {
[self applyStateToMenuItem:item];