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.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
|
|
|
|
#define ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
|
|
|
|
|
2016-04-25 14:25:14 +09:00
|
|
|
#include <string>
|
|
|
|
|
2016-04-24 21:13:46 +09:00
|
|
|
#include "atom/browser/api/event_emitter.h"
|
2016-04-25 14:25:14 +09:00
|
|
|
#include "base/callback.h"
|
2016-08-05 23:02:59 +02:00
|
|
|
#include "base/values.h"
|
2016-04-24 21:13:46 +09:00
|
|
|
#include "native_mate/handle.h"
|
|
|
|
|
2016-10-07 09:38:19 -07:00
|
|
|
#if defined(OS_WIN)
|
2017-02-02 09:34:20 -08:00
|
|
|
#include "atom/browser/browser.h"
|
|
|
|
#include "atom/browser/browser_observer.h"
|
2016-10-07 09:38:19 -07:00
|
|
|
#include "ui/gfx/sys_color_change_listener.h"
|
|
|
|
#endif
|
|
|
|
|
2016-05-18 14:40:19 +09:00
|
|
|
namespace base {
|
|
|
|
class DictionaryValue;
|
|
|
|
}
|
|
|
|
|
2016-04-24 21:13:46 +09:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2018-03-22 10:41:03 +01:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
enum NotificationCenterKind {
|
|
|
|
kNSDistributedNotificationCenter = 0,
|
|
|
|
kNSNotificationCenter,
|
|
|
|
kNSWorkspaceNotificationCenter,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-10-10 10:20:51 -07:00
|
|
|
class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
|
|
|
#if defined(OS_WIN)
|
2018-04-17 21:44:10 -04: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:
|
|
|
|
static mate::Handle<SystemPreferences> Create(v8::Isolate* isolate);
|
|
|
|
|
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 18:08:12 +09:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype);
|
2016-04-24 21:13:46 +09:00
|
|
|
|
2016-04-25 12:35:09 +09:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
bool IsAeroGlassEnabled();
|
2016-09-17 02:00:22 +10:00
|
|
|
|
|
|
|
std::string GetAccentColor();
|
2016-10-10 14:31:06 -07:00
|
|
|
std::string GetColor(const std::string& color, mate::Arguments* args);
|
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;
|
|
|
|
|
2016-04-25 14:25:14 +09:00
|
|
|
#elif defined(OS_MACOSX)
|
2018-04-17 21:44:10 -04:00
|
|
|
using NotificationCallback =
|
|
|
|
base::Callback<void(const std::string&, const base::DictionaryValue&)>;
|
2016-06-20 17:48:42 -07:00
|
|
|
|
2016-08-05 23:02:59 +02:00
|
|
|
void PostNotification(const std::string& name,
|
|
|
|
const base::DictionaryValue& user_info);
|
2016-04-25 14:25:14 +09:00
|
|
|
int SubscribeNotification(const std::string& name,
|
2016-05-18 14:40:19 +09:00
|
|
|
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,
|
|
|
|
const base::DictionaryValue& user_info);
|
2016-06-20 17:48:42 -07:00
|
|
|
int SubscribeLocalNotification(const std::string& name,
|
|
|
|
const NotificationCallback& callback);
|
|
|
|
void UnsubscribeLocalNotification(int request_id);
|
2018-03-22 10:41:03 +01:00
|
|
|
void PostWorkspaceNotification(const std::string& name,
|
2018-04-17 21:44:10 -04:00
|
|
|
const base::DictionaryValue& user_info);
|
2018-03-22 10:41:03 +01:00
|
|
|
int SubscribeWorkspaceNotification(const std::string& name,
|
2018-04-17 21:44:10 -04:00
|
|
|
const NotificationCallback& callback);
|
2018-03-22 10:41:03 +01:00
|
|
|
void UnsubscribeWorkspaceNotification(int request_id);
|
2016-04-25 15:35:52 +09:00
|
|
|
v8::Local<v8::Value> GetUserDefault(const std::string& name,
|
|
|
|
const std::string& type);
|
2017-12-12 13:08:09 -05:00
|
|
|
void RegisterDefaults(mate::Arguments* args);
|
2016-11-28 15:08:22 -08:00
|
|
|
void SetUserDefault(const std::string& name,
|
|
|
|
const std::string& type,
|
|
|
|
mate::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();
|
2016-04-25 12:35:09 +09:00
|
|
|
#endif
|
|
|
|
bool IsDarkMode();
|
2016-10-07 09:38:19 -07:00
|
|
|
bool IsInvertedColorScheme();
|
2016-04-25 12:35:09 +09:00
|
|
|
|
2016-04-24 21:13:46 +09:00
|
|
|
protected:
|
|
|
|
explicit SystemPreferences(v8::Isolate* isolate);
|
|
|
|
~SystemPreferences() override;
|
|
|
|
|
2016-06-20 17:48:42 -07:00
|
|
|
#if defined(OS_MACOSX)
|
2016-08-05 23:02:59 +02:00
|
|
|
void DoPostNotification(const std::string& name,
|
|
|
|
const base::DictionaryValue& user_info,
|
2018-03-22 10:41:03 +01:00
|
|
|
NotificationCenterKind kind);
|
2016-06-20 17:48:42 -07:00
|
|
|
int DoSubscribeNotification(const std::string& name,
|
|
|
|
const NotificationCallback& callback,
|
2018-03-22 10:41:03 +01:00
|
|
|
NotificationCenterKind kind);
|
|
|
|
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
|
|
|
|
2016-10-10 10:20:51 -07:00
|
|
|
bool invertered_color_scheme_;
|
2016-10-07 09:38:19 -07: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
|
|
|
DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
|