Write a new method that returns prefs under the NSGlobalDomain.
This commit is contained in:
parent
aa1b8cd74b
commit
0230567891
2 changed files with 22 additions and 0 deletions
|
@ -39,6 +39,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
|
|||
void UnsubscribeNotification(int id);
|
||||
v8::Local<v8::Value> GetUserDefault(const std::string& name,
|
||||
const std::string& type);
|
||||
v8::Local<v8::Value> GetGlobalDefault(const std::string& name);
|
||||
#endif
|
||||
bool IsDarkMode();
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#import <Cocoa/Cocoa.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 "base/strings/sys_string_conversions.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() {
|
||||
NSString* mode = [[NSUserDefaults standardUserDefaults]
|
||||
stringForKey:@"AppleInterfaceStyle"];
|
||||
|
|
Loading…
Reference in a new issue