From 18ee34f1a1cb346fc1e2993641ba2f5fed27afd2 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Sun, 10 Dec 2017 11:25:43 -0500 Subject: [PATCH] add method binding and error guards --- atom/browser/api/atom_api_system_preferences.cc | 1 + atom/browser/api/atom_api_system_preferences.h | 2 +- .../browser/api/atom_api_system_preferences_mac.mm | 14 +++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/atom_api_system_preferences.cc b/atom/browser/api/atom_api_system_preferences.cc index 74d6d03ce7cb..82c3b2e1017f 100644 --- a/atom/browser/api/atom_api_system_preferences.cc +++ b/atom/browser/api/atom_api_system_preferences.cc @@ -65,6 +65,7 @@ void SystemPreferences::BuildPrototype( &SystemPreferences::SubscribeLocalNotification) .SetMethod("unsubscribeLocalNotification", &SystemPreferences::UnsubscribeLocalNotification) + .SetMethod("registerDefaults", &SystemPreferences::RegisterDefaults) .SetMethod("getUserDefault", &SystemPreferences::GetUserDefault) .SetMethod("setUserDefault", &SystemPreferences::SetUserDefault) .SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault) diff --git a/atom/browser/api/atom_api_system_preferences.h b/atom/browser/api/atom_api_system_preferences.h index 872f822ed74b..4e432d7e51e1 100644 --- a/atom/browser/api/atom_api_system_preferences.h +++ b/atom/browser/api/atom_api_system_preferences.h @@ -73,7 +73,7 @@ class SystemPreferences : public mate::EventEmitter void UnsubscribeLocalNotification(int request_id); v8::Local GetUserDefault(const std::string& name, const std::string& type); - void RegisterDefaults(const base::DictionaryValue& defaults); + void RegisterDefaults(mate::Arguments* args); void SetUserDefault(const std::string& name, const std::string& type, mate::Arguments* args); diff --git a/atom/browser/api/atom_api_system_preferences_mac.mm b/atom/browser/api/atom_api_system_preferences_mac.mm index 8f1df7746ff9..23dd650b7483 100644 --- a/atom/browser/api/atom_api_system_preferences_mac.mm +++ b/atom/browser/api/atom_api_system_preferences_mac.mm @@ -144,11 +144,15 @@ v8::Local SystemPreferences::GetUserDefault( } } -void SystemPreferences::RegisterDefaults(const base::DictionaryValue& defaults) { - if (NSDictionary* defaultsDict = DictionaryValueToNSDictionary(defaults)) { - [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDict]; - } else { - defaults->ThrowError("Unable to parse userDefaults"); +void SystemPreferences::RegisterDefaults(mate::Arguments* args) { + base::DictionaryValue value; + if (!args->GetNext(&value)) { + args->ThrowError("Unable to parse userDefaults dict"); + return; + } + + if (NSDictionary* dict = DictionaryValueToNSDictionary(value)) { + [[NSUserDefaults standardUserDefaults] registerDefaults:dict]; } }