fix: potential crash calling tray.popUpContextMenu() (#39231)

fix: potential crash calling tray.popUpContextMenu
This commit is contained in:
Shelley Vohr 2023-08-01 08:07:30 +02:00 committed by GitHub
parent c8f7a0e052
commit 1f19a74417
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 20 deletions

View file

@ -83,6 +83,11 @@
[self removeTrackingArea:trackingArea_];
trackingArea_ = nil;
}
// Ensure any open menu is closed.
if ([statusItem_ menu])
[[statusItem_ menu] cancelTracking];
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem_];
[self removeFromSuperview];
statusItem_ = nil;
@ -228,7 +233,6 @@
if (menuController_ && ![menuController_ isMenuOpen]) {
// Ensure the UI can update while the menu is fading out.
base::ScopedPumpMessagesInPrivateModes pump_private;
[[statusItem_ button] performClick:self];
}
}
@ -354,16 +358,16 @@ bool TrayIconCocoa::GetIgnoreDoubleClickEvents() {
return [status_item_view_ getIgnoreDoubleClickEvents];
}
void TrayIconCocoa::PopUpOnUI(ElectronMenuModel* menu_model) {
[status_item_view_ popUpContextMenu:menu_model];
void TrayIconCocoa::PopUpOnUI(base::WeakPtr<ElectronMenuModel> menu_model) {
[status_item_view_ popUpContextMenu:menu_model.get()];
}
void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
raw_ptr<ElectronMenuModel> menu_model) {
void TrayIconCocoa::PopUpContextMenu(
const gfx::Point& pos,
base::WeakPtr<ElectronMenuModel> menu_model) {
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&TrayIconCocoa::PopUpOnUI, weak_factory_.GetWeakPtr(),
base::Unretained(menu_model)));
FROM_HERE, base::BindOnce(&TrayIconCocoa::PopUpOnUI,
weak_factory_.GetWeakPtr(), menu_model));
}
void TrayIconCocoa::CloseContextMenu() {