Simplify the public PowerObserver interface

This commit is contained in:
Cheng Zhao 2018-02-05 15:28:58 +09:00
parent e0e7dd2a8f
commit 8ae3d9dd0b
5 changed files with 23 additions and 34 deletions

View file

@ -24,14 +24,6 @@ PowerMonitor::~PowerMonitor() {
base::PowerMonitor::Get()->RemoveObserver(this);
}
void PowerMonitor::BlockShutdown(mate::Arguments* args) {
atom::PowerObserver::BlockShutdown();
}
void PowerMonitor::UnblockShutdown(mate::Arguments* args) {
atom::PowerObserver::UnblockShutdown();
}
void PowerMonitor::OnPowerStateChange(bool on_battery_power) {
if (on_battery_power)
Emit("on-battery");
@ -47,9 +39,11 @@ void PowerMonitor::OnResume() {
Emit("resume");
}
#if defined(OS_LINUX)
bool PowerMonitor::OnShutdown() {
return Emit("shutdown");
}
#endif
// static
v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
@ -67,9 +61,11 @@ v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
void PowerMonitor::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "PowerMonitor"));
#if defined(OS_LINUX)
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("blockShutdown", &PowerMonitor::BlockShutdown)
.SetMethod("unblockShutdown", &PowerMonitor::UnblockShutdown);
#endif
}
} // namespace api