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

Conversation

ckerr
Copy link
Member

@ckerr ckerr commented Jan 28, 2020

Description of Change

powerMonitor can't be used until the app is ready; however, on Linux, powerMonitor.on() was called as soon as lib/browser/api/power-monitor.ts was loaded.

This patch takes @vladimiry's suggestion of wrapping the calls in an app.on('ready') handler to prevent powerMonitor.on() from being called prematurely. It also adds an app.isReady() test in case powerMonitor is imported after the app is ready.

Note about the caveat described there about possible sequencing errors from the lazy loading — I don't think this is an issue, because powerMonitor.on() can't be called by user code before the app is ready, and power-monitor.ts' on-ready-handler is registered as soon as power-monitor.ts is loaded. I'd welcome a second opinion on that though.

Fixes #21716.

Checklist

Release Notes

Notes: Fixed error thrown when importing powerMonitor on Linux before app's 'ready' event.

powerMonitor can't be used until the app is ready; however, on Linux,
powerMonitor.on() was called as soon as lib/browser/api/power-monitor.ts
was loaded.

This patch takes @vladimiry's suggestion of wrapping that in an
app.on('ready') handler to prevent powerMonitor.on() from being called
prematurely.

Fixes #21716
Fix the previous commit's app-is-ready handler by checking to see if
app is already ready when power-monitor.ts is loaded.
@ckerr ckerr requested a review from a team January 28, 2020 06:12
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jan 28, 2020
lib/browser/api/power-monitor.ts Outdated Show resolved Hide resolved
lib/browser/api/power-monitor.ts Outdated Show resolved Hide resolved
@ckerr
Copy link
Member Author

ckerr commented Jan 28, 2020

Will the ready event be replayed if it got fired already before this code starts? I mean power-monitor module could be loaded lazily after ready got fired already and the guess is ready event won't be replayed in this case. This is why I was thinking about using/introducing something like app.promises.ready (the promise gets resolved by app module in along with firing the ready event).

@zcbenz's suggestion of app.whenReady() takes care of this 🎉

@ckerr ckerr merged commit 1b4eb0b into master Jan 28, 2020
@release-clerk
Copy link

release-clerk bot commented Jan 28, 2020

Release Notes Persisted

Fixed error thrown when importing powerMonitor on Linux before app's 'ready' event.

@ckerr ckerr deleted the fix-21716-do-not-crash-on-require-power-monitor-on-linux branch January 28, 2020 18:19
@trop
Copy link
Contributor

trop bot commented Jan 28, 2020

I have automatically backported this PR to "7-1-x", please check out #21941

@trop
Copy link
Contributor

trop bot commented Jan 28, 2020

I have automatically backported this PR to "8-x-y", please check out #21942

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jan 29, 2020
@sofianguy sofianguy added this to Fixed in 8.0.0-beta.8 in 8.2.x Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
8.2.x
Fixed in 8.0.0-beta.8
Development

Successfully merging this pull request may close these issues.

importing powerMonitor from electron before 'ready' event causes crash
4 participants