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