Implement shutdown event for macOS
This commit is contained in:
parent
c470e758cc
commit
983e1b1a70
7 changed files with 25 additions and 6 deletions
|
@ -2,8 +2,9 @@
|
|||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "base/mac/scoped_sending_event.h"
|
||||
#import "base/mac/scoped_nsobject.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/mac/scoped_sending_event.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
|
||||
@interface AtomApplication : NSApplication<CrAppProtocol,
|
||||
CrAppControlProtocol,
|
||||
|
@ -13,10 +14,13 @@
|
|||
base::scoped_nsobject<NSUserActivity> currentActivity_;
|
||||
NSCondition* handoffLock_;
|
||||
BOOL updateReceived_;
|
||||
base::Callback<bool()> shouldShutdown_;
|
||||
}
|
||||
|
||||
+ (AtomApplication*)sharedApplication;
|
||||
|
||||
- (void)setShutdownHandler:(base::Callback<bool()>)handler;
|
||||
|
||||
// CrAppProtocol:
|
||||
- (BOOL)isHandlingSendEvent;
|
||||
|
||||
|
|
|
@ -29,10 +29,16 @@ inline void dispatch_sync_main(dispatch_block_t block) {
|
|||
}
|
||||
|
||||
- (void)terminate:(id)sender {
|
||||
if (shouldShutdown_ && !shouldShutdown_.Run())
|
||||
return; // User will call Quit later.
|
||||
AtomApplicationDelegate* atomDelegate = (AtomApplicationDelegate*) [NSApp delegate];
|
||||
[atomDelegate tryToTerminateApp:self];
|
||||
}
|
||||
|
||||
- (void)setShutdownHandler:(base::Callback<bool()>)handler {
|
||||
shouldShutdown_ = std::move(handler);
|
||||
}
|
||||
|
||||
- (BOOL)isHandlingSendEvent {
|
||||
return handlingSendEvent_;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue