New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS X Handoff Feature #5352

Merged
merged 22 commits into from May 5, 2016

Conversation

Projects
None yet
4 participants
@CharlieHess
Contributor

CharlieHess commented Apr 30, 2016

This PR implements OS X Handoff using new APIs on app, as follows:

/**
 * Creates an NSUserActivity and sets it as the current activity.
 * Other Mac and iOS apps can retrieve this data in an app delegate.
 */
app.setUserActivity('com.Electron.myEvent', {
  dataToResumeWith: 'abc',
  only: 'strings allowed'
});
/**
 * If your Info.plist includes this activity type, your app will receive this 
 * event when a "handoff" occurs.
 */
app.on("continue-activity", (e, type, userInfo) => {
  if (type === 'com.Electron.myEvent') {
    event.preventDefault();
    // resume activity using data from userInfo
  }
});

In its current form, you can only pass strings in the userInfo object. Someone with more Objective-C++ chops could certainly improve on this.

TODO:

  • Documentation
  • Code review
* `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.

This comment has been minimized.

@paulcbetts

paulcbetts Apr 30, 2016

Contributor

Does this userInfo object have to be a dictionary of strings?

This comment has been minimized.

@CharlieHess

CharlieHess May 2, 2016

Contributor

Nope, that was a dumb simplification that I forgot about. I changed it to pass around base::Dictionary; only issue is that converting back and forth (taking nesting into account) is a lot of boilerplate.

This comment has been minimized.

@paulcbetts

paulcbetts May 3, 2016

Contributor

I mean, I actually think it's quite reasonable to constrain it to strings, it'd probably make your code way simpler - you just gotta Dox it

@dasilvacontin

This comment has been minimized.

dasilvacontin commented Apr 30, 2016

Thanks so much for working on this!

NSString* value_ns = [NSString stringWithUTF8String:pair.second.c_str()];
[user_info_args addObject:key_ns];
[user_info_args addObject:value_ns];

This comment has been minimized.

@@ -0,0 +1,54 @@
#import "atom/browser/mac/mac_native_converter.h"
@implementation MacNativeConverter

This comment has been minimized.

@CharlieHess

CharlieHess May 2, 2016

Contributor

This is getting a little out of hand and I feel like I must be duplicating code that already exists somewhere.
@zcbenz: Is there a better way to convert between Cocoa Foundation types and base types?

@@ -87,6 +87,23 @@
void Browser::SetAppUserModelID(const base::string16& name) {
}
void Browser::SetUserActivity(const std::string& type, const std::map<std::string, std::string>& user_info) {
NSString* type_ns = [NSString stringWithUTF8String:type.c_str()];
NSUserActivity *user_activity = [[NSUserActivity alloc] initWithActivityType:type_ns];

This comment has been minimized.

@zcbenz

zcbenz May 4, 2016

Contributor

The user_activity, user_info_args, and the array passed to user_activity.userInfo should be released after being used, you can put them in a base::scoped_nsobject to make them release automatically.

@zcbenz

This comment has been minimized.

Contributor

zcbenz commented May 5, 2016

👍

@zcbenz zcbenz merged commit 3f2a25d into electron:master May 5, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment