Browse Source

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.
Charlie Hess 8 years ago
parent
commit
af9e010162

+ 2 - 2
atom/browser/api/atom_api_app.cc

@@ -274,8 +274,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() {

+ 1 - 1
atom/browser/api/atom_api_app.h

@@ -69,7 +69,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;

+ 2 - 1
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();
+  base::DictionaryValue* empty_info = new base::DictionaryValue();
+  Browser::Get()->DidFinishLaunching(empty_info);
 #endif
 }
 

+ 2 - 2
atom/browser/browser.cc

@@ -148,14 +148,14 @@ 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() {

+ 1 - 1
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();
 

+ 1 - 1
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,

+ 11 - 2
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 {
+    base::DictionaryValue* launch_info = new base::DictionaryValue();
+    atom::Browser::Get()->DidFinishLaunching(*launch_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;