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.
|
|
|
|
|
2019-06-19 13:46:59 -07: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
|
|
|
|
2022-06-29 12:55:47 -07:00
|
|
|
namespace electron::api {
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2020-07-28 11:03:30 -07:00
|
|
|
gin::WrapperInfo SystemPreferences::kWrapperInfo = {gin::kEmbedderNativeGin};
|
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2023-04-26 07:09:54 -07:00
|
|
|
SystemPreferences::SystemPreferences() {
|
2016-09-17 02:00:22 +10:00
|
|
|
InitializeWindow();
|
2016-04-24 21:13:46 +09:00
|
|
|
}
|
2023-04-26 07:09:54 -07:00
|
|
|
#else
|
|
|
|
SystemPreferences::SystemPreferences() = default;
|
|
|
|
#endif
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2023-04-26 07:09:54 -07:00
|
|
|
SystemPreferences::~SystemPreferences() {
|
2017-02-02 09:34:20 -08:00
|
|
|
Browser::Get()->RemoveObserver(this);
|
2016-04-24 21:13:46 +09:00
|
|
|
}
|
2023-04-26 07:09:54 -07:00
|
|
|
#else
|
|
|
|
SystemPreferences::~SystemPreferences() = default;
|
|
|
|
#endif
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2019-03-19 20:15:40 +01:00
|
|
|
v8::Local<v8::Value> SystemPreferences::GetAnimationSettings(
|
|
|
|
v8::Isolate* isolate) {
|
2023-08-21 03:43:41 +02:00
|
|
|
auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
|
2019-03-19 20:15:40 +01: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 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)
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_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
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-09-17 02:09:28 +10:00
|
|
|
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
|
2022-02-09 18:58:52 -08:00
|
|
|
#elif BUILDFLAG(IS_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)
|
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)
|
2023-09-20 12:48:02 -07:00
|
|
|
.SetProperty(
|
|
|
|
"accessibilityDisplayShouldReduceTransparency",
|
|
|
|
&SystemPreferences::AccessibilityDisplayShouldReduceTransparency)
|
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";
|
|
|
|
}
|
|
|
|
|
2022-06-29 12:55:47 -07:00
|
|
|
} // namespace electron::api
|
2016-04-24 21:13:46 +09:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-08-02 20:38:35 +09:00
|
|
|
using electron::api::SystemPreferences;
|
|
|
|
|
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
|
|
|
|
|
2023-02-09 02:31:38 +01:00
|
|
|
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_browser_system_preferences,
|
|
|
|
Initialize)
|