diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index cf935f89930..751293ee41a 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -489,8 +489,8 @@ void App::OnWillFinishLaunching() { Emit("will-finish-launching"); } -void App::OnFinishLaunching() { - Emit("ready"); +void App::OnFinishLaunching(const base::DictionaryValue& launch_info) { + Emit("ready", launch_info); } void App::OnAccessibilitySupportChanged() { diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 187aba184ab..13641d04c26 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -73,7 +73,7 @@ class App : public AtomBrowserClient::Delegate, void OnOpenURL(const std::string& url) override; void OnActivate(bool has_visible_windows) override; void OnWillFinishLaunching() override; - void OnFinishLaunching() override; + void OnFinishLaunching(const base::DictionaryValue& launch_info) override; void OnLogin(LoginHandler* login_handler, const base::DictionaryValue& request_details) override; void OnAccessibilitySupportChanged() override; diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index 6c2f18be0f6..e160eb7c0ce 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -156,7 +156,8 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { #if !defined(OS_MACOSX) // The corresponding call in macOS is in AtomApplicationDelegate. Browser::Get()->WillFinishLaunching(); - Browser::Get()->DidFinishLaunching(); + std::unique_ptr<base::DictionaryValue> empty_info(new base::DictionaryValue); + Browser::Get()->DidFinishLaunching(*empty_info); #endif } diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 6c3edc0d6e3..b227b6b8159 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -148,14 +148,15 @@ void Browser::WillFinishLaunching() { FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching()); } -void Browser::DidFinishLaunching() { +void Browser::DidFinishLaunching(const base::DictionaryValue& launch_info) { // Make sure the userData directory is created. base::FilePath user_data; if (PathService::Get(brightray::DIR_USER_DATA, &user_data)) base::CreateDirectoryAndGetError(user_data, nullptr); is_ready_ = true; - FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching()); + FOR_EACH_OBSERVER(BrowserObserver, observers_, + OnFinishLaunching(launch_info)); } void Browser::OnAccessibilitySupportChanged() { diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 924685510f7..5bb2500b663 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -184,7 +184,7 @@ class Browser : public WindowListObserver { // Tell the application the loading has been done. void WillFinishLaunching(); - void DidFinishLaunching(); + void DidFinishLaunching(const base::DictionaryValue& launch_info); void OnAccessibilitySupportChanged(); diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index 54617e5e09f..88a50a93a7e 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -46,7 +46,7 @@ class BrowserObserver { // The browser has finished loading. virtual void OnWillFinishLaunching() {} - virtual void OnFinishLaunching() {} + virtual void OnFinishLaunching(const base::DictionaryValue& launch_info) {} // The browser requests HTTP login. virtual void OnLogin(LoginHandler* login_handler, diff --git a/atom/browser/mac/atom_application_delegate.mm b/atom/browser/mac/atom_application_delegate.mm index e77bd125201..4c6a938fba5 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -25,7 +25,16 @@ } - (void)applicationDidFinishLaunching:(NSNotification*)notify { - atom::Browser::Get()->DidFinishLaunching(); + NSUserNotification *user_notification = [notify userInfo][(id)@"NSApplicationLaunchUserNotificationKey"]; + + if (user_notification.userInfo != nil) { + std::unique_ptr<base::DictionaryValue> launch_info = + atom::NSDictionaryToDictionaryValue(user_notification.userInfo); + atom::Browser::Get()->DidFinishLaunching(*launch_info); + } else { + std::unique_ptr<base::DictionaryValue> empty_info(new base::DictionaryValue); + atom::Browser::Get()->DidFinishLaunching(*empty_info); + } } - (NSMenu*)applicationDockMenu:(NSApplication*)sender { @@ -64,7 +73,7 @@ continueUserActivity:(NSUserActivity*)userActivity restorationHandler:(void (^)(NSArray*restorableObjects))restorationHandler { std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType)); std::unique_ptr<base::DictionaryValue> user_info = - atom::NSDictionaryToDictionaryValue(userActivity.userInfo); + atom::NSDictionaryToDictionaryValue(userActivity.userInfo); if (!user_info) return NO; diff --git a/docs/api/app.md b/docs/api/app.md index 8fa186e66fb..46e494144cd 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -28,7 +28,13 @@ In most cases, you should just do everything in the `ready` event handler. ### Event: 'ready' -Emitted when Electron has finished initialization. +Returns: + +* `launchInfo` Object _macOS_ + +Emitted when Electron has finished initialization. On macOS, `launchInfo` holds +the `userInfo` of the `NSUserNotification` that was used to open the application, +if it was launched from Notification Center. ### Event: 'window-all-closed'