From 909ff085ac4fc87f41df1ed57f98a1125c586fd2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 25 Sep 2014 21:47:54 +0800 Subject: [PATCH] Add "quit" event for app. --- atom/browser/api/atom_api_app.cc | 4 ++++ atom/browser/api/atom_api_app.h | 1 + atom/browser/browser.cc | 2 ++ atom/browser/browser_observer.h | 3 +++ docs/api/app.md | 4 ++++ 5 files changed, 14 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 858e6ef197..7331b66a80 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -91,6 +91,10 @@ void App::OnWindowAllClosed() { Emit("window-all-closed"); } +void App::OnQuit() { + Emit("quit"); +} + void App::OnOpenFile(bool* prevent_default, const std::string& file_path) { base::ListValue args; args.AppendString(file_path); diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 0fcbf2c0a9..2afa563558 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -36,6 +36,7 @@ class App : public mate::EventEmitter, // BrowserObserver implementations: virtual void OnWillQuit(bool* prevent_default) OVERRIDE; virtual void OnWindowAllClosed() OVERRIDE; + virtual void OnQuit() OVERRIDE; virtual void OnOpenFile(bool* prevent_default, const std::string& file_path) OVERRIDE; virtual void OnOpenURL(const std::string& url) OVERRIDE; diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index afea053c66..9f31177d31 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -37,6 +37,8 @@ void Browser::Quit() { } void Browser::Shutdown() { + FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit()); + is_quiting_ = true; base::MessageLoop::current()->Quit(); } diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index 0f340b0079..df0243abe5 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -18,6 +18,9 @@ class BrowserObserver { // method will not be called, instead it will call OnWillQuit. virtual void OnWindowAllClosed() {} + // The browser is quitting. + virtual void OnQuit() {} + // The browser has opened a file by double clicking in Finder or dragging the // file to the Dock icon. (OS X only) virtual void OnOpenFile(bool* prevent_default, diff --git a/docs/api/app.md b/docs/api/app.md index 0f585f5e52..b9a837d77b 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -45,6 +45,10 @@ terminating the application. See description of `window-all-closed` for the differences between `will-quit` and it. +## Event: quit + +Emitted when application is quitting. + ## Event: open-file * `event` Event