This commit is contained in:
Cheng Zhao 2014-04-17 17:13:17 +08:00
Родитель 7106a36ccb
Коммит 7c50393c72
3 изменённых файлов: 32 добавлений и 36 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_monitor_device_source.h"
#include "native_mate/dictionary.h"
#include "atom/common/node_includes.h"
@ -13,8 +14,7 @@ namespace atom {
namespace api {
PowerMonitor::PowerMonitor(v8::Handle<v8::Object> wrapper)
: EventEmitter(wrapper) {
PowerMonitor::PowerMonitor() {
base::PowerMonitor::Get()->AddObserver(this);
}
@ -38,30 +38,29 @@ void PowerMonitor::OnResume() {
}
// static
void PowerMonitor::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (!args.IsConstructCall())
return node::ThrowError("Require constructor call");
new PowerMonitor(args.This());
mate::Handle<PowerMonitor> PowerMonitor::Create(v8::Isolate* isolate) {
return CreateHandle(isolate, new PowerMonitor);
}
// static
void PowerMonitor::Initialize(v8::Handle<v8::Object> target) {
#if defined(OS_MACOSX)
base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
#endif
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(
PowerMonitor::New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(v8::String::NewSymbol("PowerMonitor"));
target->Set(v8::String::NewSymbol("PowerMonitor"), t->GetFunction());
}
} // namespace api
} // namespace atom
NODE_MODULE(atom_browser_power_monitor, atom::api::PowerMonitor::Initialize)
namespace {
void Initialize(v8::Handle<v8::Object> exports) {
#if defined(OS_MACOSX)
base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
#endif
using atom::api::PowerMonitor;
v8::Isolate* isolate = v8::Isolate::GetCurrent();
mate::Handle<PowerMonitor> power_monitor = PowerMonitor::Create(isolate);
mate::Dictionary dict(isolate, exports);
dict.Set("powerMonitor", power_monitor);
}
} // namespace
NODE_MODULE(atom_browser_power_monitor, Initialize)

Просмотреть файл

@ -5,31 +5,29 @@
#ifndef ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#define ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#include "atom/browser/api/event_emitter.h"
#include "base/compiler_specific.h"
#include "base/power_monitor/power_observer.h"
#include "atom/common/api/atom_api_event_emitter.h"
#include "native_mate/handle.h"
namespace atom {
namespace api {
class PowerMonitor : public EventEmitter,
class PowerMonitor : public mate::EventEmitter,
public base::PowerObserver {
public:
virtual ~PowerMonitor();
static void Initialize(v8::Handle<v8::Object> target);
static mate::Handle<PowerMonitor> Create(v8::Isolate* isolate);
protected:
explicit PowerMonitor(v8::Handle<v8::Object> wrapper);
explicit PowerMonitor();
virtual ~PowerMonitor();
// base::PowerObserver implementations:
virtual void OnPowerStateChange(bool on_battery_power) OVERRIDE;
virtual void OnSuspend() OVERRIDE;
virtual void OnResume() OVERRIDE;
private:
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
};

Просмотреть файл

@ -1,7 +1,6 @@
bindings = process.atomBinding 'power_monitor'
powerMonitor = process.atomBinding('power_monitor').powerMonitor
EventEmitter = require('events').EventEmitter
PowerMonitor = bindings.PowerMonitor
PowerMonitor::__proto__ = EventEmitter.prototype
powerMonitor.__proto__ = EventEmitter.prototype
module.exports = new PowerMonitor
module.exports = powerMonitor