diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index f15fad9d47..d573ac7279 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -250,11 +250,14 @@ void App::OnFinishLaunching() { Emit("ready"); } -void App::OnContinueUserActivity(bool* prevent_default, - const std::string& type, - const std::map& user_info) { +#if defined(OS_MACOSX) +void App::OnContinueUserActivity( + bool* prevent_default, + const std::string& type, + const std::map& user_info) { *prevent_default = Emit("continue-activity", type, user_info); } +#endif void App::OnLogin(LoginHandler* login_handler) { v8::Locker locker(isolate()); diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 321230d711..acc3071aec 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -72,9 +72,12 @@ class App : public AtomBrowserClient::Delegate, void OnWillFinishLaunching() override; void OnFinishLaunching() override; void OnLogin(LoginHandler* login_handler) override; - void OnContinueUserActivity(bool* prevent_default, - const std::string& type, - const std::map& user_info) override; +#if defined(OS_MACOSX) + void OnContinueUserActivity( + bool* prevent_default, + const std::string& type, + const std::map& user_info) override; +#endif // content::ContentBrowserClient: void AllowCertificateError( diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index ee2a225246..9fb0fc6bec 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -138,9 +138,9 @@ void Browser::Activate(bool has_visible_windows) { } #if defined(OS_MACOSX) -bool Browser::ContinueUserActivity(const std::string& type, - const std::map& user_info) { +bool Browser::ContinueUserActivity( + const std::string& type, + const std::map& user_info) { bool prevent_default = false; FOR_EACH_OBSERVER(BrowserObserver, observers_, diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 5c3dcaf512..1c9e5775fd 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -101,8 +101,9 @@ class Browser : public WindowListObserver { std::string GetCurrentActivityType(); // Resumes an activity via hand-off. - bool ContinueUserActivity(const std::string& type, - const std::map& user_info); + bool ContinueUserActivity( + const std::string& type, + const std::map& user_info); // Bounce the dock icon. enum BounceType { diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 42d10debd0..74002db4cc 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -87,17 +87,20 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) { void Browser::SetAppUserModelID(const base::string16& name) { } -void Browser::SetUserActivity(const std::string& type, const std::map& user_info) { +void Browser::SetUserActivity( + const std::string& type, + const std::map& user_info) { NSString* type_ns = [NSString stringWithUTF8String:type.c_str()]; - NSUserActivity* user_activity = [[NSUserActivity alloc] initWithActivityType:type_ns]; + NSUserActivity* user_activity = + [[NSUserActivity alloc] initWithActivityType:type_ns]; - base::scoped_nsobject user_info_args([[NSMutableDictionary alloc] init]); + base::scoped_nsobject user_info_args( + [[NSMutableDictionary alloc] init]); for (auto const &pair : user_info) { NSString* value_ns = [NSString stringWithUTF8String:pair.second.c_str()]; NSString* key_ns = [NSString stringWithUTF8String:pair.first.c_str()]; - [user_info_args.get() setObject:value_ns - forKey:key_ns]; + [user_info_args.get() setObject:value_ns forKey:key_ns]; } user_activity.userInfo = user_info_args.get(); @@ -107,7 +110,8 @@ void Browser::SetUserActivity(const std::string& type, const std::map #include +#include "build/build_config.h" + namespace atom { class LoginHandler; @@ -46,10 +48,13 @@ class BrowserObserver { // The browser requests HTTP login. virtual void OnLogin(LoginHandler* login_handler) {} +#if defined(OS_MACOSX) // The browser wants to resume a user activity via handoff. (OS X only) - virtual void OnContinueUserActivity(bool* prevent_default, - const std::string& type, - const std::map& user_info) {} + virtual void OnContinueUserActivity( + bool* prevent_default, + const std::string& type, + const std::map& user_info) {} +#endif protected: virtual ~BrowserObserver() {} diff --git a/atom/browser/mac/atom_application.h b/atom/browser/mac/atom_application.h index 37074cae7b..8f52ef10eb 100644 --- a/atom/browser/mac/atom_application.h +++ b/atom/browser/mac/atom_application.h @@ -21,7 +21,6 @@ - (void)setHandlingSendEvent:(BOOL)handlingSendEvent; - (NSUserActivity*)getCurrentActivity; - - (void)setCurrentActivity:(NSUserActivity*)userActivity; @end diff --git a/atom/browser/mac/atom_application_delegate.mm b/atom/browser/mac/atom_application_delegate.mm index 0904679c49..8b7853e0d8 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -59,9 +59,9 @@ return flag; } -- (BOOL)application:(NSApplication *)sender -continueUserActivity:(NSUserActivity *)userActivity - restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler { +- (BOOL)application:(NSApplication*)sender +continueUserActivity:(NSUserActivity*)userActivity + restorationHandler:(void (^)(NSArray*restorableObjects))restorationHandler { std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType)); std::map user_info; diff --git a/docs/api/app.md b/docs/api/app.md index 3ade1da034..75ed937dc4 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -118,15 +118,15 @@ Returns: * `event` Event * `type` String - A string identifying the event. Maps to [`NSUserActivity.activityType`](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSUserActivity_Class/index.html#//apple_ref/occ/instp/NSUserActivity/activityType). * `userInfo` Object - Contains app-specific state stored by the activity on -another device. Currently only string data is supported. + another device. Currently only string data is supported. -Emitted during [handoff](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Handoff/HandoffFundamentals/HandoffFundamentals.html) when an activity from a different device wants to be -resumed. You should call `event.preventDefault()` if you want to handle this -event. +Emitted during [handoff][handoff] when an activity from a different device wants +to be resumed. You should call `event.preventDefault()` if you want to handle +this event. -A user activity can be continued only in an app that has the same developer -Team ID as the activity's source app and that supports the activity's type. -Supported activity types are specified in the app's Info.plist under the +A user activity can be continued only in an app that has the same developer Team +ID as the activity's source app and that supports the activity's type. +Supported activity types are specified in the app's `Info.plist` under the `NSUserActivityTypes` key. ### Event: 'browser-window-blur' @@ -503,12 +503,12 @@ app.on('ready', function() { ### `app.setUserActivity(type, userInfo)` _OS X_ * `type` String - Uniquely identifies the activity. It's recommended to use a -reverse-DNS string. + reverse-DNS string. * `userInfo` Object - App-specific state to store for use by another device. -Currently only string data is supported. + Currently only string data is supported. Creates an `NSUserActivity` and sets it as the current activity. The activity -is eligible for [handoff](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Handoff/HandoffFundamentals/HandoffFundamentals.html) to another device afterward. +is eligible for [handoff][handoff] to another device afterward. ### `app.getCurrentActivityType()` _OS X_ @@ -600,5 +600,5 @@ Sets the `image` associated with this dock icon. [tasks]:http://msdn.microsoft.com/en-us/library/windows/desktop/dd378460(v=vs.85).aspx#tasks [app-user-model-id]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx [CFBundleURLTypes]: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-102207-TPXREF115 -[LSCopyDefaultHandlerForURLScheme]: -https://developer.apple.com/library/mac/documentation/Carbon/Reference/LaunchServicesReference/#//apple_ref/c/func/LSCopyDefaultHandlerForURLScheme +[LSCopyDefaultHandlerForURLScheme]: https://developer.apple.com/library/mac/documentation/Carbon/Reference/LaunchServicesReference/#//apple_ref/c/func/LSCopyDefaultHandlerForURLScheme +[handoff]: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Handoff/HandoffFundamentals/HandoffFundamentals.html