From 63f7692da55829bc6c08ee6fbccc81672e409dee Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 5 Feb 2026 10:57:47 -0500 Subject: [PATCH] fix: menu state in macOS dock menus (#49626) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- shell/browser/mac/electron_application_delegate.mm | 9 ++++++++- shell/browser/ui/cocoa/electron_menu_controller.h | 4 ++++ shell/browser/ui/cocoa/electron_menu_controller.mm | 2 -- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/shell/browser/mac/electron_application_delegate.mm b/shell/browser/mac/electron_application_delegate.mm index 9f947f4933..7ab2741aa1 100644 --- a/shell/browser/mac/electron_application_delegate.mm +++ b/shell/browser/mac/electron_application_delegate.mm @@ -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 { diff --git a/shell/browser/ui/cocoa/electron_menu_controller.h b/shell/browser/ui/cocoa/electron_menu_controller.h index 489f42ad77..b0f104215d 100644 --- a/shell/browser/ui/cocoa/electron_menu_controller.h +++ b/shell/browser/ui/cocoa/electron_menu_controller.h @@ -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; diff --git a/shell/browser/ui/cocoa/electron_menu_controller.mm b/shell/browser/ui/cocoa/electron_menu_controller.mm index 7c58fb44f9..81bfad9463 100644 --- a/shell/browser/ui/cocoa/electron_menu_controller.mm +++ b/shell/browser/ui/cocoa/electron_menu_controller.mm @@ -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];