Skip to content

Commit 2a4aaa9

Browse files
fix: emit 'shutdown' outside -[NSApplication terminate:] (electron#24140)
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
1 parent 793da44 commit 2a4aaa9

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

shell/browser/mac/electron_application.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
base::scoped_nsobject<NSUserActivity> currentActivity_;
1818
NSCondition* handoffLock_;
1919
BOOL updateReceived_;
20+
BOOL userStoppedShutdown_;
2021
base::Callback<bool()> shouldShutdown_;
2122
}
2223

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

29+
// Called when macOS itself is shutting down.
30+
- (void)willPowerOff:(NSNotification*)notify;
31+
2832
// CrAppProtocol:
2933
- (BOOL)isHandlingSendEvent;
3034

shell/browser/mac/electron_application.mm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ + (AtomApplication*)sharedApplication {
4141
return (AtomApplication*)[super sharedApplication];
4242
}
4343

44+
- (void)willPowerOff:(NSNotification*)notify {
45+
userStoppedShutdown_ = shouldShutdown_ && !shouldShutdown_.Run();
46+
}
47+
4448
- (void)terminate:(id)sender {
45-
if (shouldShutdown_ && !shouldShutdown_.Run())
46-
return; // User will call Quit later.
49+
// User will call Quit later.
50+
if (userStoppedShutdown_)
51+
return;
4752

4853
// We simply try to close the browser, which in turn will try to close the
4954
// windows. Termination can proceed if all windows are closed or window close

shell/browser/mac/electron_application_delegate.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,22 @@ - (void)setApplicationDockMenu:(electron::ElectronMenuModel*)model {
4848
useDefaultAccelerator:NO]);
4949
}
5050

51+
- (void)willPowerOff:(NSNotification*)notify {
52+
[[AtomApplication sharedApplication] willPowerOff:notify];
53+
}
54+
5155
- (void)applicationWillFinishLaunching:(NSNotification*)notify {
5256
// Don't add the "Enter Full Screen" menu item automatically.
5357
[[NSUserDefaults standardUserDefaults]
5458
setBool:NO
5559
forKey:@"NSFullScreenMenuItemEverywhere"];
5660

61+
[[[NSWorkspace sharedWorkspace] notificationCenter]
62+
addObserver:self
63+
selector:@selector(willPowerOff:)
64+
name:NSWorkspaceWillPowerOffNotification
65+
object:nil];
66+
5767
electron::Browser::Get()->WillFinishLaunching();
5868
}
5969

0 commit comments

Comments
 (0)