add method binding and error guards
This commit is contained in:
parent
1ccad4a7e9
commit
18ee34f1a1
3 changed files with 11 additions and 6 deletions
|
@ -65,6 +65,7 @@ void SystemPreferences::BuildPrototype(
|
||||||
&SystemPreferences::SubscribeLocalNotification)
|
&SystemPreferences::SubscribeLocalNotification)
|
||||||
.SetMethod("unsubscribeLocalNotification",
|
.SetMethod("unsubscribeLocalNotification",
|
||||||
&SystemPreferences::UnsubscribeLocalNotification)
|
&SystemPreferences::UnsubscribeLocalNotification)
|
||||||
|
.SetMethod("registerDefaults", &SystemPreferences::RegisterDefaults)
|
||||||
.SetMethod("getUserDefault", &SystemPreferences::GetUserDefault)
|
.SetMethod("getUserDefault", &SystemPreferences::GetUserDefault)
|
||||||
.SetMethod("setUserDefault", &SystemPreferences::SetUserDefault)
|
.SetMethod("setUserDefault", &SystemPreferences::SetUserDefault)
|
||||||
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
|
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
|
||||||
|
|
|
@ -73,7 +73,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||||
void UnsubscribeLocalNotification(int request_id);
|
void UnsubscribeLocalNotification(int request_id);
|
||||||
v8::Local<v8::Value> GetUserDefault(const std::string& name,
|
v8::Local<v8::Value> GetUserDefault(const std::string& name,
|
||||||
const std::string& type);
|
const std::string& type);
|
||||||
void RegisterDefaults(const base::DictionaryValue& defaults);
|
void RegisterDefaults(mate::Arguments* args);
|
||||||
void SetUserDefault(const std::string& name,
|
void SetUserDefault(const std::string& name,
|
||||||
const std::string& type,
|
const std::string& type,
|
||||||
mate::Arguments* args);
|
mate::Arguments* args);
|
||||||
|
|
|
@ -144,11 +144,15 @@ v8::Local<v8::Value> SystemPreferences::GetUserDefault(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemPreferences::RegisterDefaults(const base::DictionaryValue& defaults) {
|
void SystemPreferences::RegisterDefaults(mate::Arguments* args) {
|
||||||
if (NSDictionary* defaultsDict = DictionaryValueToNSDictionary(defaults)) {
|
base::DictionaryValue value;
|
||||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDict];
|
if (!args->GetNext(&value)) {
|
||||||
} else {
|
args->ThrowError("Unable to parse userDefaults dict");
|
||||||
defaults->ThrowError("Unable to parse userDefaults");
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NSDictionary* dict = DictionaryValueToNSDictionary(value)) {
|
||||||
|
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue