diff --git a/shell/browser/mac/electron_application.h b/shell/browser/mac/electron_application.h index a9d1817b4e6e6..074d9c20be50b 100644 --- a/shell/browser/mac/electron_application.h +++ b/shell/browser/mac/electron_application.h @@ -17,6 +17,7 @@ base::scoped_nsobject currentActivity_; NSCondition* handoffLock_; BOOL updateReceived_; + BOOL userStoppedShutdown_; base::Callback shouldShutdown_; } @@ -25,6 +26,9 @@ - (void)setShutdownHandler:(base::Callback)handler; - (void)registerURLHandler; +// Called when macOS itself is shutting down. +- (void)willPowerOff:(NSNotification*)notify; + // CrAppProtocol: - (BOOL)isHandlingSendEvent; diff --git a/shell/browser/mac/electron_application.mm b/shell/browser/mac/electron_application.mm index 4b6408652bddf..ac732190fdb80 100644 --- a/shell/browser/mac/electron_application.mm +++ b/shell/browser/mac/electron_application.mm @@ -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 diff --git a/shell/browser/mac/electron_application_delegate.mm b/shell/browser/mac/electron_application_delegate.mm index 57de325d7bb66..73da6ec7c5153 100644 --- a/shell/browser/mac/electron_application_delegate.mm +++ b/shell/browser/mac/electron_application_delegate.mm @@ -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(); }