diff --git a/atom/browser/api/atom_api_system_preferences_mac.mm b/atom/browser/api/atom_api_system_preferences_mac.mm index f0b48adf2564..72011500bd04 100644 --- a/atom/browser/api/atom_api_system_preferences_mac.mm +++ b/atom/browser/api/atom_api_system_preferences_mac.mm @@ -9,6 +9,7 @@ #import #include "atom/browser/mac/dict_util.h" +#include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/native_mate_converters/gurl_converter.h" #include "base/strings/sys_string_conversions.h" #include "base/values.h" @@ -66,8 +67,8 @@ v8::Local SystemPreferences::GetUserDefault( NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; NSString* key = base::SysUTF8ToNSString(name); if (type == "string") { - return mate::StringToV8( - isolate(), base::SysNSStringToUTF8([defaults stringForKey:key])); + return mate::StringToV8(isolate(), + base::SysNSStringToUTF8([defaults stringForKey:key])); } else if (type == "boolean") { return v8::Boolean::New(isolate(), [defaults boolForKey:key]); } else if (type == "float") { @@ -77,8 +78,14 @@ v8::Local SystemPreferences::GetUserDefault( } else if (type == "double") { return v8::Number::New(isolate(), [defaults doubleForKey:key]); } else if (type == "url") { - return mate::ConvertToV8( - isolate(), net::GURLWithNSURL([defaults URLForKey:key])); + return mate::ConvertToV8(isolate(), + net::GURLWithNSURL([defaults URLForKey:key])); + } else if (type == "array") { + return mate::ConvertToV8(isolate(), + *NSArrayToListValue([defaults arrayForKey:key])); + } else if (type == "dictionary") { + return mate::ConvertToV8(isolate(), + *NSDictionaryToDictionaryValue([defaults dictionaryForKey:key])); } else { return v8::Undefined(isolate()); } diff --git a/atom/browser/mac/dict_util.h b/atom/browser/mac/dict_util.h index 404636d1901a..3ffd8ba51006 100644 --- a/atom/browser/mac/dict_util.h +++ b/atom/browser/mac/dict_util.h @@ -10,7 +10,7 @@ #include "base/memory/scoped_ptr.h" namespace base { -class Value; +class ListValue; class DictionaryValue; } @@ -21,6 +21,8 @@ NSDictionary* DictionaryValueToNSDictionary(const base::DictionaryValue& value); std::unique_ptr NSDictionaryToDictionaryValue( NSDictionary* dict); +std::unique_ptr NSArrayToListValue(NSArray* arr); + } // namespace atom #endif // ATOM_BROWSER_MAC_DICT_UTIL_H_ diff --git a/atom/browser/mac/dict_util.mm b/atom/browser/mac/dict_util.mm index 43b629cc32be..8692f001f6a8 100644 --- a/atom/browser/mac/dict_util.mm +++ b/atom/browser/mac/dict_util.mm @@ -10,8 +10,6 @@ namespace atom { -namespace { - std::unique_ptr NSArrayToListValue(NSArray* arr) { if (!arr) return nullptr; @@ -51,8 +49,6 @@ std::unique_ptr NSArrayToListValue(NSArray* arr) { return result; } -} // namespace - NSDictionary* DictionaryValueToNSDictionary(const base::DictionaryValue& value) { std::string json; if (!base::JSONWriter::Write(value, &json)) diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 8f4dc8993852..7b2f0724a4aa 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -39,7 +39,7 @@ Removes the subscriber with `id`. * `key` String * `type` String - Can be `string`, `boolean`, `integer`, `float`, `double`, - `url`. + `url`, `array`, `dictionary` Get the value of `key` in system preferences. @@ -50,6 +50,9 @@ are: * `AppleAquaColorVariant: integer` * `AppleHighlightColor: string` * `AppleShowScrollBars: string` +* `NSNavRecentPlaces: array` +* `NSPreferredWebServices: dictionary` +* `NSUserDictionaryReplacementItems: array` ### `systemPreferences.isAeroGlassEnabled()` _Windows_ diff --git a/spec/api-system-preferences-spec.js b/spec/api-system-preferences-spec.js new file mode 100644 index 000000000000..333c4dbacb4e --- /dev/null +++ b/spec/api-system-preferences-spec.js @@ -0,0 +1,22 @@ +const assert = require('assert') +const {remote} = require('electron') +const {systemPreferences} = remote + +describe('systemPreferences module', function () { + if (process.platform !== 'darwin') { + return + } + + describe('systemPreferences.getUserDefault(key, type)', function () { + it('returns values for known user defaults', function () { + let locale = systemPreferences.getUserDefault('AppleLocale', 'string') + assert.notEqual(locale, null) + assert(locale.length > 0) + + let languages = systemPreferences.getUserDefault('AppleLanguages', 'array') + assert.notEqual(languages, null) + assert(languages.length > 0) + }) + }) + +})