fix: emit 'shutdown' outside -[NSApplication terminate:] (#24111)
This commit is contained in:
parent
0b830ba9e5
commit
9c7d73c6d6
3 changed files with 21 additions and 2 deletions
|
@ -17,6 +17,7 @@
|
||||||
base::scoped_nsobject<NSUserActivity> currentActivity_;
|
base::scoped_nsobject<NSUserActivity> currentActivity_;
|
||||||
NSCondition* handoffLock_;
|
NSCondition* handoffLock_;
|
||||||
BOOL updateReceived_;
|
BOOL updateReceived_;
|
||||||
|
BOOL userStoppedShutdown_;
|
||||||
base::Callback<bool()> shouldShutdown_;
|
base::Callback<bool()> shouldShutdown_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +26,9 @@
|
||||||
- (void)setShutdownHandler:(base::Callback<bool()>)handler;
|
- (void)setShutdownHandler:(base::Callback<bool()>)handler;
|
||||||
- (void)registerURLHandler;
|
- (void)registerURLHandler;
|
||||||
|
|
||||||
|
// Called when macOS itself is shutting down.
|
||||||
|
- (void)willPowerOff:(NSNotification*)notify;
|
||||||
|
|
||||||
// CrAppProtocol:
|
// CrAppProtocol:
|
||||||
- (BOOL)isHandlingSendEvent;
|
- (BOOL)isHandlingSendEvent;
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,14 @@ inline void dispatch_sync_main(dispatch_block_t block) {
|
||||||
return (AtomApplication*)[super sharedApplication];
|
return (AtomApplication*)[super sharedApplication];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)willPowerOff:(NSNotification*)notify {
|
||||||
|
userStoppedShutdown_ = shouldShutdown_ && !shouldShutdown_.Run();
|
||||||
|
}
|
||||||
|
|
||||||
- (void)terminate:(id)sender {
|
- (void)terminate:(id)sender {
|
||||||
if (shouldShutdown_ && !shouldShutdown_.Run())
|
// User will call Quit later.
|
||||||
return; // User will call Quit later.
|
if (userStoppedShutdown_)
|
||||||
|
return;
|
||||||
|
|
||||||
// We simply try to close the browser, which in turn will try to close the
|
// 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
|
// windows. Termination can proceed if all windows are closed or window close
|
||||||
|
|
|
@ -48,12 +48,22 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
|
||||||
useDefaultAccelerator:NO]);
|
useDefaultAccelerator:NO]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)willPowerOff:(NSNotification*)notify {
|
||||||
|
[[AtomApplication sharedApplication] willPowerOff:notify];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)applicationWillFinishLaunching:(NSNotification*)notify {
|
- (void)applicationWillFinishLaunching:(NSNotification*)notify {
|
||||||
// Don't add the "Enter Full Screen" menu item automatically.
|
// Don't add the "Enter Full Screen" menu item automatically.
|
||||||
[[NSUserDefaults standardUserDefaults]
|
[[NSUserDefaults standardUserDefaults]
|
||||||
setBool:NO
|
setBool:NO
|
||||||
forKey:@"NSFullScreenMenuItemEverywhere"];
|
forKey:@"NSFullScreenMenuItemEverywhere"];
|
||||||
|
|
||||||
|
[[[NSWorkspace sharedWorkspace] notificationCenter]
|
||||||
|
addObserver:self
|
||||||
|
selector:@selector(willPowerOff:)
|
||||||
|
name:NSWorkspaceWillPowerOffNotification
|
||||||
|
object:nil];
|
||||||
|
|
||||||
electron::Browser::Get()->WillFinishLaunching();
|
electron::Browser::Get()->WillFinishLaunching();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue