зеркало из https://github.com/electron/electron.git
Add power-monitor module, fixes #45.
This commit is contained in:
Родитель
79870494df
Коммит
55034be104
3
atom.gyp
3
atom.gyp
|
@ -18,6 +18,7 @@
|
||||||
'browser/api/lib/ipc.coffee',
|
'browser/api/lib/ipc.coffee',
|
||||||
'browser/api/lib/menu.coffee',
|
'browser/api/lib/menu.coffee',
|
||||||
'browser/api/lib/menu-item.coffee',
|
'browser/api/lib/menu-item.coffee',
|
||||||
|
'browser/api/lib/power-monitor.coffee',
|
||||||
'browser/atom/atom.coffee',
|
'browser/atom/atom.coffee',
|
||||||
'browser/atom/objects-registry.coffee',
|
'browser/atom/objects-registry.coffee',
|
||||||
'browser/atom/rpc-server.coffee',
|
'browser/atom/rpc-server.coffee',
|
||||||
|
@ -55,6 +56,8 @@
|
||||||
'browser/api/atom_api_menu_mac.mm',
|
'browser/api/atom_api_menu_mac.mm',
|
||||||
'browser/api/atom_api_menu_win.cc',
|
'browser/api/atom_api_menu_win.cc',
|
||||||
'browser/api/atom_api_menu_win.h',
|
'browser/api/atom_api_menu_win.h',
|
||||||
|
'browser/api/atom_api_power_monitor.cc',
|
||||||
|
'browser/api/atom_api_power_monitor.h',
|
||||||
'browser/api/atom_api_window.cc',
|
'browser/api/atom_api_window.cc',
|
||||||
'browser/api/atom_api_window.h',
|
'browser/api/atom_api_window.h',
|
||||||
'browser/api/atom_browser_bindings.cc',
|
'browser/api/atom_browser_bindings.cc',
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "browser/api/atom_api_power_monitor.h"
|
||||||
|
|
||||||
|
#include "base/power_monitor/power_monitor.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
namespace api {
|
||||||
|
|
||||||
|
PowerMonitor::PowerMonitor(v8::Handle<v8::Object> wrapper)
|
||||||
|
: EventEmitter(wrapper) {
|
||||||
|
base::PowerMonitor::Get()->AddObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
PowerMonitor::~PowerMonitor() {
|
||||||
|
base::PowerMonitor::Get()->RemoveObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerMonitor::OnPowerStateChange(bool on_battery_power) {
|
||||||
|
if (on_battery_power)
|
||||||
|
Emit("on-battery");
|
||||||
|
else
|
||||||
|
Emit("on-ac");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerMonitor::OnSuspend() {
|
||||||
|
Emit("suspend");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerMonitor::OnResume() {
|
||||||
|
Emit("resume");
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
v8::Handle<v8::Value> PowerMonitor::New(const v8::Arguments& args) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
|
||||||
|
if (!args.IsConstructCall())
|
||||||
|
return node::ThrowError("Require constructor call");
|
||||||
|
|
||||||
|
new PowerMonitor(args.This());
|
||||||
|
|
||||||
|
return args.This();
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void PowerMonitor::Initialize(v8::Handle<v8::Object> target) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
|
||||||
|
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)
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_
|
||||||
|
#define ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_
|
||||||
|
|
||||||
|
#include "browser/api/atom_api_event_emitter.h"
|
||||||
|
|
||||||
|
#include "base/compiler_specific.h"
|
||||||
|
#include "base/power_monitor/power_observer.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
namespace api {
|
||||||
|
|
||||||
|
class PowerMonitor : public EventEmitter,
|
||||||
|
public base::PowerObserver {
|
||||||
|
public:
|
||||||
|
virtual ~PowerMonitor();
|
||||||
|
|
||||||
|
static void Initialize(v8::Handle<v8::Object> target);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit PowerMonitor(v8::Handle<v8::Object> wrapper);
|
||||||
|
|
||||||
|
virtual void OnPowerStateChange(bool on_battery_power) OVERRIDE;
|
||||||
|
virtual void OnSuspend() OVERRIDE;
|
||||||
|
virtual void OnResume() OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static v8::Handle<v8::Value> New(const v8::Arguments &args);
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace api
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
#endif // ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_
|
|
@ -0,0 +1,7 @@
|
||||||
|
bindings = process.atomBinding 'power_monitor'
|
||||||
|
EventEmitter = require('events').EventEmitter
|
||||||
|
|
||||||
|
PowerMonitor = bindings.PowerMonitor
|
||||||
|
PowerMonitor::__proto__ = EventEmitter.prototype
|
||||||
|
|
||||||
|
module.exports = new PowerMonitor
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "browser/atom_browser_main_parts.h"
|
#include "browser/atom_browser_main_parts.h"
|
||||||
|
|
||||||
|
#include "base/power_monitor/power_monitor.h"
|
||||||
#include "browser/api/atom_browser_bindings.h"
|
#include "browser/api/atom_browser_bindings.h"
|
||||||
#include "browser/atom_browser_client.h"
|
#include "browser/atom_browser_client.h"
|
||||||
#include "browser/atom_browser_context.h"
|
#include "browser/atom_browser_context.h"
|
||||||
|
@ -41,6 +42,10 @@ brightray::BrowserContext* AtomBrowserMainParts::CreateBrowserContext() {
|
||||||
void AtomBrowserMainParts::PostEarlyInitialization() {
|
void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||||
brightray::BrowserMainParts::PostEarlyInitialization();
|
brightray::BrowserMainParts::PostEarlyInitialization();
|
||||||
|
|
||||||
|
#if defined(OS_MACOSX)
|
||||||
|
base::PowerMonitor::AllocateSystemIOPorts();
|
||||||
|
#endif
|
||||||
|
|
||||||
node_bindings_->Initialize();
|
node_bindings_->Initialize();
|
||||||
|
|
||||||
// Wrap whole process in one global context.
|
// Wrap whole process in one global context.
|
||||||
|
|
|
@ -15,6 +15,7 @@ NODE_EXT_LIST_ITEM(atom_browser_crash_reporter)
|
||||||
NODE_EXT_LIST_ITEM(atom_browser_dialog)
|
NODE_EXT_LIST_ITEM(atom_browser_dialog)
|
||||||
NODE_EXT_LIST_ITEM(atom_browser_ipc)
|
NODE_EXT_LIST_ITEM(atom_browser_ipc)
|
||||||
NODE_EXT_LIST_ITEM(atom_browser_menu)
|
NODE_EXT_LIST_ITEM(atom_browser_menu)
|
||||||
|
NODE_EXT_LIST_ITEM(atom_browser_power_monitor)
|
||||||
NODE_EXT_LIST_ITEM(atom_browser_window)
|
NODE_EXT_LIST_ITEM(atom_browser_window)
|
||||||
|
|
||||||
// Module names start with `atom_renderer_` can only be used by renderer
|
// Module names start with `atom_renderer_` can only be used by renderer
|
||||||
|
|
Загрузка…
Ссылка в новой задаче