From bf409efc468db27d8b5dc248a0606b1375c95f73 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 3 Jun 2013 15:31:46 +0800 Subject: [PATCH] Add 'will-finish-launching' event for app. --- browser/api/atom_api_app.cc | 4 ++++ browser/api/atom_api_app.h | 1 + browser/atom_application_delegate_mac.mm | 4 ++++ browser/atom_browser_main_parts.cc | 1 + browser/browser.cc | 4 ++++ browser/browser.h | 1 + browser/browser_observer.h | 1 + 7 files changed, 16 insertions(+) diff --git a/browser/api/atom_api_app.cc b/browser/api/atom_api_app.cc index ca49b6212a36..385b540bf4f1 100644 --- a/browser/api/atom_api_app.cc +++ b/browser/api/atom_api_app.cc @@ -36,6 +36,10 @@ void App::OnOpenFile(bool* prevent_default, const std::string& file_path) { *prevent_default = Emit("open-file", &args); } +void App::OnWillFinishLaunching() { + Emit("will-finish-launching"); +} + void App::OnFinishLaunching() { Emit("finish-launching"); } diff --git a/browser/api/atom_api_app.h b/browser/api/atom_api_app.h index f718b6678b8d..1192081676c0 100644 --- a/browser/api/atom_api_app.h +++ b/browser/api/atom_api_app.h @@ -28,6 +28,7 @@ class App : public EventEmitter, virtual void OnWindowAllClosed() OVERRIDE; virtual void OnOpenFile(bool* prevent_default, const std::string& file_path) OVERRIDE; + virtual void OnWillFinishLaunching() OVERRIDE; virtual void OnFinishLaunching() OVERRIDE; private: diff --git a/browser/atom_application_delegate_mac.mm b/browser/atom_application_delegate_mac.mm index 16b8da72bed5..83fecfeb3c03 100644 --- a/browser/atom_application_delegate_mac.mm +++ b/browser/atom_application_delegate_mac.mm @@ -10,6 +10,10 @@ @implementation AtomApplicationDelegate +- (void)applicationWillFinishLaunching:(NSNotification*)notify { + atom::Browser::Get()->WillFinishLaunching(); +} + - (void)applicationDidFinishLaunching:(NSNotification*)notify { // Trap the quit message to handleQuitEvent. NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; diff --git a/browser/atom_browser_main_parts.cc b/browser/atom_browser_main_parts.cc index f2fdfc20773a..31fe68f34d5b 100644 --- a/browser/atom_browser_main_parts.cc +++ b/browser/atom_browser_main_parts.cc @@ -72,6 +72,7 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { #if !defined(OS_MACOSX) // The corresponding call in OS X is in AtomApplicationDelegate. + Browser::Get()->WillFinishLaunching(); Browser::Get()->DidFinishLaunching(); #endif } diff --git a/browser/browser.cc b/browser/browser.cc index e2327effadc2..290d4133201c 100644 --- a/browser/browser.cc +++ b/browser/browser.cc @@ -41,6 +41,10 @@ bool Browser::OpenFile(const std::string& file_path) { return prevent_default; } +void Browser::WillFinishLaunching() { + FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching()); +} + void Browser::DidFinishLaunching() { FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching()); } diff --git a/browser/browser.h b/browser/browser.h index 6f700b4b5a8a..bf879a3753cc 100644 --- a/browser/browser.h +++ b/browser/browser.h @@ -34,6 +34,7 @@ class Browser : public WindowListObserver { bool OpenFile(const std::string& file_path); // Tell the application the loading has been done. + void WillFinishLaunching(); void DidFinishLaunching(); void AddObserver(BrowserObserver* obs) { diff --git a/browser/browser_observer.h b/browser/browser_observer.h index 690d5463bbbf..fb46b677e703 100644 --- a/browser/browser_observer.h +++ b/browser/browser_observer.h @@ -24,6 +24,7 @@ class BrowserObserver { const std::string& file_path) {} // The browser has finished loading. + virtual void OnWillFinishLaunching() {} virtual void OnFinishLaunching() {} protected: