Add systemPreferences module

This commit is contained in:
Cheng Zhao 2016-04-24 21:13:46 +09:00
parent 60b9ff3948
commit 13f8599ba1
7 changed files with 114 additions and 0 deletions

View file

@ -0,0 +1,48 @@
// 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"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace atom {
namespace api {
SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
Init(isolate);
}
SystemPreferences::~SystemPreferences() {
}
// static
mate::Handle<SystemPreferences> SystemPreferences::Create(
v8::Isolate* isolate) {
return mate::CreateHandle(isolate, new SystemPreferences(isolate));
}
// static
void SystemPreferences::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype);
}
} // namespace api
} // namespace atom
namespace {
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);
dict.Set("systemPreferences", atom::api::SystemPreferences::Create(isolate));
}
} // namespace
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_system_preferences, Initialize);

View file

@ -0,0 +1,34 @@
// 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_
#include "atom/browser/api/event_emitter.h"
#include "native_mate/handle.h"
namespace atom {
namespace api {
class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
public:
static mate::Handle<SystemPreferences> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
protected:
explicit SystemPreferences(v8::Isolate* isolate);
~SystemPreferences() override;
private:
DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_SYSTEM_PREFERENCES_H_

View file

@ -0,0 +1,15 @@
// 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"
namespace atom {
namespace api {
} // namespace api
} // namespace atom

View file

@ -44,6 +44,7 @@ REFERENCE_MODULE(atom_browser_power_save_blocker);
REFERENCE_MODULE(atom_browser_protocol);
REFERENCE_MODULE(atom_browser_global_shortcut);
REFERENCE_MODULE(atom_browser_session);
REFERENCE_MODULE(atom_browser_system_preferences);
REFERENCE_MODULE(atom_browser_tray);
REFERENCE_MODULE(atom_browser_web_contents);
REFERENCE_MODULE(atom_browser_web_view_manager);

View file

@ -28,6 +28,7 @@
'lib/browser/api/protocol.js',
'lib/browser/api/session.js',
'lib/browser/api/screen.js',
'lib/browser/api/system-preferences.js',
'lib/browser/api/tray.js',
'lib/browser/api/web-contents.js',
'lib/browser/chrome-extension.js',
@ -115,6 +116,9 @@
'atom/browser/api/atom_api_screen.h',
'atom/browser/api/atom_api_session.cc',
'atom/browser/api/atom_api_session.h',
'atom/browser/api/atom_api_system_preferences.cc',
'atom/browser/api/atom_api_system_preferences.h',
'atom/browser/api/atom_api_system_preferences_mac.mm',
'atom/browser/api/atom_api_tray.cc',
'atom/browser/api/atom_api_tray.h',
'atom/browser/api/atom_api_web_contents.cc',

View file

@ -89,6 +89,12 @@ Object.defineProperties(exports, {
return require('../session')
}
},
systemPreferences: {
enumerable: true,
get: function () {
return require('../system-preferences')
}
},
Tray: {
enumerable: true,
get: function () {

View file

@ -0,0 +1,6 @@
const {EventEmitter} = require('events')
const {systemPreferences} = process.atomBinding('system_preferences')
Object.setPrototypeOf(systemPreferences, EventEmitter.prototype)
module.exports = systemPreferences