2016-04-24 21:13:46 +09:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 12:19:40 -08:00
|
|
|
#include "shell/browser/api/electron_api_system_preferences.h"
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2019-10-24 14:47:58 +09:00
|
|
|
#include "shell/common/gin_converters/callback_converter.h"
|
2019-10-31 16:56:00 +09:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2019-09-09 00:10:18 +09:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2020-07-28 11:03:30 -07:00
|
|
|
#include "shell/common/gin_helper/function_template_extensions.h"
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/common/node_includes.h"
|
2019-03-19 20:15:40 +01:00
|
|
|
#include "ui/gfx/animation/animation.h"
|
2016-10-06 15:27:24 -07:00
|
|
|
#include "ui/gfx/color_utils.h"
|
2019-07-15 14:37:33 -07:00
|
|
|
#include "ui/native_theme/native_theme.h"
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2016-04-24 21:13:46 +09:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2020-07-28 11:03:30 -07:00
|
|
|
gin::WrapperInfo SystemPreferences::kWrapperInfo = {gin::kEmbedderNativeGin};
|
|
|
|
|
|
|
|
SystemPreferences::SystemPreferences() {
|
2016-10-07 09:38:19 -07:00
|
|
|
#if defined(OS_WIN)
|
2016-09-17 02:00:22 +10:00
|
|
|
InitializeWindow();
|
2016-10-07 09:38:19 -07:00
|
|
|
#endif
|
2016-04-24 21:13:46 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
SystemPreferences::~SystemPreferences() {
|
2017-02-02 09:34:20 -08:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
Browser::Get()->RemoveObserver(this);
|
|
|
|
#endif
|
2016-04-24 21:13:46 +09:00
|
|
|
}
|
|
|
|
|
2016-10-07 09:38:19 -07:00
|
|
|
bool SystemPreferences::IsInvertedColorScheme() {
|
2020-04-13 16:39:26 -07:00
|
|
|
return ui::NativeTheme::GetInstanceForNativeUi()
|
2020-07-13 18:13:34 -07:00
|
|
|
->GetPlatformHighContrastColorScheme() ==
|
|
|
|
ui::NativeTheme::PlatformHighContrastColorScheme::kDark;
|
2016-10-07 09:38:19 -07:00
|
|
|
}
|
|
|
|
|
2018-10-31 15:22:18 +01:00
|
|
|
bool SystemPreferences::IsHighContrastColorScheme() {
|
2021-01-12 15:31:23 -08:00
|
|
|
return ui::NativeTheme::GetInstanceForNativeUi()->UserHasContrastPreference();
|
2018-10-31 15:22:18 +01:00
|
|
|
}
|
|
|
|
|
2019-03-19 20:15:40 +01:00
|
|
|
v8::Local<v8::Value> SystemPreferences::GetAnimationSettings(
|
|
|
|
v8::Isolate* isolate) {
|
2019-09-09 00:10:18 +09:00
|
|
|
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
2019-03-19 20:15:40 +01:00
|
|
|
dict.SetHidden("simple", true);
|
|
|
|
dict.Set("shouldRenderRichAnimation",
|
|
|
|
gfx::Animation::ShouldRenderRichAnimation());
|
|
|
|
dict.Set("scrollAnimationsEnabledBySystem",
|
|
|
|
gfx::Animation::ScrollAnimationsEnabledBySystem());
|
|
|
|
dict.Set("prefersReducedMotion", gfx::Animation::PrefersReducedMotion());
|
|
|
|
|
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
|
2016-04-24 21:13:46 +09:00
|
|
|
// static
|
2019-10-24 14:47:58 +09:00
|
|
|
gin::Handle<SystemPreferences> SystemPreferences::Create(v8::Isolate* isolate) {
|
2020-07-28 11:03:30 -07:00
|
|
|
return gin::CreateHandle(isolate, new SystemPreferences());
|
2016-04-24 21:13:46 +09:00
|
|
|
}
|
|
|
|
|
2020-07-28 11:03:30 -07:00
|
|
|
gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) {
|
|
|
|
return gin_helper::EventEmitterMixin<
|
|
|
|
SystemPreferences>::GetObjectTemplateBuilder(isolate)
|
2020-08-12 11:33:58 -07:00
|
|
|
#if defined(OS_WIN) || defined(OS_MAC)
|
2019-01-03 16:17:07 -08:00
|
|
|
.SetMethod("getColor", &SystemPreferences::GetColor)
|
2016-09-17 02:00:22 +10:00
|
|
|
.SetMethod("getAccentColor", &SystemPreferences::GetAccentColor)
|
2020-06-25 18:47:50 +02:00
|
|
|
.SetMethod("getMediaAccessStatus",
|
|
|
|
&SystemPreferences::GetMediaAccessStatus)
|
2019-01-03 13:24:55 -08:00
|
|
|
#endif
|
2019-01-03 16:17:07 -08:00
|
|
|
|
2019-01-03 13:24:55 -08:00
|
|
|
#if defined(OS_WIN)
|
2016-09-17 02:09:28 +10:00
|
|
|
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
|
2020-08-12 11:33:58 -07:00
|
|
|
#elif defined(OS_MAC)
|
2018-04-17 21:55:30 -04:00
|
|
|
.SetMethod("postNotification", &SystemPreferences::PostNotification)
|
2016-04-25 14:25:14 +09:00
|
|
|
.SetMethod("subscribeNotification",
|
|
|
|
&SystemPreferences::SubscribeNotification)
|
|
|
|
.SetMethod("unsubscribeNotification",
|
|
|
|
&SystemPreferences::UnsubscribeNotification)
|
2018-03-22 10:41:03 +01:00
|
|
|
.SetMethod("postLocalNotification",
|
|
|
|
&SystemPreferences::PostLocalNotification)
|
2016-06-20 17:48:42 -07:00
|
|
|
.SetMethod("subscribeLocalNotification",
|
|
|
|
&SystemPreferences::SubscribeLocalNotification)
|
|
|
|
.SetMethod("unsubscribeLocalNotification",
|
|
|
|
&SystemPreferences::UnsubscribeLocalNotification)
|
2018-03-22 10:41:03 +01:00
|
|
|
.SetMethod("postWorkspaceNotification",
|
|
|
|
&SystemPreferences::PostWorkspaceNotification)
|
|
|
|
.SetMethod("subscribeWorkspaceNotification",
|
|
|
|
&SystemPreferences::SubscribeWorkspaceNotification)
|
|
|
|
.SetMethod("unsubscribeWorkspaceNotification",
|
|
|
|
&SystemPreferences::UnsubscribeWorkspaceNotification)
|
2017-12-12 13:08:09 -05:00
|
|
|
.SetMethod("registerDefaults", &SystemPreferences::RegisterDefaults)
|
2016-04-25 15:35:52 +09:00
|
|
|
.SetMethod("getUserDefault", &SystemPreferences::GetUserDefault)
|
2016-11-28 15:08:22 -08:00
|
|
|
.SetMethod("setUserDefault", &SystemPreferences::SetUserDefault)
|
2017-10-10 22:55:15 +03:00
|
|
|
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
|
2016-08-03 10:27:56 +08:00
|
|
|
.SetMethod("isSwipeTrackingFromScrollEventsEnabled",
|
|
|
|
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
|
2020-03-17 18:06:52 -07:00
|
|
|
.SetMethod("getEffectiveAppearance",
|
2018-09-28 01:33:31 +10:00
|
|
|
&SystemPreferences::GetEffectiveAppearance)
|
2020-03-17 18:06:52 -07:00
|
|
|
.SetMethod("getAppLevelAppearance",
|
2018-09-28 01:33:31 +10:00
|
|
|
&SystemPreferences::GetAppLevelAppearance)
|
2020-03-17 18:06:52 -07:00
|
|
|
.SetMethod("setAppLevelAppearance",
|
2018-09-28 01:33:31 +10:00
|
|
|
&SystemPreferences::SetAppLevelAppearance)
|
2019-01-03 14:30:38 -08:00
|
|
|
.SetMethod("getSystemColor", &SystemPreferences::GetSystemColor)
|
2019-02-13 18:36:28 -08:00
|
|
|
.SetMethod("canPromptTouchID", &SystemPreferences::CanPromptTouchID)
|
|
|
|
.SetMethod("promptTouchID", &SystemPreferences::PromptTouchID)
|
2018-12-18 09:15:22 -07:00
|
|
|
.SetMethod("isTrustedAccessibilityClient",
|
|
|
|
&SystemPreferences::IsTrustedAccessibilityClient)
|
2018-12-04 07:54:13 -08:00
|
|
|
.SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess)
|
2016-04-25 12:35:09 +09:00
|
|
|
#endif
|
2019-03-19 20:15:40 +01:00
|
|
|
.SetMethod("getAnimationSettings",
|
|
|
|
&SystemPreferences::GetAnimationSettings);
|
2016-04-24 21:13:46 +09:00
|
|
|
}
|
|
|
|
|
2020-07-28 11:03:30 -07:00
|
|
|
const char* SystemPreferences::GetTypeName() {
|
|
|
|
return "SystemPreferences";
|
|
|
|
}
|
|
|
|
|
2016-04-24 21:13:46 +09:00
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|
2016-04-24 21:13:46 +09:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
using electron::api::SystemPreferences;
|
2016-08-02 20:38:35 +09:00
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2016-04-24 21:13:46 +09:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2019-10-24 14:47:58 +09:00
|
|
|
gin_helper::Dictionary dict(isolate, exports);
|
2016-08-02 20:38:35 +09:00
|
|
|
dict.Set("systemPreferences", SystemPreferences::Create(isolate));
|
2016-04-24 21:13:46 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-02-14 03:25:39 -08:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_system_preferences,
|
|
|
|
Initialize)
|