refactor: ginify SystemPreferences (#24675)
This commit is contained in:
parent
3f45fc24bb
commit
362da77c0a
6 changed files with 76 additions and 70 deletions
|
@ -1,15 +1,10 @@
|
||||||
import { EventEmitter } from 'events';
|
|
||||||
import { deprecate } from 'electron/main';
|
import { deprecate } from 'electron/main';
|
||||||
const { systemPreferences, SystemPreferences } = process._linkedBinding('electron_browser_system_preferences');
|
const { systemPreferences } = process._linkedBinding('electron_browser_system_preferences');
|
||||||
|
|
||||||
// SystemPreferences is an EventEmitter.
|
|
||||||
Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype);
|
|
||||||
EventEmitter.call(systemPreferences);
|
|
||||||
|
|
||||||
if ('getAppLevelAppearance' in systemPreferences) {
|
if ('getAppLevelAppearance' in systemPreferences) {
|
||||||
const nativeALAGetter = systemPreferences.getAppLevelAppearance;
|
const nativeALAGetter = systemPreferences.getAppLevelAppearance;
|
||||||
const nativeALASetter = systemPreferences.setAppLevelAppearance;
|
const nativeALASetter = systemPreferences.setAppLevelAppearance;
|
||||||
Object.defineProperty(SystemPreferences.prototype, 'appLevelAppearance', {
|
Object.defineProperty(systemPreferences, 'appLevelAppearance', {
|
||||||
get: () => nativeALAGetter.call(systemPreferences),
|
get: () => nativeALAGetter.call(systemPreferences),
|
||||||
set: (appearance) => nativeALASetter.call(systemPreferences, appearance)
|
set: (appearance) => nativeALASetter.call(systemPreferences, appearance)
|
||||||
});
|
});
|
||||||
|
@ -17,25 +12,25 @@ if ('getAppLevelAppearance' in systemPreferences) {
|
||||||
|
|
||||||
if ('getEffectiveAppearance' in systemPreferences) {
|
if ('getEffectiveAppearance' in systemPreferences) {
|
||||||
const nativeEAGetter = systemPreferences.getAppLevelAppearance;
|
const nativeEAGetter = systemPreferences.getAppLevelAppearance;
|
||||||
Object.defineProperty(SystemPreferences.prototype, 'effectiveAppearance', {
|
Object.defineProperty(systemPreferences, 'effectiveAppearance', {
|
||||||
get: () => nativeEAGetter.call(systemPreferences)
|
get: () => nativeEAGetter.call(systemPreferences)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemPreferences.prototype.isDarkMode = deprecate.moveAPI(
|
systemPreferences.isDarkMode = deprecate.moveAPI(
|
||||||
SystemPreferences.prototype.isDarkMode,
|
systemPreferences.isDarkMode,
|
||||||
'systemPreferences.isDarkMode()',
|
'systemPreferences.isDarkMode()',
|
||||||
'nativeTheme.shouldUseDarkColors'
|
'nativeTheme.shouldUseDarkColors'
|
||||||
);
|
);
|
||||||
SystemPreferences.prototype.isInvertedColorScheme = deprecate.moveAPI(
|
systemPreferences.isInvertedColorScheme = deprecate.moveAPI(
|
||||||
SystemPreferences.prototype.isInvertedColorScheme,
|
systemPreferences.isInvertedColorScheme,
|
||||||
'systemPreferences.isInvertedColorScheme()',
|
'systemPreferences.isInvertedColorScheme()',
|
||||||
'nativeTheme.shouldUseInvertedColorScheme'
|
'nativeTheme.shouldUseInvertedColorScheme'
|
||||||
);
|
);
|
||||||
SystemPreferences.prototype.isHighContrastColorScheme = deprecate.moveAPI(
|
systemPreferences.isHighContrastColorScheme = deprecate.moveAPI(
|
||||||
SystemPreferences.prototype.isHighContrastColorScheme,
|
systemPreferences.isHighContrastColorScheme,
|
||||||
'systemPreferences.isHighContrastColorScheme()',
|
'systemPreferences.isHighContrastColorScheme()',
|
||||||
'nativeTheme.shouldUseHighContrastColors'
|
'nativeTheme.shouldUseHighContrastColors'
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = systemPreferences;
|
export default systemPreferences;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "shell/common/gin_converters/callback_converter.h"
|
#include "shell/common/gin_converters/callback_converter.h"
|
||||||
#include "shell/common/gin_converters/value_converter.h"
|
#include "shell/common/gin_converters/value_converter.h"
|
||||||
#include "shell/common/gin_helper/dictionary.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/gin_helper/object_template_builder.h"
|
#include "shell/common/gin_helper/function_template_extensions.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "ui/gfx/animation/animation.h"
|
#include "ui/gfx/animation/animation.h"
|
||||||
#include "ui/gfx/color_utils.h"
|
#include "ui/gfx/color_utils.h"
|
||||||
|
@ -17,8 +17,9 @@ namespace electron {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
|
gin::WrapperInfo SystemPreferences::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||||
Init(isolate);
|
|
||||||
|
SystemPreferences::SystemPreferences() {
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
InitializeWindow();
|
InitializeWindow();
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,15 +62,13 @@ v8::Local<v8::Value> SystemPreferences::GetAnimationSettings(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
gin::Handle<SystemPreferences> SystemPreferences::Create(v8::Isolate* isolate) {
|
gin::Handle<SystemPreferences> SystemPreferences::Create(v8::Isolate* isolate) {
|
||||||
return gin::CreateHandle(isolate, new SystemPreferences(isolate));
|
return gin::CreateHandle(isolate, new SystemPreferences());
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder(
|
||||||
void SystemPreferences::BuildPrototype(
|
v8::Isolate* isolate) {
|
||||||
v8::Isolate* isolate,
|
return gin_helper::EventEmitterMixin<
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
SystemPreferences>::GetObjectTemplateBuilder(isolate)
|
||||||
prototype->SetClassName(gin::StringToV8(isolate, "SystemPreferences"));
|
|
||||||
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
|
||||||
#if defined(OS_WIN) || defined(OS_MACOSX)
|
#if defined(OS_WIN) || defined(OS_MACOSX)
|
||||||
.SetMethod("getColor", &SystemPreferences::GetColor)
|
.SetMethod("getColor", &SystemPreferences::GetColor)
|
||||||
.SetMethod("getAccentColor", &SystemPreferences::GetAccentColor)
|
.SetMethod("getAccentColor", &SystemPreferences::GetAccentColor)
|
||||||
|
@ -125,6 +124,10 @@ void SystemPreferences::BuildPrototype(
|
||||||
&SystemPreferences::GetAnimationSettings);
|
&SystemPreferences::GetAnimationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* SystemPreferences::GetTypeName() {
|
||||||
|
return "SystemPreferences";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
@ -140,9 +143,6 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
gin_helper::Dictionary dict(isolate, exports);
|
gin_helper::Dictionary dict(isolate, exports);
|
||||||
dict.Set("systemPreferences", SystemPreferences::Create(isolate));
|
dict.Set("systemPreferences", SystemPreferences::Create(isolate));
|
||||||
dict.Set("SystemPreferences", SystemPreferences::GetConstructor(isolate)
|
|
||||||
->GetFunction(context)
|
|
||||||
.ToLocalChecked());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
|
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "gin/handle.h"
|
#include "gin/handle.h"
|
||||||
|
#include "gin/wrappable.h"
|
||||||
|
#include "shell/browser/event_emitter_mixin.h"
|
||||||
#include "shell/common/gin_helper/error_thrower.h"
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
#include "shell/common/gin_helper/event_emitter.h"
|
|
||||||
#include "shell/common/gin_helper/promise.h"
|
#include "shell/common/gin_helper/promise.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
@ -32,25 +33,30 @@ enum NotificationCenterKind {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class SystemPreferences : public gin_helper::EventEmitter<SystemPreferences>
|
class SystemPreferences
|
||||||
|
: public gin::Wrappable<SystemPreferences>,
|
||||||
|
public gin_helper::EventEmitterMixin<SystemPreferences>
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
,
|
,
|
||||||
public BrowserObserver,
|
public BrowserObserver,
|
||||||
public gfx::SysColorChangeListener
|
public gfx::SysColorChangeListener
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static gin::Handle<SystemPreferences> Create(v8::Isolate* isolate);
|
static gin::Handle<SystemPreferences> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
// gin::Wrappable
|
||||||
v8::Local<v8::FunctionTemplate> prototype);
|
static gin::WrapperInfo kWrapperInfo;
|
||||||
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
|
v8::Isolate* isolate) override;
|
||||||
|
const char* GetTypeName() override;
|
||||||
|
|
||||||
#if defined(OS_WIN) || defined(OS_MACOSX)
|
#if defined(OS_WIN) || defined(OS_MACOSX)
|
||||||
std::string GetAccentColor();
|
std::string GetAccentColor();
|
||||||
std::string GetColor(gin_helper::ErrorThrower thrower,
|
std::string GetColor(gin_helper::ErrorThrower thrower,
|
||||||
const std::string& color);
|
const std::string& color);
|
||||||
std::string GetMediaAccessStatus(const std::string& media_type,
|
std::string GetMediaAccessStatus(gin_helper::ErrorThrower thrower,
|
||||||
gin_helper::Arguments* args);
|
const std::string& media_type);
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
bool IsAeroGlassEnabled();
|
bool IsAeroGlassEnabled();
|
||||||
|
@ -69,7 +75,7 @@ class SystemPreferences : public gin_helper::EventEmitter<SystemPreferences>
|
||||||
|
|
||||||
void PostNotification(const std::string& name,
|
void PostNotification(const std::string& name,
|
||||||
base::DictionaryValue user_info,
|
base::DictionaryValue user_info,
|
||||||
gin_helper::Arguments* args);
|
gin::Arguments* args);
|
||||||
int SubscribeNotification(const std::string& name,
|
int SubscribeNotification(const std::string& name,
|
||||||
const NotificationCallback& callback);
|
const NotificationCallback& callback);
|
||||||
void UnsubscribeNotification(int id);
|
void UnsubscribeNotification(int id);
|
||||||
|
@ -83,12 +89,13 @@ class SystemPreferences : public gin_helper::EventEmitter<SystemPreferences>
|
||||||
int SubscribeWorkspaceNotification(const std::string& name,
|
int SubscribeWorkspaceNotification(const std::string& name,
|
||||||
const NotificationCallback& callback);
|
const NotificationCallback& callback);
|
||||||
void UnsubscribeWorkspaceNotification(int request_id);
|
void UnsubscribeWorkspaceNotification(int request_id);
|
||||||
v8::Local<v8::Value> GetUserDefault(const std::string& name,
|
v8::Local<v8::Value> GetUserDefault(v8::Isolate* isolate,
|
||||||
|
const std::string& name,
|
||||||
const std::string& type);
|
const std::string& type);
|
||||||
void RegisterDefaults(gin_helper::Arguments* args);
|
void RegisterDefaults(gin::Arguments* args);
|
||||||
void SetUserDefault(const std::string& name,
|
void SetUserDefault(const std::string& name,
|
||||||
const std::string& type,
|
const std::string& type,
|
||||||
gin_helper::Arguments* args);
|
gin::Arguments* args);
|
||||||
void RemoveUserDefault(const std::string& name);
|
void RemoveUserDefault(const std::string& name);
|
||||||
bool IsSwipeTrackingFromScrollEventsEnabled();
|
bool IsSwipeTrackingFromScrollEventsEnabled();
|
||||||
|
|
||||||
|
@ -108,7 +115,7 @@ class SystemPreferences : public gin_helper::EventEmitter<SystemPreferences>
|
||||||
// are running tests on a Mojave machine
|
// are running tests on a Mojave machine
|
||||||
v8::Local<v8::Value> GetEffectiveAppearance(v8::Isolate* isolate);
|
v8::Local<v8::Value> GetEffectiveAppearance(v8::Isolate* isolate);
|
||||||
v8::Local<v8::Value> GetAppLevelAppearance(v8::Isolate* isolate);
|
v8::Local<v8::Value> GetAppLevelAppearance(v8::Isolate* isolate);
|
||||||
void SetAppLevelAppearance(gin_helper::Arguments* args);
|
void SetAppLevelAppearance(gin::Arguments* args);
|
||||||
#endif
|
#endif
|
||||||
bool IsDarkMode();
|
bool IsDarkMode();
|
||||||
bool IsInvertedColorScheme();
|
bool IsInvertedColorScheme();
|
||||||
|
@ -116,7 +123,7 @@ class SystemPreferences : public gin_helper::EventEmitter<SystemPreferences>
|
||||||
v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);
|
v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit SystemPreferences(v8::Isolate* isolate);
|
SystemPreferences();
|
||||||
~SystemPreferences() override;
|
~SystemPreferences() override;
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
|
|
|
@ -125,7 +125,7 @@ std::string ConvertSystemPermission(
|
||||||
|
|
||||||
void SystemPreferences::PostNotification(const std::string& name,
|
void SystemPreferences::PostNotification(const std::string& name,
|
||||||
base::DictionaryValue user_info,
|
base::DictionaryValue user_info,
|
||||||
gin_helper::Arguments* args) {
|
gin::Arguments* args) {
|
||||||
bool immediate = false;
|
bool immediate = false;
|
||||||
args->GetNext(&immediate);
|
args->GetNext(&immediate);
|
||||||
|
|
||||||
|
@ -257,60 +257,61 @@ void SystemPreferences::DoUnsubscribeNotification(int request_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> SystemPreferences::GetUserDefault(
|
v8::Local<v8::Value> SystemPreferences::GetUserDefault(
|
||||||
|
v8::Isolate* isolate,
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::string& type) {
|
const std::string& type) {
|
||||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||||
NSString* key = base::SysUTF8ToNSString(name);
|
NSString* key = base::SysUTF8ToNSString(name);
|
||||||
if (type == "string") {
|
if (type == "string") {
|
||||||
return gin::StringToV8(
|
return gin::StringToV8(
|
||||||
isolate(), base::SysNSStringToUTF8([defaults stringForKey:key]));
|
isolate, base::SysNSStringToUTF8([defaults stringForKey:key]));
|
||||||
} else if (type == "boolean") {
|
} else if (type == "boolean") {
|
||||||
return v8::Boolean::New(isolate(), [defaults boolForKey:key]);
|
return v8::Boolean::New(isolate, [defaults boolForKey:key]);
|
||||||
} else if (type == "float") {
|
} else if (type == "float") {
|
||||||
return v8::Number::New(isolate(), [defaults floatForKey:key]);
|
return v8::Number::New(isolate, [defaults floatForKey:key]);
|
||||||
} else if (type == "integer") {
|
} else if (type == "integer") {
|
||||||
return v8::Integer::New(isolate(), [defaults integerForKey:key]);
|
return v8::Integer::New(isolate, [defaults integerForKey:key]);
|
||||||
} else if (type == "double") {
|
} else if (type == "double") {
|
||||||
return v8::Number::New(isolate(), [defaults doubleForKey:key]);
|
return v8::Number::New(isolate, [defaults doubleForKey:key]);
|
||||||
} else if (type == "url") {
|
} else if (type == "url") {
|
||||||
return gin::ConvertToV8(isolate(),
|
return gin::ConvertToV8(isolate,
|
||||||
net::GURLWithNSURL([defaults URLForKey:key]));
|
net::GURLWithNSURL([defaults URLForKey:key]));
|
||||||
} else if (type == "array") {
|
} else if (type == "array") {
|
||||||
return gin::ConvertToV8(isolate(),
|
return gin::ConvertToV8(isolate,
|
||||||
NSArrayToListValue([defaults arrayForKey:key]));
|
NSArrayToListValue([defaults arrayForKey:key]));
|
||||||
} else if (type == "dictionary") {
|
} else if (type == "dictionary") {
|
||||||
return gin::ConvertToV8(isolate(), NSDictionaryToDictionaryValue(
|
return gin::ConvertToV8(isolate, NSDictionaryToDictionaryValue(
|
||||||
[defaults dictionaryForKey:key]));
|
[defaults dictionaryForKey:key]));
|
||||||
} else {
|
} else {
|
||||||
return v8::Undefined(isolate());
|
return v8::Undefined(isolate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemPreferences::RegisterDefaults(gin_helper::Arguments* args) {
|
void SystemPreferences::RegisterDefaults(gin::Arguments* args) {
|
||||||
base::DictionaryValue value;
|
base::DictionaryValue value;
|
||||||
|
|
||||||
if (!args->GetNext(&value)) {
|
if (!args->GetNext(&value)) {
|
||||||
args->ThrowError("Invalid userDefault data provided");
|
args->ThrowError();
|
||||||
} else {
|
} else {
|
||||||
@try {
|
@try {
|
||||||
NSDictionary* dict = DictionaryValueToNSDictionary(value);
|
NSDictionary* dict = DictionaryValueToNSDictionary(value);
|
||||||
for (id key in dict) {
|
for (id key in dict) {
|
||||||
id value = [dict objectForKey:key];
|
id value = [dict objectForKey:key];
|
||||||
if ([value isKindOfClass:[NSNull class]] || value == nil) {
|
if ([value isKindOfClass:[NSNull class]] || value == nil) {
|
||||||
args->ThrowError("Invalid userDefault data provided");
|
args->ThrowError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
||||||
} @catch (NSException* exception) {
|
} @catch (NSException* exception) {
|
||||||
args->ThrowError("Invalid userDefault data provided");
|
args->ThrowError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemPreferences::SetUserDefault(const std::string& name,
|
void SystemPreferences::SetUserDefault(const std::string& name,
|
||||||
const std::string& type,
|
const std::string& type,
|
||||||
gin_helper::Arguments* args) {
|
gin::Arguments* args) {
|
||||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||||
NSString* key = base::SysUTF8ToNSString(name);
|
NSString* key = base::SysUTF8ToNSString(name);
|
||||||
if (type == "string") {
|
if (type == "string") {
|
||||||
|
@ -321,7 +322,8 @@ void SystemPreferences::SetUserDefault(const std::string& name,
|
||||||
}
|
}
|
||||||
} else if (type == "boolean") {
|
} else if (type == "boolean") {
|
||||||
bool value;
|
bool value;
|
||||||
if (args->GetNext(&value)) {
|
v8::Local<v8::Value> next = args->PeekNext();
|
||||||
|
if (!next.IsEmpty() && next->IsBoolean() && args->GetNext(&value)) {
|
||||||
[defaults setBool:value forKey:key];
|
[defaults setBool:value forKey:key];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -368,11 +370,13 @@ void SystemPreferences::SetUserDefault(const std::string& name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
args->ThrowError("Invalid type: " + type);
|
gin_helper::ErrorThrower(args->isolate())
|
||||||
|
.ThrowTypeError("Invalid type: " + type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
args->ThrowError("Unable to convert value to: " + type);
|
gin_helper::ErrorThrower(args->isolate())
|
||||||
|
.ThrowTypeError("Unable to convert value to: " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SystemPreferences::GetAccentColor() {
|
std::string SystemPreferences::GetAccentColor() {
|
||||||
|
@ -572,8 +576,8 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SystemPreferences::GetMediaAccessStatus(
|
std::string SystemPreferences::GetMediaAccessStatus(
|
||||||
const std::string& media_type,
|
gin_helper::ErrorThrower thrower,
|
||||||
gin_helper::Arguments* args) {
|
const std::string& media_type) {
|
||||||
if (media_type == "camera") {
|
if (media_type == "camera") {
|
||||||
return ConvertSystemPermission(
|
return ConvertSystemPermission(
|
||||||
system_media_permissions::CheckSystemVideoCapturePermission());
|
system_media_permissions::CheckSystemVideoCapturePermission());
|
||||||
|
@ -584,7 +588,7 @@ std::string SystemPreferences::GetMediaAccessStatus(
|
||||||
return ConvertSystemPermission(
|
return ConvertSystemPermission(
|
||||||
system_media_permissions::CheckSystemScreenCapturePermission());
|
system_media_permissions::CheckSystemScreenCapturePermission());
|
||||||
} else {
|
} else {
|
||||||
args->ThrowError("Invalid media type");
|
thrower.ThrowError("Invalid media type");
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -651,13 +655,13 @@ v8::Local<v8::Value> SystemPreferences::GetAppLevelAppearance(
|
||||||
return v8::Null(isolate);
|
return v8::Null(isolate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemPreferences::SetAppLevelAppearance(gin_helper::Arguments* args) {
|
void SystemPreferences::SetAppLevelAppearance(gin::Arguments* args) {
|
||||||
if (@available(macOS 10.14, *)) {
|
if (@available(macOS 10.14, *)) {
|
||||||
NSAppearance* appearance;
|
NSAppearance* appearance;
|
||||||
if (args->GetNext(&appearance)) {
|
if (args->GetNext(&appearance)) {
|
||||||
[[NSApplication sharedApplication] setAppearance:appearance];
|
[[NSApplication sharedApplication] setAppearance:appearance];
|
||||||
} else {
|
} else {
|
||||||
args->ThrowError("Invalid app appearance provided as first argument");
|
args->ThrowError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,8 +167,8 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SystemPreferences::GetMediaAccessStatus(
|
std::string SystemPreferences::GetMediaAccessStatus(
|
||||||
const std::string& media_type,
|
gin_helper::ErrorThrower thrower,
|
||||||
gin_helper::Arguments* args) {
|
const std::string& media_type) {
|
||||||
if (media_type == "camera") {
|
if (media_type == "camera") {
|
||||||
return ConvertDeviceAccessStatus(
|
return ConvertDeviceAccessStatus(
|
||||||
GetDeviceAccessStatus(DeviceClass::DeviceClass_VideoCapture));
|
GetDeviceAccessStatus(DeviceClass::DeviceClass_VideoCapture));
|
||||||
|
@ -179,7 +179,7 @@ std::string SystemPreferences::GetMediaAccessStatus(
|
||||||
return ConvertDeviceAccessStatus(
|
return ConvertDeviceAccessStatus(
|
||||||
DeviceAccessStatus::DeviceAccessStatus_Allowed);
|
DeviceAccessStatus::DeviceAccessStatus_Allowed);
|
||||||
} else {
|
} else {
|
||||||
args->ThrowError("Invalid media type");
|
thrower.ThrowError("Invalid media type");
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ describe('systemPreferences module', () => {
|
||||||
for (const badDefault of badDefaults) {
|
for (const badDefault of badDefaults) {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
systemPreferences.registerDefaults(badDefault as any);
|
systemPreferences.registerDefaults(badDefault as any);
|
||||||
}).to.throw('Invalid userDefault data provided');
|
}).to.throw('Error processing argument at index 0, conversion failure from ');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue