Send notification userInfo to app.ready, on macOS.

Check if the user launched the app from a notification and send the notification args across if so.
This commit is contained in:
Charlie Hess 2016-08-31 17:17:44 -07:00
parent a37544cef4
commit af9e010162
7 changed files with 20 additions and 10 deletions

View file

@ -274,8 +274,8 @@ void App::OnWillFinishLaunching() {
Emit("will-finish-launching"); Emit("will-finish-launching");
} }
void App::OnFinishLaunching() { void App::OnFinishLaunching(const base::DictionaryValue& launch_info) {
Emit("ready"); Emit("ready", launch_info);
} }
void App::OnAccessibilitySupportChanged() { void App::OnAccessibilitySupportChanged() {

View file

@ -69,7 +69,7 @@ class App : public AtomBrowserClient::Delegate,
void OnOpenURL(const std::string& url) override; void OnOpenURL(const std::string& url) override;
void OnActivate(bool has_visible_windows) override; void OnActivate(bool has_visible_windows) override;
void OnWillFinishLaunching() override; void OnWillFinishLaunching() override;
void OnFinishLaunching() override; void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
void OnLogin(LoginHandler* login_handler, void OnLogin(LoginHandler* login_handler,
const base::DictionaryValue& request_details) override; const base::DictionaryValue& request_details) override;
void OnAccessibilitySupportChanged() override; void OnAccessibilitySupportChanged() override;

View file

@ -156,7 +156,8 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
// The corresponding call in macOS is in AtomApplicationDelegate. // The corresponding call in macOS is in AtomApplicationDelegate.
Browser::Get()->WillFinishLaunching(); Browser::Get()->WillFinishLaunching();
Browser::Get()->DidFinishLaunching(); base::DictionaryValue* empty_info = new base::DictionaryValue();
Browser::Get()->DidFinishLaunching(empty_info);
#endif #endif
} }

View file

@ -148,14 +148,14 @@ void Browser::WillFinishLaunching() {
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching()); FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching());
} }
void Browser::DidFinishLaunching() { void Browser::DidFinishLaunching(const base::DictionaryValue& launch_info) {
// Make sure the userData directory is created. // Make sure the userData directory is created.
base::FilePath user_data; base::FilePath user_data;
if (PathService::Get(brightray::DIR_USER_DATA, &user_data)) if (PathService::Get(brightray::DIR_USER_DATA, &user_data))
base::CreateDirectoryAndGetError(user_data, nullptr); base::CreateDirectoryAndGetError(user_data, nullptr);
is_ready_ = true; is_ready_ = true;
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching()); FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching(launch_info));
} }
void Browser::OnAccessibilitySupportChanged() { void Browser::OnAccessibilitySupportChanged() {

View file

@ -184,7 +184,7 @@ class Browser : public WindowListObserver {
// Tell the application the loading has been done. // Tell the application the loading has been done.
void WillFinishLaunching(); void WillFinishLaunching();
void DidFinishLaunching(); void DidFinishLaunching(const base::DictionaryValue& launch_info);
void OnAccessibilitySupportChanged(); void OnAccessibilitySupportChanged();

View file

@ -46,7 +46,7 @@ class BrowserObserver {
// The browser has finished loading. // The browser has finished loading.
virtual void OnWillFinishLaunching() {} virtual void OnWillFinishLaunching() {}
virtual void OnFinishLaunching() {} virtual void OnFinishLaunching(const base::DictionaryValue& launch_info) {}
// The browser requests HTTP login. // The browser requests HTTP login.
virtual void OnLogin(LoginHandler* login_handler, virtual void OnLogin(LoginHandler* login_handler,

View file

@ -25,7 +25,16 @@
} }
- (void)applicationDidFinishLaunching:(NSNotification*)notify { - (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 {
base::DictionaryValue* launch_info = new base::DictionaryValue();
atom::Browser::Get()->DidFinishLaunching(*launch_info);
}
} }
- (NSMenu*)applicationDockMenu:(NSApplication*)sender { - (NSMenu*)applicationDockMenu:(NSApplication*)sender {
@ -64,7 +73,7 @@ continueUserActivity:(NSUserActivity*)userActivity
restorationHandler:(void (^)(NSArray*restorableObjects))restorationHandler { restorationHandler:(void (^)(NSArray*restorableObjects))restorationHandler {
std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType)); std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
std::unique_ptr<base::DictionaryValue> user_info = std::unique_ptr<base::DictionaryValue> user_info =
atom::NSDictionaryToDictionaryValue(userActivity.userInfo); atom::NSDictionaryToDictionaryValue(userActivity.userInfo);
if (!user_info) if (!user_info)
return NO; return NO;