Write a new method that returns prefs under the NSGlobalDomain.

This commit is contained in:
Charlie Hess 2016-06-01 18:55:20 -07:00
parent aa1b8cd74b
commit 0230567891
2 changed files with 22 additions and 0 deletions

View file

@ -39,6 +39,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
void UnsubscribeNotification(int id); void UnsubscribeNotification(int 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);
v8::Local<v8::Value> GetGlobalDefault(const std::string& name);
#endif #endif
bool IsDarkMode(); bool IsDarkMode();

View file

@ -9,6 +9,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include "atom/browser/mac/dict_util.h" #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 "atom/common/native_mate_converters/gurl_converter.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/values.h" #include "base/values.h"
@ -84,6 +85,26 @@ v8::Local<v8::Value> SystemPreferences::GetUserDefault(
} }
} }
v8::Local<v8::Value> 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() { bool SystemPreferences::IsDarkMode() {
NSString* mode = [[NSUserDefaults standardUserDefaults] NSString* mode = [[NSUserDefaults standardUserDefaults]
stringForKey:@"AppleInterfaceStyle"]; stringForKey:@"AppleInterfaceStyle"];