Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emit 'shutdown' outside -[NSApplication terminate:] #24141

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions shell/browser/mac/electron_application.h
Expand Up @@ -17,6 +17,7 @@
base::scoped_nsobject<NSUserActivity> currentActivity_;
NSCondition* handoffLock_;
BOOL updateReceived_;
BOOL userStoppedShutdown_;
base::Callback<bool()> shouldShutdown_;
}

Expand All @@ -25,6 +26,9 @@
- (void)setShutdownHandler:(base::Callback<bool()>)handler;
- (void)registerURLHandler;

// Called when macOS itself is shutting down.
- (void)willPowerOff:(NSNotification*)notify;

// CrAppProtocol:
- (BOOL)isHandlingSendEvent;

Expand Down
9 changes: 7 additions & 2 deletions shell/browser/mac/electron_application.mm
Expand Up @@ -41,9 +41,14 @@ + (AtomApplication*)sharedApplication {
return (AtomApplication*)[super sharedApplication];
}

- (void)willPowerOff:(NSNotification*)notify {
userStoppedShutdown_ = shouldShutdown_ && !shouldShutdown_.Run();
}

- (void)terminate:(id)sender {
if (shouldShutdown_ && !shouldShutdown_.Run())
return; // User will call Quit later.
// User will call Quit later.
if (userStoppedShutdown_)
return;

// We simply try to close the browser, which in turn will try to close the
// windows. Termination can proceed if all windows are closed or window close
Expand Down
10 changes: 10 additions & 0 deletions shell/browser/mac/electron_application_delegate.mm
Expand Up @@ -48,12 +48,22 @@ - (void)setApplicationDockMenu:(electron::ElectronMenuModel*)model {
useDefaultAccelerator:NO]);
}

- (void)willPowerOff:(NSNotification*)notify {
[[AtomApplication sharedApplication] willPowerOff:notify];
}

- (void)applicationWillFinishLaunching:(NSNotification*)notify {
// Don't add the "Enter Full Screen" menu item automatically.
[[NSUserDefaults standardUserDefaults]
setBool:NO
forKey:@"NSFullScreenMenuItemEverywhere"];

[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector:@selector(willPowerOff:)
name:NSWorkspaceWillPowerOffNotification
object:nil];

electron::Browser::Get()->WillFinishLaunching();
}

Expand Down