.SetMethod("show", base::Bind(&Browser::Show, browser))
.SetMethod("setUserActivity",
base::Bind(&Browser::SetUserActivity, browser))
+ .SetMethod("getCurrentActivityType",
+ base::Bind(&Browser::GetCurrentActivityType, browser))
#endif
#if defined(OS_WIN)
.SetMethod("setUserTasks",
void SetUserActivity(const std::string& type,
const std::map<std::string, std::string>& user_info);
+ // Returns the type name of the current user activity.
+ std::string GetCurrentActivityType();
+
// Resumes an activity via hand-off.
bool ContinueUserActivity(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];
- NSMutableArray* user_info_args = [[NSMutableArray alloc] init];
+ NSMutableDictionary* 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 addObject:value_ns];
- [user_info_args addObject:key_ns];
+ [user_info_args setObject:value_ns
+ forKey:key_ns];
}
- user_activity.userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:user_info_args, nil];
+ user_activity.userInfo = user_info_args;
[user_activity becomeCurrent];
- [[AtomApplication sharedApplication] setUserActivity:user_activity];
+ [[AtomApplication sharedApplication] setCurrentActivity:user_activity];
+}
+
+std::string Browser::GetCurrentActivityType() {
+ NSUserActivity* user_activity = [[AtomApplication sharedApplication] getCurrentActivity];
+ return base::SysNSStringToUTF8(user_activity.activityType);
}
std::string Browser::GetExecutableFileVersion() const {
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
-
+
std::map<std::string, std::string> user_info;
-
+
NSArray* keys = [userActivity.userInfo allKeys];
- for (NSString* key in keys)
- {
+ for (NSString* key in keys) {
NSString* value = [userActivity.userInfo objectForKey:key];
std::string key_str(base::SysNSStringToUTF8(key));
std::string value_str(base::SysNSStringToUTF8(value));
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.
+### `app.getCurrentActivityType()` _OS X_
+
+Returns the type of the currently running activity.
+
### `app.setAppUserModelId(id)` _Windows_
* `id` String
})
})
+ describe('app.setUserActivity(type, userInfo)', function () {
+ it('sets the current activity', function () {
+ app.setUserActivity('com.electron.testActivity', {testData: '123'});
+ assert.equal(app.getCurrentActivityType(), 'com.electron.testActivity');
+ })
+ })
+
describe('app.importCertificate', function () {
if (process.platform !== 'linux')
return