Skip to content

Fix: Cannot create BrowserWindow before app is ready - #79

Merged
wojtekn merged 4 commits into
trunkfrom
fix/app-error-create-browser-window
May 6, 2024
Merged

Fix: Cannot create BrowserWindow before app is ready#79
wojtekn merged 4 commits into
trunkfrom
fix/app-error-create-browser-window

Conversation

@katinthehatsite

@katinthehatsite katinthehatsite commented May 2, 2024

Copy link
Copy Markdown
Contributor

Related to https://github.com/Automattic/dotcom-forge/issues/6878

Proposed Changes

This PR adds additional app.isReady() check to app.on( 'activate') to ensure that the app is ready before it attempts to create a browser window.

Testing Instructions

  • Pull the changes from this branch locally
  • Run nvm use && npm install && npm start to start the app
  • Press cmd + W on macOS to close the app window but keep the app running
  • Open the app again
  • Confirm there are no errors in the terminal

Notes
I spent some time trying to trigger the error manually but with no luck. It seems that the steps that a user might take to trigger this error would be (since activate event is specifically designed for macOS, it would need to be tested on Mac):

  • Run the application.
  • Close the main window but do not quit the application. (Typically CMD + W on macOS)
  • Click the application icon in the dock to reactivate it.
  • I also tried simulating the activate event starting early before the app is ready by adding something like app.emit( 'activate' ) early after app initialization but that also did not trigger the error on my end;
  • I am assuming that the fix would work as app.isReady() would need to be true first before the BrowserWindow is created. It seems that the activate event can possible fire ( https://github.com/Automattic/dotcom-forge/issues/6878#issuecomment-2087334306 ) before the ready event so it makes sense to add this guard in that case.

If you have any good suggestions on how to test this, let me know!

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@katinthehatsite katinthehatsite self-assigned this May 2, 2024
@dcalhoun

dcalhoun commented May 2, 2024

Copy link
Copy Markdown
Member

👋🏻 @katinthehatsite. I coincidently encountered the test failures blocking this PR. I addressed them in #80 if you have time to review. 🙇🏻 Once that merges, updating this branch with the latest trunk should fix the failing CI checks.

@katinthehatsite

Copy link
Copy Markdown
Contributor Author

Hye @dcalhoun - thanks for the fix! I approved the PR you mentioned 👍

@sejas

sejas commented May 2, 2024

Copy link
Copy Markdown
Member

I updated trunk and that fixes the unit tests 👌 .

I also forgot to change the branch, and continued working in other issue. I pushed a commit and then reverted it 😅 , sorry for the noise.

@katinthehatsite
katinthehatsite requested a review from a team May 3, 2024 14:27

@wojtekn wojtekn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works fine, and the code change looks clear. Thanks for the fix.

@wojtekn
wojtekn merged commit 6c0d86d into trunk May 6, 2024
@wojtekn
wojtekn deleted the fix/app-error-create-browser-window branch May 6, 2024 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants