Skip to content

Commit c2c1d40

Browse files
fix: only call popup closecallback for top-level menu (#49045)
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <[email protected]>
1 parent 0e9decd commit c2c1d40

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

shell/browser/ui/cocoa/electron_menu_controller.mm

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -563,16 +563,22 @@ - (void)menuWillOpen:(NSMenu*)menu {
563563
}
564564

565565
- (void)menuDidClose:(NSMenu*)menu {
566-
if (isMenuOpen_) {
567-
isMenuOpen_ = NO;
568-
if (model_)
569-
model_->MenuWillClose();
570-
// Post async task so that itemSelected runs before the close callback
571-
// deletes the controller from the map which deallocates it
572-
if (!closeCallback.is_null()) {
573-
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE,
574-
std::move(closeCallback));
575-
}
566+
// If the menu is already closed, do nothing.
567+
if (!isMenuOpen_)
568+
return;
569+
570+
// We should only respond to the top-level menu's close event.
571+
if (menu != menu_)
572+
return;
573+
574+
isMenuOpen_ = NO;
575+
if (model_)
576+
model_->MenuWillClose();
577+
// Post async task so that itemSelected runs before the close callback
578+
// deletes the controller from the map which deallocates it
579+
if (!closeCallback.is_null()) {
580+
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE,
581+
std::move(closeCallback));
576582
}
577583
}
578584

0 commit comments

Comments
 (0)