Add "quit" event for app.

This commit is contained in:
Cheng Zhao 2014-09-25 21:47:54 +08:00
parent dbbfef38b1
commit 909ff085ac
5 changed files with 14 additions and 0 deletions

View file

@ -91,6 +91,10 @@ void App::OnWindowAllClosed() {
Emit("window-all-closed"); Emit("window-all-closed");
} }
void App::OnQuit() {
Emit("quit");
}
void App::OnOpenFile(bool* prevent_default, const std::string& file_path) { void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
base::ListValue args; base::ListValue args;
args.AppendString(file_path); args.AppendString(file_path);

View file

@ -36,6 +36,7 @@ class App : public mate::EventEmitter,
// BrowserObserver implementations: // BrowserObserver implementations:
virtual void OnWillQuit(bool* prevent_default) OVERRIDE; virtual void OnWillQuit(bool* prevent_default) OVERRIDE;
virtual void OnWindowAllClosed() OVERRIDE; virtual void OnWindowAllClosed() OVERRIDE;
virtual void OnQuit() OVERRIDE;
virtual void OnOpenFile(bool* prevent_default, virtual void OnOpenFile(bool* prevent_default,
const std::string& file_path) OVERRIDE; const std::string& file_path) OVERRIDE;
virtual void OnOpenURL(const std::string& url) OVERRIDE; virtual void OnOpenURL(const std::string& url) OVERRIDE;

View file

@ -37,6 +37,8 @@ void Browser::Quit() {
} }
void Browser::Shutdown() { void Browser::Shutdown() {
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit());
is_quiting_ = true; is_quiting_ = true;
base::MessageLoop::current()->Quit(); base::MessageLoop::current()->Quit();
} }

View file

@ -18,6 +18,9 @@ class BrowserObserver {
// method will not be called, instead it will call OnWillQuit. // method will not be called, instead it will call OnWillQuit.
virtual void OnWindowAllClosed() {} virtual void OnWindowAllClosed() {}
// The browser is quitting.
virtual void OnQuit() {}
// The browser has opened a file by double clicking in Finder or dragging the // The browser has opened a file by double clicking in Finder or dragging the
// file to the Dock icon. (OS X only) // file to the Dock icon. (OS X only)
virtual void OnOpenFile(bool* prevent_default, virtual void OnOpenFile(bool* prevent_default,

View file

@ -45,6 +45,10 @@ terminating the application.
See description of `window-all-closed` for the differences between `will-quit` See description of `window-all-closed` for the differences between `will-quit`
and it. and it.
## Event: quit
Emitted when application is quitting.
## Event: open-file ## Event: open-file
* `event` Event * `event` Event