Include exit code with quit event
This commit is contained in:
parent
aa82eddca8
commit
92433be888
10 changed files with 19 additions and 14 deletions
|
@ -180,8 +180,8 @@ void App::OnWindowAllClosed() {
|
|||
Emit("window-all-closed");
|
||||
}
|
||||
|
||||
void App::OnQuit() {
|
||||
Emit("quit");
|
||||
void App::OnQuit(const int code) {
|
||||
Emit("quit", code);
|
||||
|
||||
if (process_singleton_.get()) {
|
||||
process_singleton_->Cleanup();
|
||||
|
@ -344,7 +344,7 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
|||
auto browser = base::Unretained(Browser::Get());
|
||||
return mate::ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
|
||||
.SetMethod("_exit", base::Bind(&Browser::Exit, browser))
|
||||
.SetMethod("exit", base::Bind(&Browser::Exit, browser))
|
||||
.SetMethod("focus", base::Bind(&Browser::Focus, browser))
|
||||
.SetMethod("getVersion", base::Bind(&Browser::GetVersion, browser))
|
||||
.SetMethod("setVersion", base::Bind(&Browser::SetVersion, browser))
|
||||
|
|
|
@ -42,7 +42,7 @@ class App : public AtomBrowserClient::Delegate,
|
|||
void OnBeforeQuit(bool* prevent_default) override;
|
||||
void OnWillQuit(bool* prevent_default) override;
|
||||
void OnWindowAllClosed() override;
|
||||
void OnQuit() override;
|
||||
void OnQuit(int code) override;
|
||||
void OnOpenFile(bool* prevent_default, const std::string& file_path) override;
|
||||
void OnOpenURL(const std::string& url) override;
|
||||
void OnActivate(bool has_visible_windows) override;
|
||||
|
|
|
@ -34,17 +34,12 @@ app.setAppPath = (path) ->
|
|||
app.getAppPath = ->
|
||||
appPath
|
||||
|
||||
appExitCode = undefined
|
||||
app.exit = (exitCode) ->
|
||||
appExitCode = exitCode
|
||||
app._exit(exitCode)
|
||||
|
||||
# Map process.exit to app.exit, which quits gracefully.
|
||||
process.exit = app.exit
|
||||
|
||||
# Emit a process 'exit' event on app quit.
|
||||
app.on 'quit', ->
|
||||
process.emit 'exit', appExitCode
|
||||
app.on 'quit', (event, exitCode) ->
|
||||
process.emit 'exit', exitCode
|
||||
|
||||
# Routes the events to webContents.
|
||||
for name in ['login', 'certificate-error', 'select-client-certificate']
|
||||
|
|
|
@ -61,6 +61,10 @@ bool AtomBrowserMainParts::SetExitCode(int code) {
|
|||
return true;
|
||||
}
|
||||
|
||||
int AtomBrowserMainParts::GetExitCode() {
|
||||
return exit_code_ != nullptr ? *exit_code_ : 0;
|
||||
}
|
||||
|
||||
base::Closure AtomBrowserMainParts::RegisterDestructionCallback(
|
||||
const base::Closure& callback) {
|
||||
auto iter = destructors_.insert(destructors_.end(), callback);
|
||||
|
|
|
@ -34,6 +34,9 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
|||
// Sets the exit code, will fail if the the message loop is not ready.
|
||||
bool SetExitCode(int code);
|
||||
|
||||
// Gets the exit code
|
||||
int GetExitCode();
|
||||
|
||||
// Register a callback that should be destroyed before JavaScript environment
|
||||
// gets destroyed.
|
||||
// Returns a closure that can be used to remove |callback| from the list.
|
||||
|
|
|
@ -72,7 +72,8 @@ void Browser::Shutdown() {
|
|||
is_shutdown_ = true;
|
||||
is_quiting_ = true;
|
||||
|
||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit());
|
||||
int exitCode = AtomBrowserMainParts::Get()->GetExitCode();
|
||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit(exitCode));
|
||||
|
||||
if (base::MessageLoop::current()) {
|
||||
base::MessageLoop::current()->PostTask(
|
||||
|
|
|
@ -24,7 +24,7 @@ class BrowserObserver {
|
|||
virtual void OnWindowAllClosed() {}
|
||||
|
||||
// The browser is quitting.
|
||||
virtual void OnQuit() {}
|
||||
virtual void OnQuit(const int code) {}
|
||||
|
||||
// The browser has opened a file by double clicking in Finder or dragging the
|
||||
// file to the Dock icon. (OS X only)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue