Fix double-launch flashing a port-in-use error - #23
Merged
Conversation
app.quit() is asynchronous: when a second instance lost the single-instance lock, the top-level whenReady() handler still ran, booted a server into the occupied port, and showed the EADDRINUSE dialog before the queued quit landed. Gate the whenReady registration on holding the lock so the losing instance exits silently. The second-instance handler in the surviving app now also restores a minimized window (tray mode already recreated it) and brings it to the foreground - relaunching the app is now just 'show me the deck'. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FNRQP2h3GUQVThuE2KVBEu
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.
Summary
Launching Hype Ghost while it's already running no longer spawns a doomed second instance that errors with "port already in use" — it now just brings the running app to the foreground (recreating the window from tray mode, restoring it if minimized).
Changes
app.quit()is asynchronous — and theapp.whenReady().then(...)startup block was registered at top level regardless of the lock. The losing instance therefore still reachedstartServer(), collided on port 3777, and showed the EADDRINUSE dialog before its queued quit ever landed. ThewhenReadyregistration is now gated on holding the lock, so a second launch exits silently.second-instancein the surviving app): restore if minimized, recreate the window if it was destroyed to tray, then show + focus — "open the program again" now simply means "show me the deck".Verification
Risk & rollout
HG_SMOKE) holds the lock as the only instance, unchanged.Checklist
npm run smokepasses locally (or CI is green)main🤖 Generated with Claude Code
https://claude.ai/code/session_01FNRQP2h3GUQVThuE2KVBEu
Generated by Claude Code