Implement powerMonitor 'shutdown' event for Linux.
The event is emitted when the OS is rebooting/shutting down, and allows an electron app to call `e.preventDefault()` in order to delay shutdown and exit cleanly.
This commit is contained in:
parent
28d96e2d29
commit
56b53e71aa
6 changed files with 104 additions and 2 deletions
|
@ -24,6 +24,14 @@ 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");
|
||||
|
@ -39,6 +47,10 @@ void PowerMonitor::OnResume() {
|
|||
Emit("resume");
|
||||
}
|
||||
|
||||
bool PowerMonitor::OnShutdown() {
|
||||
return Emit("shutdown");
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
|
||||
if (!Browser::Get()->is_ready()) {
|
||||
|
@ -55,6 +67,9 @@ 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"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetMethod("blockShutdown", &PowerMonitor::BlockShutdown)
|
||||
.SetMethod("unblockShutdown", &PowerMonitor::UnblockShutdown);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue