fix: use powerMonitor.on() only after app is ready#21927
Merged
Conversation
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.
vladimiry
reviewed
Jan 28, 2020
vladimiry
approved these changes
Jan 28, 2020
zcbenz
reviewed
Jan 28, 2020
Member
Author
@zcbenz's suggestion of app.whenReady() takes care of this 🎉 |
codebytere
approved these changes
Jan 28, 2020
|
Release Notes Persisted
|
This was referenced Jan 28, 2020
Contributor
|
I have automatically backported this PR to "7-1-x", please check out #21941 |
Contributor
|
I have automatically backported this PR to "8-x-y", please check out #21942 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
npm testpassesRelease Notes
Notes: Fixed error thrown when importing powerMonitor on Linux before app's 'ready' event.