Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use powerMonitor.on() only after app is ready #21927

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/browser/api/power-monitor.ts
Expand Up @@ -18,21 +18,27 @@ if (process.platform === 'linux') {
*
* So here we watch for 'shutdown' listeners to be added or removed and
* set or unset our shutdown delay lock accordingly. */
const { app } = require('electron')
app.once('ready', (): void => {
const onceReady = (): void => {
powerMonitor.on('newListener', (event: string) => {
// if first shutdown listener added
// whenever the listener count is incremented to one...
if (event === 'shutdown' && powerMonitor.listenerCount('shutdown') === 0) {
powerMonitor.blockShutdown()
}
})
powerMonitor.on('removeListener', (event: string) => {
// if last shutdown listener removed
// whenever the listener count is decremented to zero...
if (event === 'shutdown' && powerMonitor.listenerCount('shutdown') === 0) {
powerMonitor.unblockShutdown()
}
})
})
}

const { app } = require('electron')
if (app.isReady()) {
ckerr marked this conversation as resolved.
Show resolved Hide resolved
onceReady()
} else {
app.once('ready', onceReady)
ckerr marked this conversation as resolved.
Show resolved Hide resolved
}
}

module.exports = powerMonitor