From 0230567891a7ba1850ff7901f5174c9b16b07464 Mon Sep 17 00:00:00 2001 From: Charlie Hess Date: Wed, 1 Jun 2016 18:55:20 -0700 Subject: [PATCH] Write a new method that returns prefs under the NSGlobalDomain. --- .../browser/api/atom_api_system_preferences.h | 1 + .../api/atom_api_system_preferences_mac.mm | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/atom/browser/api/atom_api_system_preferences.h b/atom/browser/api/atom_api_system_preferences.h index 7779ce00781..0234d843440 100644 --- a/atom/browser/api/atom_api_system_preferences.h +++ b/atom/browser/api/atom_api_system_preferences.h @@ -39,6 +39,7 @@ class SystemPreferences : public mate::EventEmitter { void UnsubscribeNotification(int id); v8::Local GetUserDefault(const std::string& name, const std::string& type); + v8::Local GetGlobalDefault(const std::string& name); #endif bool IsDarkMode(); diff --git a/atom/browser/api/atom_api_system_preferences_mac.mm b/atom/browser/api/atom_api_system_preferences_mac.mm index f0b48adf256..2556fef35a6 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" @@ -84,6 +85,26 @@ v8::Local SystemPreferences::GetUserDefault( } } +v8::Local SystemPreferences::GetGlobalDefault(const std::string& name) { + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + NSString* key = base::SysUTF8ToNSString(name); + + NSDictionary* globalPrefs = [defaults persistentDomainForName:NSGlobalDomain]; + id value = [globalPrefs objectForKey:key]; + + if ([value isKindOfClass:[NSString class]]) { + return mate::StringToV8(isolate(), base::SysNSStringToUTF8(value)); + } else if ([value isKindOfClass:[NSNumber class]]) { + return v8::Integer::New(isolate(), [value integerValue]); + } else if ([value isKindOfClass:[NSArray class]]) { + return mate::ConvertToV8(isolate(), *NSArrayToListValue(value)); + } else if ([value isKindOfClass:[NSDictionary class]]) { + return mate::ConvertToV8(isolate(), *NSDictionaryToDictionaryValue(value)); + } else { + return v8::Undefined(isolate()); + } +} + bool SystemPreferences::IsDarkMode() { NSString* mode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];