fix(main): guard app.on('activate') against firing before app.isReady()#326
Open
Optic00 wants to merge 1 commit into
Open
fix(main): guard app.on('activate') against firing before app.isReady()#326Optic00 wants to merge 1 commit into
Optic00 wants to merge 1 commit into
Conversation
macOS can deliver 'activate' before Electron's own 'ready' event resolves (e.g. cold launch via Dock click), which crashed with 'Cannot create BrowserWindow before app is ready'. Mirrors the isReady() guard already used in the second-instance/open-url handlers; app.whenReady().then() still creates the initial window once ready.
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.
Problem
Installed Steno.app (v0.5.8, macOS) crashed on launch with:
macOS can deliver the native
activateevent (e.g. cold launch via Dock click) before Electron's ownreadyevent resolves. Theactivatehandler had noapp.isReady()guard - unlike the siblingsecond-instanceandopen-urlhandlers in the same file, which both guard on it - so it calledcreateWindow()pre-ready and threw.Fix
Early return from the
activatehandler while!app.isReady(). No queuing needed: theapp.whenReady().then(...)path already creates the initial window once ready (unlikesecond-instance/open-url, which must preserve an incoming deep-link URL). SkippingrewarmParakeetpre-ready is fine too - the startup path does the initial warmup itself.Verification
Deterministic repro without triggering a real crash dialog: temporarily appended
app.emit('activate')at the end ofmain.js(after all top-level state is initialized, beforewhenReady()resolves) and launched viaelectron .with a scratchSTENOAI_USER_DATA_DIR:isReady=false, throws the exact production messageCannot create BrowserWindow before app is readyisReady=false, no throw; the window is created normally oncewhenReady()resolvesNo e2e spec: this is a native-event timing race in the pre-ready window, not practically reachable from Playwright (the app is already past
readyby the time a test can drive it).Summary by cubic
Prevent macOS launch crash by guarding
app.on('activate')untilapp.isReady(). Window creation now defers to the existingapp.whenReady().then(...)path.if (!app.isReady()) return;to theactivatehandler; aligns withsecond-instanceandopen-url.Written for commit 30fc88f. Summary will update on new commits.