electron/shell/browser/api/atom_api_system_preferences.h

172 lines
5.7 KiB
C
Raw Normal View History

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.
2019-06-19 20:56:58 +00:00
#ifndef SHELL_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
#define SHELL_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
2016-04-24 12:13:46 +00:00
#include <memory>
#include <string>
#include "base/callback.h"
#include "base/values.h"
2016-04-24 12:13:46 +00:00
#include "native_mate/handle.h"
#include "shell/browser/api/event_emitter.h"
#include "shell/common/promise_util.h"
2016-04-24 12:13:46 +00:00
#if defined(OS_WIN)
#include "shell/browser/browser.h"
#include "shell/browser/browser_observer.h"
#include "ui/gfx/sys_color_change_listener.h"
#endif
2016-05-18 05:40:19 +00:00
namespace base {
class DictionaryValue;
}
2016-04-24 12:13:46 +00:00
namespace atom {
namespace api {
#if defined(OS_MACOSX)
enum NotificationCenterKind {
kNSDistributedNotificationCenter = 0,
kNSNotificationCenter,
kNSWorkspaceNotificationCenter,
};
#endif
class SystemPreferences : public mate::EventEmitter<SystemPreferences>
#if defined(OS_WIN)
2018-04-18 01:44:10 +00:00
,
public BrowserObserver,
public gfx::SysColorChangeListener
#endif
2018-04-18 01:44:10 +00:00
{
2016-04-24 12:13:46 +00:00
public:
static mate::Handle<SystemPreferences> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
2016-04-24 12:13:46 +00:00
#if defined(OS_WIN) || defined(OS_MACOSX)
std::string GetAccentColor();
std::string GetColor(const std::string& color, mate::Arguments* args);
#endif
#if defined(OS_WIN)
bool IsAeroGlassEnabled();
void InitializeWindow();
// gfx::SysColorChangeListener:
void OnSysColorChange() override;
// BrowserObserver:
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
#elif defined(OS_MACOSX)
using NotificationCallback =
base::RepeatingCallback<void(const std::string&,
const base::DictionaryValue&)>;
void PostNotification(const std::string& name,
const base::DictionaryValue& user_info,
mate::Arguments* args);
int SubscribeNotification(const std::string& name,
const NotificationCallback& callback);
void UnsubscribeNotification(int id);
void PostLocalNotification(const std::string& name,
const base::DictionaryValue& user_info);
int SubscribeLocalNotification(const std::string& name,
const NotificationCallback& callback);
void UnsubscribeLocalNotification(int request_id);
void PostWorkspaceNotification(const std::string& name,
2018-04-18 01:44:10 +00:00
const base::DictionaryValue& user_info);
int SubscribeWorkspaceNotification(const std::string& name,
const NotificationCallback& callback);
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);
2017-12-12 18:08:09 +00:00
void RegisterDefaults(mate::Arguments* args);
void SetUserDefault(const std::string& name,
const std::string& type,
mate::Arguments* args);
void RemoveUserDefault(const std::string& name);
bool IsSwipeTrackingFromScrollEventsEnabled();
std::string GetSystemColor(const std::string& color, mate::Arguments* args);
bool CanPromptTouchID();
v8::Local<v8::Promise> PromptTouchID(v8::Isolate* isolate,
const std::string& reason);
static bool IsTrustedAccessibilityClient(bool prompt);
// TODO(codebytere): Write tests for these methods once we
// are running tests on a Mojave machine
std::string GetMediaAccessStatus(const std::string& media_type,
mate::Arguments* args);
v8::Local<v8::Promise> AskForMediaAccess(v8::Isolate* isolate,
const std::string& media_type);
// 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);
void SetAppLevelAppearance(mate::Arguments* args);
#endif
bool IsDarkMode();
bool IsInvertedColorScheme();
bool IsHighContrastColorScheme();
v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);
2016-04-24 12:13:46 +00:00
protected:
explicit SystemPreferences(v8::Isolate* isolate);
~SystemPreferences() override;
#if defined(OS_MACOSX)
int DoSubscribeNotification(const std::string& name,
const NotificationCallback& callback,
NotificationCenterKind kind);
void DoUnsubscribeNotification(int request_id, NotificationCenterKind kind);
#endif
2016-04-24 12:13:46 +00:00
private:
#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);
// 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_;
bool invertered_color_scheme_;
bool high_contrast_color_scheme_;
std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
#endif
2016-04-24 12:13:46 +00:00
DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
};
} // namespace api
} // namespace atom
2019-06-19 20:56:58 +00:00
#endif // SHELL_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_