feat(main): prevent multiple app instances with single-instance lock#65
Merged
Conversation
Acquire app.requestSingleInstanceLock() before startup. A second launch (double-clicking the exe while DropPilot is in the tray, or auto-start firing alongside a manual launch) fails to acquire the lock and quits before creating a window or starting any Twitch/IPC services. Electron forwards that launch to the running process via the "second-instance" event, which restores the existing window from the tray and focuses it. A close-to-tray default means the running instance usually has a hidden but alive window, so the handler calls show()/restore() before focus(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Adds an Electron single-instance lock so only one DropPilot process can run at a time. A second launch surfaces the already-running window instead of starting a duplicate process.
Why
DropPilot defaults to close-to-tray, so the window is usually hidden-but-alive rather than closed. Without a guard, double-clicking the exe (or auto-start firing while a manual instance is already running) spins up a second process — two trackers, two PubSub connections, two trays competing over the same Twitch session.
How
In
src/main/index.ts:app.requestSingleInstanceLock()before startup. The losing instance callsapp.quit()and never creates a window or starts Twitch/IPC services.second-instanceevent by restoring the existing window from the tray (restore()/show()) and focusing it — chosen behavior: bring the running window to front.app.whenReady()callback (if (!gotSingleInstanceLock) return;) guarantees a losing instance does no startup work even ifreadystill fires.Verification
npm run typecheck(both tsconfigs): cleannpm run format:check/ prettier: cleannpm run lint: clean for the changed file (pre-existing warnings only, in unrelatedrenderer/.../watchhooks)npm test: 514 passedindex.tsis main-process lifecycle wiring and isn't unit-testable (consistent with the project's pure-function-only test convention), so there's no automated test for this path.Reviewer notes
npm run devonly ever launches one instance and vite-plugin-electron releases the lock on hot-restart; if it ever interferes, guarding withapp.isPackagedis a one-line fallback.quitAndInstallexits the old process (releasing the lock) before the new one launches.🤖 Generated with Claude Code