atom_api_system_preferences.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include "atom/browser/api/atom_api_system_preferences.h"
  5. #include "atom/common/native_mate_converters/callback.h"
  6. #include "atom/common/native_mate_converters/value_converter.h"
  7. #include "atom/common/node_includes.h"
  8. #include "native_mate/dictionary.h"
  9. #include "ui/gfx/color_utils.h"
  10. namespace atom {
  11. namespace api {
  12. SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
  13. Init(isolate);
  14. #if defined(OS_WIN)
  15. InitializeWindow();
  16. #endif
  17. }
  18. SystemPreferences::~SystemPreferences() {
  19. #if defined(OS_WIN)
  20. Browser::Get()->RemoveObserver(this);
  21. #endif
  22. }
  23. #if !defined(OS_MACOSX)
  24. bool SystemPreferences::IsDarkMode() {
  25. return false;
  26. }
  27. #endif
  28. bool SystemPreferences::IsInvertedColorScheme() {
  29. return color_utils::IsInvertedColorScheme();
  30. }
  31. // static
  32. mate::Handle<SystemPreferences> SystemPreferences::Create(
  33. v8::Isolate* isolate) {
  34. return mate::CreateHandle(isolate, new SystemPreferences(isolate));
  35. }
  36. // static
  37. void SystemPreferences::BuildPrototype(
  38. v8::Isolate* isolate,
  39. v8::Local<v8::FunctionTemplate> prototype) {
  40. prototype->SetClassName(mate::StringToV8(isolate, "SystemPreferences"));
  41. mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
  42. #if defined(OS_WIN)
  43. .SetMethod("getAccentColor", &SystemPreferences::GetAccentColor)
  44. .SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
  45. .SetMethod("getColor", &SystemPreferences::GetColor)
  46. #elif defined(OS_MACOSX)
  47. .SetMethod("postNotification", &SystemPreferences::PostNotification)
  48. .SetMethod("subscribeNotification",
  49. &SystemPreferences::SubscribeNotification)
  50. .SetMethod("unsubscribeNotification",
  51. &SystemPreferences::UnsubscribeNotification)
  52. .SetMethod("postLocalNotification",
  53. &SystemPreferences::PostLocalNotification)
  54. .SetMethod("subscribeLocalNotification",
  55. &SystemPreferences::SubscribeLocalNotification)
  56. .SetMethod("unsubscribeLocalNotification",
  57. &SystemPreferences::UnsubscribeLocalNotification)
  58. .SetMethod("postWorkspaceNotification",
  59. &SystemPreferences::PostWorkspaceNotification)
  60. .SetMethod("subscribeWorkspaceNotification",
  61. &SystemPreferences::SubscribeWorkspaceNotification)
  62. .SetMethod("unsubscribeWorkspaceNotification",
  63. &SystemPreferences::UnsubscribeWorkspaceNotification)
  64. .SetMethod("registerDefaults", &SystemPreferences::RegisterDefaults)
  65. .SetMethod("getUserDefault", &SystemPreferences::GetUserDefault)
  66. .SetMethod("setUserDefault", &SystemPreferences::SetUserDefault)
  67. .SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
  68. .SetMethod("isSwipeTrackingFromScrollEventsEnabled",
  69. &SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
  70. #endif
  71. .SetMethod("isInvertedColorScheme",
  72. &SystemPreferences::IsInvertedColorScheme)
  73. .SetMethod("isDarkMode", &SystemPreferences::IsDarkMode);
  74. }
  75. } // namespace api
  76. } // namespace atom
  77. namespace {
  78. using atom::api::SystemPreferences;
  79. void Initialize(v8::Local<v8::Object> exports,
  80. v8::Local<v8::Value> unused,
  81. v8::Local<v8::Context> context,
  82. void* priv) {
  83. v8::Isolate* isolate = context->GetIsolate();
  84. mate::Dictionary dict(isolate, exports);
  85. dict.Set("systemPreferences", SystemPreferences::Create(isolate));
  86. dict.Set("SystemPreferences",
  87. SystemPreferences::GetConstructor(isolate)->GetFunction());
  88. }
  89. } // namespace
  90. NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_system_preferences, Initialize);