2016-04-24 12:13:46 +00: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.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/electron_api_system_preferences.h"
|
2016-04-24 12:13:46 +00:00
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
#include "shell/common/gin_converters/callback_converter.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2019-09-08 15:10:18 +00:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2020-07-28 18:03:30 +00:00
|
|
|
#include "shell/common/gin_helper/function_template_extensions.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/node_includes.h"
|
2019-03-19 19:15:40 +00:00
|
|
|
#include "ui/gfx/animation/animation.h"
|
2016-10-06 22:27:24 +00:00
|
|
|
#include "ui/gfx/color_utils.h"
|
2019-07-15 21:37:33 +00:00
|
|
|
#include "ui/native_theme/native_theme.h"
|
2016-04-24 12:13:46 +00:00
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::api {
|
2016-04-24 12:13:46 +00:00
|
|
|
|
2020-07-28 18:03:30 +00:00
|
|
|
gin::WrapperInfo SystemPreferences::kWrapperInfo = {gin::kEmbedderNativeGin};
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2023-04-26 14:09:54 +00:00
|
|
|
SystemPreferences::SystemPreferences() {
|
2016-09-16 16:00:22 +00:00
|
|
|
InitializeWindow();
|
2016-04-24 12:13:46 +00:00
|
|
|
}
|
2023-04-26 14:09:54 +00:00
|
|
|
#else
|
|
|
|
SystemPreferences::SystemPreferences() = default;
|
|
|
|
#endif
|
2016-04-24 12:13:46 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2023-04-26 14:09:54 +00:00
|
|
|
SystemPreferences::~SystemPreferences() {
|
2017-02-02 17:34:20 +00:00
|
|
|
Browser::Get()->RemoveObserver(this);
|
2016-04-24 12:13:46 +00:00
|
|
|
}
|
2023-04-26 14:09:54 +00:00
|
|
|
#else
|
|
|
|
SystemPreferences::~SystemPreferences() = default;
|
|
|
|
#endif
|
2016-04-24 12:13:46 +00:00
|
|
|
|
2019-03-19 19:15:40 +00:00
|
|
|
v8::Local<v8::Value> SystemPreferences::GetAnimationSettings(
|
|
|
|
v8::Isolate* isolate) {
|
2023-08-21 01:43:41 +00:00
|
|
|
auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
|
2019-03-19 19:15:40 +00:00
|
|
|
dict.Set("shouldRenderRichAnimation",
|
|
|
|
gfx::Animation::ShouldRenderRichAnimation());
|
|
|
|
dict.Set("scrollAnimationsEnabledBySystem",
|
|
|
|
gfx::Animation::ScrollAnimationsEnabledBySystem());
|
|
|
|
dict.Set("prefersReducedMotion", gfx::Animation::PrefersReducedMotion());
|
|
|
|
|
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
|
2016-04-24 12:13:46 +00:00
|
|
|
// static
|
2019-10-24 05:47:58 +00:00
|
|
|
gin::Handle<SystemPreferences> SystemPreferences::Create(v8::Isolate* isolate) {
|
2020-07-28 18:03:30 +00:00
|
|
|
return gin::CreateHandle(isolate, new SystemPreferences());
|
2016-04-24 12:13:46 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 18:03:30 +00:00
|
|
|
gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) {
|
|
|
|
return gin_helper::EventEmitterMixin<
|
|
|
|
SystemPreferences>::GetObjectTemplateBuilder(isolate)
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
|
2019-01-04 00:17:07 +00:00
|
|
|
.SetMethod("getColor", &SystemPreferences::GetColor)
|
2016-09-16 16:00:22 +00:00
|
|
|
.SetMethod("getAccentColor", &SystemPreferences::GetAccentColor)
|
2020-06-25 16:47:50 +00:00
|
|
|
.SetMethod("getMediaAccessStatus",
|
|
|
|
&SystemPreferences::GetMediaAccessStatus)
|
2019-01-03 21:24:55 +00:00
|
|
|
#endif
|
2019-01-04 00:17:07 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-09-16 16:09:28 +00:00
|
|
|
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_MAC)
|
2018-04-18 01:55:30 +00:00
|
|
|
.SetMethod("postNotification", &SystemPreferences::PostNotification)
|
2016-04-25 05:25:14 +00:00
|
|
|
.SetMethod("subscribeNotification",
|
|
|
|
&SystemPreferences::SubscribeNotification)
|
|
|
|
.SetMethod("unsubscribeNotification",
|
|
|
|
&SystemPreferences::UnsubscribeNotification)
|
2018-03-22 09:41:03 +00:00
|
|
|
.SetMethod("postLocalNotification",
|
|
|
|
&SystemPreferences::PostLocalNotification)
|
2016-06-21 00:48:42 +00:00
|
|
|
.SetMethod("subscribeLocalNotification",
|
|
|
|
&SystemPreferences::SubscribeLocalNotification)
|
|
|
|
.SetMethod("unsubscribeLocalNotification",
|
|
|
|
&SystemPreferences::UnsubscribeLocalNotification)
|
2018-03-22 09:41:03 +00:00
|
|
|
.SetMethod("postWorkspaceNotification",
|
|
|
|
&SystemPreferences::PostWorkspaceNotification)
|
|
|
|
.SetMethod("subscribeWorkspaceNotification",
|
|
|
|
&SystemPreferences::SubscribeWorkspaceNotification)
|
|
|
|
.SetMethod("unsubscribeWorkspaceNotification",
|
|
|
|
&SystemPreferences::UnsubscribeWorkspaceNotification)
|
2017-12-12 18:08:09 +00:00
|
|
|
.SetMethod("registerDefaults", &SystemPreferences::RegisterDefaults)
|
2016-04-25 06:35:52 +00:00
|
|
|
.SetMethod("getUserDefault", &SystemPreferences::GetUserDefault)
|
2016-11-28 23:08:22 +00:00
|
|
|
.SetMethod("setUserDefault", &SystemPreferences::SetUserDefault)
|
2017-10-10 19:55:15 +00:00
|
|
|
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
|
2016-08-03 02:27:56 +00:00
|
|
|
.SetMethod("isSwipeTrackingFromScrollEventsEnabled",
|
|
|
|
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
|
2020-03-18 01:06:52 +00:00
|
|
|
.SetMethod("getEffectiveAppearance",
|
2018-09-27 15:33:31 +00:00
|
|
|
&SystemPreferences::GetEffectiveAppearance)
|
2019-01-03 22:30:38 +00:00
|
|
|
.SetMethod("getSystemColor", &SystemPreferences::GetSystemColor)
|
2019-02-14 02:36:28 +00:00
|
|
|
.SetMethod("canPromptTouchID", &SystemPreferences::CanPromptTouchID)
|
|
|
|
.SetMethod("promptTouchID", &SystemPreferences::PromptTouchID)
|
2018-12-18 16:15:22 +00:00
|
|
|
.SetMethod("isTrustedAccessibilityClient",
|
|
|
|
&SystemPreferences::IsTrustedAccessibilityClient)
|
2018-12-04 15:54:13 +00:00
|
|
|
.SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess)
|
2023-09-20 19:48:02 +00:00
|
|
|
.SetProperty(
|
|
|
|
"accessibilityDisplayShouldReduceTransparency",
|
|
|
|
&SystemPreferences::AccessibilityDisplayShouldReduceTransparency)
|
2016-04-25 03:35:09 +00:00
|
|
|
#endif
|
2019-03-19 19:15:40 +00:00
|
|
|
.SetMethod("getAnimationSettings",
|
|
|
|
&SystemPreferences::GetAnimationSettings);
|
2016-04-24 12:13:46 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 18:03:30 +00:00
|
|
|
const char* SystemPreferences::GetTypeName() {
|
|
|
|
return "SystemPreferences";
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api
|
2016-04-24 12:13:46 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-08-02 11:38:35 +00:00
|
|
|
using electron::api::SystemPreferences;
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2016-04-24 12:13:46 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Dictionary dict(isolate, exports);
|
2016-08-02 11:38:35 +00:00
|
|
|
dict.Set("systemPreferences", SystemPreferences::Create(isolate));
|
2016-04-24 12:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-02-09 01:31:38 +00:00
|
|
|
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_browser_system_preferences,
|
|
|
|
Initialize)
|