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