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.
|
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SYSTEM_PREFERENCES_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SYSTEM_PREFERENCES_H_
|
2016-04-24 06:13:46 -06:00
|
|
|
|
2018-09-12 18:25:56 -06:00
|
|
|
#include <memory>
|
2016-04-24 23:25:14 -06:00
|
|
|
#include <string>
|
|
|
|
|
2019-10-28 16:12:35 -06:00
|
|
|
#include "base/values.h"
|
2019-10-23 23:47:58 -06:00
|
|
|
#include "gin/handle.h"
|
2020-07-28 12:03:30 -06:00
|
|
|
#include "gin/wrappable.h"
|
|
|
|
#include "shell/browser/event_emitter_mixin.h"
|
2019-09-05 23:52:54 -06:00
|
|
|
#include "shell/common/gin_helper/error_thrower.h"
|
2019-11-01 00:10:32 -06:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2016-04-24 06:13:46 -06:00
|
|
|
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-06-19 14:46:59 -06:00
|
|
|
#include "shell/browser/browser.h"
|
|
|
|
#include "shell/browser/browser_observer.h"
|
2016-10-07 10:38:19 -06:00
|
|
|
#include "ui/gfx/sys_color_change_listener.h"
|
|
|
|
#endif
|
|
|
|
|
2022-06-29 13:55:47 -06:00
|
|
|
namespace electron::api {
|
2016-04-24 06:13:46 -06:00
|
|
|
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2020-12-07 21:39:33 -07:00
|
|
|
enum class NotificationCenterKind {
|
2018-03-22 03:41:03 -06:00
|
|
|
kNSDistributedNotificationCenter = 0,
|
|
|
|
kNSNotificationCenter,
|
|
|
|
kNSWorkspaceNotificationCenter,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2020-07-28 12:03:30 -06:00
|
|
|
class SystemPreferences
|
|
|
|
: public gin::Wrappable<SystemPreferences>,
|
|
|
|
public gin_helper::EventEmitterMixin<SystemPreferences>
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-04-17 19:44:10 -06:00
|
|
|
,
|
2020-07-28 12:03:30 -06:00
|
|
|
public BrowserObserver,
|
|
|
|
public gfx::SysColorChangeListener
|
2016-10-10 11:20:51 -06:00
|
|
|
#endif
|
2018-04-17 19:44:10 -06:00
|
|
|
{
|
2016-04-24 06:13:46 -06:00
|
|
|
public:
|
2019-10-23 23:47:58 -06:00
|
|
|
static gin::Handle<SystemPreferences> Create(v8::Isolate* isolate);
|
2016-04-24 06:13:46 -06:00
|
|
|
|
2020-07-28 12:03:30 -06:00
|
|
|
// gin::Wrappable
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
const char* GetTypeName() override;
|
2016-04-24 06:13:46 -06:00
|
|
|
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
|
2019-01-03 14:24:55 -07:00
|
|
|
std::string GetAccentColor();
|
2019-10-21 15:31:03 -06:00
|
|
|
std::string GetColor(gin_helper::ErrorThrower thrower,
|
|
|
|
const std::string& color);
|
2020-07-28 12:03:30 -06:00
|
|
|
std::string GetMediaAccessStatus(gin_helper::ErrorThrower thrower,
|
|
|
|
const std::string& media_type);
|
2019-01-03 14:24:55 -07:00
|
|
|
#endif
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-04-24 21:35:09 -06:00
|
|
|
bool IsAeroGlassEnabled();
|
2016-09-16 10:00:22 -06:00
|
|
|
|
|
|
|
void InitializeWindow();
|
|
|
|
|
2016-10-10 11:20:51 -06:00
|
|
|
// gfx::SysColorChangeListener:
|
|
|
|
void OnSysColorChange() override;
|
2016-09-16 10:00:22 -06:00
|
|
|
|
2017-02-02 10:34:20 -07:00
|
|
|
// BrowserObserver:
|
2022-06-23 00:28:41 -06:00
|
|
|
void OnFinishLaunching(base::Value::Dict launch_info) override;
|
2017-02-02 10:34:20 -07:00
|
|
|
|
2022-02-09 19:58:52 -07:00
|
|
|
#elif BUILDFLAG(IS_MAC)
|
2019-10-29 23:30:59 -06:00
|
|
|
using NotificationCallback = base::RepeatingCallback<
|
2022-06-23 00:28:41 -06:00
|
|
|
void(const std::string&, base::Value, const std::string&)>;
|
2019-06-10 10:34:21 -06:00
|
|
|
|
2016-08-05 15:02:59 -06:00
|
|
|
void PostNotification(const std::string& name,
|
2022-07-05 09:25:18 -06:00
|
|
|
base::Value::Dict user_info,
|
2020-07-28 12:03:30 -06:00
|
|
|
gin::Arguments* args);
|
2022-04-13 14:02:33 -06:00
|
|
|
int SubscribeNotification(v8::Local<v8::Value> maybe_name,
|
2019-06-10 10:34:21 -06:00
|
|
|
const NotificationCallback& callback);
|
2016-04-24 23:25:14 -06:00
|
|
|
void UnsubscribeNotification(int id);
|
2018-03-22 03:41:03 -06:00
|
|
|
void PostLocalNotification(const std::string& name,
|
2022-07-05 09:25:18 -06:00
|
|
|
base::Value::Dict user_info);
|
2022-04-13 14:02:33 -06:00
|
|
|
int SubscribeLocalNotification(v8::Local<v8::Value> maybe_name,
|
2019-06-10 10:34:21 -06:00
|
|
|
const NotificationCallback& callback);
|
2016-06-20 18:48:42 -06:00
|
|
|
void UnsubscribeLocalNotification(int request_id);
|
2018-03-22 03:41:03 -06:00
|
|
|
void PostWorkspaceNotification(const std::string& name,
|
2022-07-05 09:25:18 -06:00
|
|
|
base::Value::Dict user_info);
|
2022-04-13 14:02:33 -06:00
|
|
|
int SubscribeWorkspaceNotification(v8::Local<v8::Value> maybe_name,
|
2019-06-10 10:34:21 -06:00
|
|
|
const NotificationCallback& callback);
|
2018-03-22 03:41:03 -06:00
|
|
|
void UnsubscribeWorkspaceNotification(int request_id);
|
2020-07-28 12:03:30 -06:00
|
|
|
v8::Local<v8::Value> GetUserDefault(v8::Isolate* isolate,
|
|
|
|
const std::string& name,
|
2016-04-25 00:35:52 -06:00
|
|
|
const std::string& type);
|
2020-07-28 12:03:30 -06:00
|
|
|
void RegisterDefaults(gin::Arguments* args);
|
2016-11-28 16:08:22 -07:00
|
|
|
void SetUserDefault(const std::string& name,
|
|
|
|
const std::string& type,
|
2020-07-28 12:03:30 -06:00
|
|
|
gin::Arguments* args);
|
2017-10-10 13:55:15 -06:00
|
|
|
void RemoveUserDefault(const std::string& name);
|
2016-08-02 20:27:56 -06:00
|
|
|
bool IsSwipeTrackingFromScrollEventsEnabled();
|
2023-09-20 13:48:02 -06:00
|
|
|
bool AccessibilityDisplayShouldReduceTransparency();
|
2018-09-27 09:33:31 -06:00
|
|
|
|
2019-09-05 23:52:54 -06:00
|
|
|
std::string GetSystemColor(gin_helper::ErrorThrower thrower,
|
2019-08-19 10:10:18 -06:00
|
|
|
const std::string& color);
|
2019-01-03 15:30:38 -07:00
|
|
|
|
2019-02-13 19:36:28 -07:00
|
|
|
bool CanPromptTouchID();
|
|
|
|
v8::Local<v8::Promise> PromptTouchID(v8::Isolate* isolate,
|
|
|
|
const std::string& reason);
|
|
|
|
|
2019-01-03 21:40:17 -07:00
|
|
|
static bool IsTrustedAccessibilityClient(bool prompt);
|
2018-12-18 09:15:22 -07:00
|
|
|
|
2018-12-04 08:54:13 -07:00
|
|
|
v8::Local<v8::Promise> AskForMediaAccess(v8::Isolate* isolate,
|
|
|
|
const std::string& media_type);
|
|
|
|
|
2018-09-27 09:33:31 -06:00
|
|
|
// TODO(MarshallOfSound): Write tests for these methods once we
|
|
|
|
// are running tests on a Mojave machine
|
|
|
|
v8::Local<v8::Value> GetEffectiveAppearance(v8::Isolate* isolate);
|
2016-04-24 21:35:09 -06:00
|
|
|
#endif
|
2019-03-19 13:15:40 -06:00
|
|
|
v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);
|
2016-04-24 21:35:09 -06:00
|
|
|
|
2021-11-03 05:41:45 -06:00
|
|
|
// disable copy
|
|
|
|
SystemPreferences(const SystemPreferences&) = delete;
|
|
|
|
SystemPreferences& operator=(const SystemPreferences&) = delete;
|
|
|
|
|
2016-04-24 06:13:46 -06:00
|
|
|
protected:
|
2020-07-28 12:03:30 -06:00
|
|
|
SystemPreferences();
|
2016-04-24 06:13:46 -06:00
|
|
|
~SystemPreferences() override;
|
|
|
|
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2022-04-13 14:02:33 -06:00
|
|
|
int DoSubscribeNotification(v8::Local<v8::Value> maybe_name,
|
2019-06-10 10:34:21 -06:00
|
|
|
const NotificationCallback& callback,
|
|
|
|
NotificationCenterKind kind);
|
2018-03-22 03:41:03 -06:00
|
|
|
void DoUnsubscribeNotification(int request_id, NotificationCenterKind kind);
|
2016-06-20 18:48:42 -06:00
|
|
|
#endif
|
|
|
|
|
2016-04-24 06:13:46 -06:00
|
|
|
private:
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-09-16 10:00:22 -06:00
|
|
|
// Static callback invoked when a message comes in to our messaging window.
|
2018-04-17 19:44:10 -06:00
|
|
|
static LRESULT CALLBACK WndProcStatic(HWND hwnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wparam,
|
|
|
|
LPARAM lparam);
|
|
|
|
|
|
|
|
LRESULT CALLBACK WndProc(HWND hwnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wparam,
|
|
|
|
LPARAM lparam);
|
2016-09-16 10:00:22 -06:00
|
|
|
|
|
|
|
// The window class of |window_|.
|
|
|
|
ATOM atom_;
|
|
|
|
|
|
|
|
// The handle of the module that contains the window procedure of |window_|.
|
|
|
|
HMODULE instance_;
|
|
|
|
|
|
|
|
// The window used for processing events.
|
|
|
|
HWND window_;
|
|
|
|
|
|
|
|
std::string current_color_;
|
2016-10-07 10:38:19 -06:00
|
|
|
|
2017-02-02 10:34:20 -07:00
|
|
|
std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
|
2016-09-16 10:00:22 -06:00
|
|
|
#endif
|
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
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SYSTEM_PREFERENCES_H_
|