Add an accessor for the current activity type and write the simplest possible test.

This commit is contained in:
Charlie Hess 2016-05-03 15:51:31 -07:00
Родитель 42768bcc2b
Коммит 12764a66ed
6 изменённых файлов: 29 добавлений и 9 удалений

Просмотреть файл

@ -469,6 +469,8 @@ void App::BuildPrototype(
.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",

Просмотреть файл

@ -97,6 +97,9 @@ class Browser : public WindowListObserver {
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);

Просмотреть файл

@ -91,19 +91,24 @@ void Browser::SetUserActivity(const std::string& type, const std::map<std::strin
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 {

Просмотреть файл

@ -63,12 +63,11 @@
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));

Просмотреть файл

@ -510,6 +510,10 @@ 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.
### `app.getCurrentActivityType()` _OS X_
Returns the type of the currently running activity.
### `app.setAppUserModelId(id)` _Windows_
* `id` String

Просмотреть файл

@ -89,6 +89,13 @@ describe('app module', function () {
})
})
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