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.
|
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SYSTEM_PREFERENCES_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SYSTEM_PREFERENCES_H_
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2018-09-12 19:25:56 -05:00
|
|
|
#include <memory>
|
2016-04-25 14:25:14 +09:00
|
|
|
#include <string>
|
|
|
|
|
2019-10-28 18:12:35 -04:00
|
|
|
#include "base/values.h"
|
2019-10-24 14:47:58 +09:00
|
|
|
#include "gin/handle.h"
|
2020-07-28 11:03:30 -07:00
|
|
|
#include "gin/wrappable.h"
|
|
|
|
#include "shell/browser/event_emitter_mixin.h"
|
2019-09-06 14:52:54 +09:00
|
|
|
#include "shell/common/gin_helper/error_thrower.h"
|
2019-11-01 15:10:32 +09:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2016-10-07 09:38:19 -07:00
|
|
|
#if defined(OS_WIN)
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/browser/browser.h"
|
|
|
|
#include "shell/browser/browser_observer.h"
|
2016-10-07 09:38:19 -07:00
|
|
|
#include "ui/gfx/sys_color_change_listener.h"
|
|
|
|
#endif
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2016-04-24 21:13:46 +09:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2020-08-12 11:33:58 -07:00
|
|
|
#if defined(OS_MAC)
|
2020-12-08 05:39:33 +01:00
|
|
|
enum class NotificationCenterKind {
|
2018-03-22 10:41:03 +01:00
|
|
|
kNSDistributedNotificationCenter = 0,
|
|
|
|
kNSNotificationCenter,
|
|
|
|
kNSWorkspaceNotificationCenter,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2020-07-28 11:03:30 -07:00
|
|
|
class SystemPreferences
|
|
|
|
: public gin::Wrappable<SystemPreferences>,
|
|
|
|
public gin_helper::EventEmitterMixin<SystemPreferences>
|
2016-10-10 10:20:51 -07:00
|
|
|
#if defined(OS_WIN)
|
2018-04-17 21:44:10 -04:00
|
|
|
,
|
2020-07-28 11:03:30 -07:00
|
|
|
public BrowserObserver,
|
|
|
|
public gfx::SysColorChangeListener
|
2016-10-10 10:20:51 -07:00
|
|
|
#endif
|
2018-04-17 21:44:10 -04:00
|
|
|
{
|
2016-04-24 21:13:46 +09:00
|
|
|
public:
|
2019-10-24 14:47:58 +09:00
|
|
|
static gin::Handle<SystemPreferences> Create(v8::Isolate* isolate);
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2020-07-28 11:03:30 -07:00
|
|
|
// gin::Wrappable
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
const char* GetTypeName() override;
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2020-08-12 11:33:58 -07:00
|
|
|
#if defined(OS_WIN) || defined(OS_MAC)
|
2019-01-03 13:24:55 -08:00
|
|
|
std::string GetAccentColor();
|
2019-10-21 14:31:03 -07:00
|
|
|
std::string GetColor(gin_helper::ErrorThrower thrower,
|
|
|
|
const std::string& color);
|
2020-07-28 11:03:30 -07:00
|
|
|
std::string GetMediaAccessStatus(gin_helper::ErrorThrower thrower,
|
|
|
|
const std::string& media_type);
|
2019-01-03 13:24:55 -08:00
|
|
|
#endif
|
2016-04-25 12:35:09 +09:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
bool IsAeroGlassEnabled();
|
2016-09-17 02:00:22 +10:00
|
|
|
|
|
|
|
void InitializeWindow();
|
|
|
|
|
2016-10-10 10:20:51 -07:00
|
|
|
// gfx::SysColorChangeListener:
|
|
|
|
void OnSysColorChange() override;
|
2016-09-17 02:00:22 +10:00
|
|
|
|
2017-02-02 09:34:20 -08:00
|
|
|
// BrowserObserver:
|
|
|
|
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
|
|
|
|
|
2020-08-12 11:33:58 -07:00
|
|
|
#elif defined(OS_MAC)
|
2019-10-30 14:30:59 +09:00
|
|
|
using NotificationCallback = base::RepeatingCallback<
|
|
|
|
void(const std::string&, base::DictionaryValue, const std::string&)>;
|
2019-06-10 09:34:21 -07:00
|
|
|
|
2016-08-05 23:02:59 +02:00
|
|
|
void PostNotification(const std::string& name,
|
2019-10-30 14:30:59 +09:00
|
|
|
base::DictionaryValue user_info,
|
2020-07-28 11:03:30 -07:00
|
|
|
gin::Arguments* args);
|
2019-06-10 09:34:21 -07:00
|
|
|
int SubscribeNotification(const std::string& name,
|
|
|
|
const NotificationCallback& callback);
|
2016-04-25 14:25:14 +09:00
|
|
|
void UnsubscribeNotification(int id);
|
2018-03-22 10:41:03 +01:00
|
|
|
void PostLocalNotification(const std::string& name,
|
2019-10-30 14:30:59 +09:00
|
|
|
base::DictionaryValue user_info);
|
2019-06-10 09:34:21 -07:00
|
|
|
int SubscribeLocalNotification(const std::string& name,
|
|
|
|
const NotificationCallback& callback);
|
2016-06-20 17:48:42 -07:00
|
|
|
void UnsubscribeLocalNotification(int request_id);
|
2018-03-22 10:41:03 +01:00
|
|
|
void PostWorkspaceNotification(const std::string& name,
|
2019-10-30 14:30:59 +09:00
|
|
|
base::DictionaryValue user_info);
|
2019-06-10 09:34:21 -07:00
|
|
|
int SubscribeWorkspaceNotification(const std::string& name,
|
|
|
|
const NotificationCallback& callback);
|
2018-03-22 10:41:03 +01:00
|
|
|
void UnsubscribeWorkspaceNotification(int request_id);
|
2020-07-28 11:03:30 -07:00
|
|
|
v8::Local<v8::Value> GetUserDefault(v8::Isolate* isolate,
|
|
|
|
const std::string& name,
|
2016-04-25 15:35:52 +09:00
|
|
|
const std::string& type);
|
2020-07-28 11:03:30 -07:00
|
|
|
void RegisterDefaults(gin::Arguments* args);
|
2016-11-28 15:08:22 -08:00
|
|
|
void SetUserDefault(const std::string& name,
|
|
|
|
const std::string& type,
|
2020-07-28 11:03:30 -07:00
|
|
|
gin::Arguments* args);
|
2017-10-10 22:55:15 +03:00
|
|
|
void RemoveUserDefault(const std::string& name);
|
2016-08-03 10:27:56 +08:00
|
|
|
bool IsSwipeTrackingFromScrollEventsEnabled();
|
2018-09-28 01:33:31 +10:00
|
|
|
|
2019-09-06 14:52:54 +09:00
|
|
|
std::string GetSystemColor(gin_helper::ErrorThrower thrower,
|
2019-08-19 09:10:18 -07:00
|
|
|
const std::string& color);
|
2019-01-03 14:30:38 -08:00
|
|
|
|
2019-02-13 18:36:28 -08:00
|
|
|
bool CanPromptTouchID();
|
|
|
|
v8::Local<v8::Promise> PromptTouchID(v8::Isolate* isolate,
|
|
|
|
const std::string& reason);
|
|
|
|
|
2019-01-03 20:40:17 -08:00
|
|
|
static bool IsTrustedAccessibilityClient(bool prompt);
|
2018-12-18 09:15:22 -07:00
|
|
|
|
2018-12-04 07:54:13 -08:00
|
|
|
v8::Local<v8::Promise> AskForMediaAccess(v8::Isolate* isolate,
|
|
|
|
const std::string& media_type);
|
|
|
|
|
2018-09-28 01:33:31 +10: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);
|
|
|
|
v8::Local<v8::Value> GetAppLevelAppearance(v8::Isolate* isolate);
|
2020-07-28 11:03:30 -07:00
|
|
|
void SetAppLevelAppearance(gin::Arguments* args);
|
2016-04-25 12:35:09 +09:00
|
|
|
#endif
|
2016-10-07 09:38:19 -07:00
|
|
|
bool IsInvertedColorScheme();
|
2018-10-31 15:22:18 +01:00
|
|
|
bool IsHighContrastColorScheme();
|
2019-03-19 20:15:40 +01:00
|
|
|
v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);
|
2016-04-25 12:35:09 +09:00
|
|
|
|
2021-11-03 12:41:45 +01:00
|
|
|
// disable copy
|
|
|
|
SystemPreferences(const SystemPreferences&) = delete;
|
|
|
|
SystemPreferences& operator=(const SystemPreferences&) = delete;
|
|
|
|
|
2016-04-24 21:13:46 +09:00
|
|
|
protected:
|
2020-07-28 11:03:30 -07:00
|
|
|
SystemPreferences();
|
2016-04-24 21:13:46 +09:00
|
|
|
~SystemPreferences() override;
|
|
|
|
|
2020-08-12 11:33:58 -07:00
|
|
|
#if defined(OS_MAC)
|
2019-06-10 09:34:21 -07:00
|
|
|
int DoSubscribeNotification(const std::string& name,
|
|
|
|
const NotificationCallback& callback,
|
|
|
|
NotificationCenterKind kind);
|
2018-03-22 10:41:03 +01:00
|
|
|
void DoUnsubscribeNotification(int request_id, NotificationCenterKind kind);
|
2016-06-20 17:48:42 -07:00
|
|
|
#endif
|
|
|
|
|
2016-04-24 21:13:46 +09:00
|
|
|
private:
|
2016-09-17 02:00:22 +10:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Static callback invoked when a message comes in to our messaging window.
|
2018-04-17 21:44:10 -04: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-17 02:00:22 +10: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 09:38:19 -07:00
|
|
|
|
2021-01-26 19:16:21 +01:00
|
|
|
bool invertered_color_scheme_ = false;
|
2016-10-07 09:38:19 -07:00
|
|
|
|
2021-01-26 19:16:21 +01:00
|
|
|
bool high_contrast_color_scheme_ = false;
|
2018-10-31 15:22:18 +01:00
|
|
|
|
2017-02-02 09:34:20 -08:00
|
|
|
std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
|
2016-09-17 02:00:22 +10:00
|
|
|
#endif
|
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
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SYSTEM_PREFERENCES_H_
|