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.
|
|
|
|
|
|
|
|
#include "atom/browser/api/atom_api_system_preferences.h"
|
|
|
|
|
2016-04-25 05:25:14 +00:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2016-05-18 05:40:19 +00:00
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
2016-04-24 12:13:46 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
|
2016-04-25 03:35:09 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "ui/base/win/shell.h"
|
|
|
|
#endif
|
|
|
|
|
2016-04-24 12:13:46 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
|
|
|
|
Init(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemPreferences::~SystemPreferences() {
|
|
|
|
}
|
|
|
|
|
2016-04-25 03:35:09 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
bool SystemPreferences::IsAeroGlassEnabled() {
|
|
|
|
return ui::win::IsAeroGlassEnabled();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(OS_MACOSX)
|
|
|
|
bool SystemPreferences::IsDarkMode() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-24 12:13:46 +00:00
|
|
|
// static
|
|
|
|
mate::Handle<SystemPreferences> SystemPreferences::Create(
|
|
|
|
v8::Isolate* isolate) {
|
|
|
|
return mate::CreateHandle(isolate, new SystemPreferences(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void SystemPreferences::BuildPrototype(
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
2016-08-02 10:28:12 +00:00
|
|
|
prototype->SetClassName(mate::StringToV8(isolate, "SystemPreferences"));
|
2016-08-02 09:08:12 +00:00
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2016-04-25 03:35:09 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
|
2016-04-25 05:25:14 +00:00
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
.SetMethod("subscribeNotification",
|
|
|
|
&SystemPreferences::SubscribeNotification)
|
|
|
|
.SetMethod("unsubscribeNotification",
|
|
|
|
&SystemPreferences::UnsubscribeNotification)
|
2016-06-21 00:48:42 +00:00
|
|
|
.SetMethod("subscribeLocalNotification",
|
|
|
|
&SystemPreferences::SubscribeLocalNotification)
|
|
|
|
.SetMethod("unsubscribeLocalNotification",
|
|
|
|
&SystemPreferences::UnsubscribeLocalNotification)
|
2016-04-25 06:35:52 +00:00
|
|
|
.SetMethod("getUserDefault", &SystemPreferences::GetUserDefault)
|
2016-08-03 02:27:56 +00:00
|
|
|
.SetMethod("isSwipeTrackingFromScrollEventsEnabled",
|
|
|
|
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
|
2016-04-25 03:35:09 +00:00
|
|
|
#endif
|
|
|
|
.SetMethod("isDarkMode", &SystemPreferences::IsDarkMode);
|
2016-04-24 12:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-08-02 11:38:35 +00:00
|
|
|
using atom::api::SystemPreferences;
|
|
|
|
|
2016-04-24 12:13:46 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context, void* priv) {
|
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
mate::Dictionary dict(isolate, exports);
|
2016-08-02 11:38:35 +00:00
|
|
|
dict.Set("systemPreferences", SystemPreferences::Create(isolate));
|
|
|
|
dict.Set("SystemPreferences",
|
|
|
|
SystemPreferences::GetConstructor(isolate)->GetFunction());
|
2016-04-24 12:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_system_preferences, Initialize);
|