feat(main): requestSingleInstanceLock to prevent PTY loss on AppImage replace - #13
Merged
Merged
Conversation
… replace
On 2026-05-23, replacing the AppImage while Switchboard had active node-pty
sessions killed those sessions. The OS spawned the new binary which initialised
a second Electron process; the two instances raced and the running PTYs were
orphaned/killed.
Electron's requestSingleInstanceLock() is the standard fix:
- The first instance acquires the lock and continues normally.
- Any subsequent launch (e.g. the new AppImage binary after an in-place replace)
fails to acquire the lock, calls app.quit() immediately, and exits without
touching any PTY.
- A 'second-instance' listener on the first instance brings its main window to
the front, so the user gets visual confirmation the app is still running.
Changes:
- main.js: call app.requestSingleInstanceLock() before app.whenReady()
- Wrap app.whenReady() and all init code in the else-branch so it only runs for
the true first instance
- Register app.on('second-instance') to restore/focus mainWindow
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
On 2026-05-23, replacing the AppImage at
~/Applications/Switchboard.AppImagewhile Switchboard had activenode-ptysessions in the running Electron process killed those sessions. The OS launched the new binary, which initialised a second Electron process. The two instances raced and the running PTYs were orphaned or killed.Fix
Electron's
app.requestSingleInstanceLock()is the standard pattern for this:app.quit()immediately, and exits without touching any PTY or DB.second-instancelistener on the first instance restores and focuses the main window, giving the user visual confirmation the app is still running.Changes
main.js(lines 1601–1673): callapp.requestSingleInstanceLock()beforeapp.whenReady(); wrapapp.whenReady()and all startup code in theelse-branch so it only runs for the true first instance; registerapp.on('second-instance')to restore/focusmainWindow.Testing
node --test)