atom_api_system_preferences.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
  5. #define ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_
  6. #include <string>
  7. #include "atom/browser/api/event_emitter.h"
  8. #include "base/callback.h"
  9. #include "base/values.h"
  10. #include "native_mate/handle.h"
  11. #if defined(OS_WIN)
  12. #include "atom/browser/browser.h"
  13. #include "atom/browser/browser_observer.h"
  14. #include "ui/gfx/sys_color_change_listener.h"
  15. #endif
  16. namespace base {
  17. class DictionaryValue;
  18. }
  19. namespace atom {
  20. namespace api {
  21. #if defined(OS_MACOSX)
  22. enum NotificationCenterKind {
  23. kNSDistributedNotificationCenter = 0,
  24. kNSNotificationCenter,
  25. kNSWorkspaceNotificationCenter,
  26. };
  27. #endif
  28. class SystemPreferences : public mate::EventEmitter<SystemPreferences>
  29. #if defined(OS_WIN)
  30. ,
  31. public BrowserObserver,
  32. public gfx::SysColorChangeListener
  33. #endif
  34. {
  35. public:
  36. static mate::Handle<SystemPreferences> Create(v8::Isolate* isolate);
  37. static void BuildPrototype(v8::Isolate* isolate,
  38. v8::Local<v8::FunctionTemplate> prototype);
  39. #if defined(OS_WIN)
  40. bool IsAeroGlassEnabled();
  41. typedef HRESULT(STDAPICALLTYPE* DwmGetColorizationColor)(DWORD*, BOOL*);
  42. DwmGetColorizationColor dwmGetColorizationColor =
  43. (DwmGetColorizationColor)GetProcAddress(LoadLibraryW(L"dwmapi.dll"),
  44. "DwmGetColorizationColor");
  45. std::string GetAccentColor();
  46. std::string GetColor(const std::string& color, mate::Arguments* args);
  47. void InitializeWindow();
  48. // gfx::SysColorChangeListener:
  49. void OnSysColorChange() override;
  50. // BrowserObserver:
  51. void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
  52. #elif defined(OS_MACOSX)
  53. using NotificationCallback =
  54. base::Callback<void(const std::string&, const base::DictionaryValue&)>;
  55. void PostNotification(const std::string& name,
  56. const base::DictionaryValue& user_info);
  57. int SubscribeNotification(const std::string& name,
  58. const NotificationCallback& callback);
  59. void UnsubscribeNotification(int id);
  60. void PostLocalNotification(const std::string& name,
  61. const base::DictionaryValue& user_info);
  62. int SubscribeLocalNotification(const std::string& name,
  63. const NotificationCallback& callback);
  64. void UnsubscribeLocalNotification(int request_id);
  65. void PostWorkspaceNotification(const std::string& name,
  66. const base::DictionaryValue& user_info);
  67. int SubscribeWorkspaceNotification(const std::string& name,
  68. const NotificationCallback& callback);
  69. void UnsubscribeWorkspaceNotification(int request_id);
  70. v8::Local<v8::Value> GetUserDefault(const std::string& name,
  71. const std::string& type);
  72. void RegisterDefaults(mate::Arguments* args);
  73. void SetUserDefault(const std::string& name,
  74. const std::string& type,
  75. mate::Arguments* args);
  76. void RemoveUserDefault(const std::string& name);
  77. bool IsSwipeTrackingFromScrollEventsEnabled();
  78. #endif
  79. bool IsDarkMode();
  80. bool IsInvertedColorScheme();
  81. protected:
  82. explicit SystemPreferences(v8::Isolate* isolate);
  83. ~SystemPreferences() override;
  84. #if defined(OS_MACOSX)
  85. void DoPostNotification(const std::string& name,
  86. const base::DictionaryValue& user_info,
  87. NotificationCenterKind kind);
  88. int DoSubscribeNotification(const std::string& name,
  89. const NotificationCallback& callback,
  90. NotificationCenterKind kind);
  91. void DoUnsubscribeNotification(int request_id, NotificationCenterKind kind);
  92. #endif
  93. private:
  94. #if defined(OS_WIN)
  95. // Static callback invoked when a message comes in to our messaging window.
  96. static LRESULT CALLBACK WndProcStatic(HWND hwnd,
  97. UINT message,
  98. WPARAM wparam,
  99. LPARAM lparam);
  100. LRESULT CALLBACK WndProc(HWND hwnd,
  101. UINT message,
  102. WPARAM wparam,
  103. LPARAM lparam);
  104. // The window class of |window_|.
  105. ATOM atom_;
  106. // The handle of the module that contains the window procedure of |window_|.
  107. HMODULE instance_;
  108. // The window used for processing events.
  109. HWND window_;
  110. std::string current_color_;
  111. bool invertered_color_scheme_;
  112. std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
  113. #endif
  114. DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
  115. };
  116. } // namespace api
  117. } // namespace atom
  118. #endif // ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_