Merge pull request #7053 from electron/launch-from-notification

Send notification info to app.ready, on macOS
This commit is contained in:
Cheng Zhao 2016-09-09 20:01:39 +09:00 committed by GitHub
commit b6079ff90b
8 changed files with 28 additions and 11 deletions

View file

@ -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() {

View file

@ -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;

View file

@ -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
}

View file

@ -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() {

View file

@ -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();

View file

@ -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,

View file

@ -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;

View file

@ -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'