Skip to content

Commit 23e9688

Browse files
trop[bot]rf-figma
andauthored
fix: restore SelfKeepAlive in Menu (#52278)
This fixes #52247 by ensuring that a `Menu` instance will stay alive as long as the menu is open, even if its owner has cleared or replaced it. It's a (very) partial revert of 9be03cb, which removed this `keep_alive_` property because it was thought to be unnecessary. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Ryan Fitzgerald <[email protected]>
1 parent 015e7a6 commit 23e9688

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎shell/browser/api/electron_api_menu.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,11 @@ bool Menu::WorksWhenHiddenAt(int index) const {
301301

302302
void Menu::OnMenuWillClose() {
303303
Emit("menu-will-close");
304+
keep_alive_.Clear();
304305
}
305306

306307
void Menu::OnMenuWillShow() {
308+
keep_alive_ = this;
307309
Emit("menu-will-show");
308310
}
309311

‎shell/browser/api/electron_api_menu.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "shell/browser/event_emitter_mixin.h"
1313
#include "shell/browser/ui/electron_menu_model.h"
1414
#include "shell/common/gin_helper/constructible.h"
15+
#include "shell/common/gin_helper/self_keep_alive.h"
1516
#include "ui/base/mojom/menu_source_type.mojom-forward.h"
1617
#include "v8/include/cppgc/member.h"
1718

@@ -139,6 +140,9 @@ class Menu : public gin::Wrappable<Menu>,
139140

140141
std::unique_ptr<ElectronMenuModel> model_;
141142
cppgc::Member<Menu> parent_;
143+
144+
// Keep active menus alive even if they've been replaced.
145+
gin_helper::SelfKeepAlive<Menu> keep_alive_{nullptr};
142146
};
143147

144148
} // namespace electron::api

0 commit comments

Comments
 (0)