feat: remove on(ready) requirement from powerMonitor (#37937)
This commit is contained in:
parent
908bef7ca9
commit
fef1b04238
3 changed files with 25 additions and 24 deletions
|
@ -1,5 +1,4 @@
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { app } from 'electron/main';
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
createPowerMonitor,
|
createPowerMonitor,
|
||||||
|
@ -14,7 +13,6 @@ class PowerMonitor extends EventEmitter {
|
||||||
// Don't start the event source until both a) the app is ready and b)
|
// Don't start the event source until both a) the app is ready and b)
|
||||||
// there's a listener registered for a powerMonitor event.
|
// there's a listener registered for a powerMonitor event.
|
||||||
this.once('newListener', () => {
|
this.once('newListener', () => {
|
||||||
app.whenReady().then(() => {
|
|
||||||
const pm = createPowerMonitor();
|
const pm = createPowerMonitor();
|
||||||
pm.emit = this.emit.bind(this);
|
pm.emit = this.emit.bind(this);
|
||||||
|
|
||||||
|
@ -36,7 +34,6 @@ class PowerMonitor extends EventEmitter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSystemIdleState (idleThreshold: number) {
|
getSystemIdleState (idleThreshold: number) {
|
||||||
|
|
|
@ -91,7 +91,6 @@ void PowerMonitor::SetListeningForShutdown(bool is_listening) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
|
v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
|
||||||
CHECK(Browser::Get()->is_ready());
|
|
||||||
auto* pm = new PowerMonitor(isolate);
|
auto* pm = new PowerMonitor(isolate);
|
||||||
auto handle = gin::CreateHandle(isolate, pm).ToV8();
|
auto handle = gin::CreateHandle(isolate, pm).ToV8();
|
||||||
pm->Pin(isolate);
|
pm->Pin(isolate);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// python-dbusmock.
|
// python-dbusmock.
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as dbus from 'dbus-native';
|
import * as dbus from 'dbus-native';
|
||||||
import { ifdescribe } from './lib/spec-helpers';
|
import { ifdescribe, startRemoteControlApp } from './lib/spec-helpers';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import { setTimeout } from 'timers/promises';
|
import { setTimeout } from 'timers/promises';
|
||||||
|
|
||||||
|
@ -135,6 +135,11 @@ describe('powerMonitor', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('is usable before app ready', async () => {
|
||||||
|
const remoteApp = await startRemoteControlApp(['--boot-eval=globalThis.initialValue=require("electron").powerMonitor.getSystemIdleTime()']);
|
||||||
|
expect(await remoteApp.remoteEval('globalThis.initialValue')).to.be.a('number');
|
||||||
|
});
|
||||||
|
|
||||||
describe('when powerMonitor module is loaded', () => {
|
describe('when powerMonitor module is loaded', () => {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
let powerMonitor: typeof Electron.powerMonitor;
|
let powerMonitor: typeof Electron.powerMonitor;
|
||||||
|
|
Loading…
Reference in a new issue