Skip to content

fix(electron): skip single-instance lock in dev to prevent dev server…#1276

Open
dataCenter430 wants to merge 1 commit intoeigent-ai:mainfrom
dataCenter430:fix-electron-single-instance-lock
Open

fix(electron): skip single-instance lock in dev to prevent dev server…#1276
dataCenter430 wants to merge 1 commit intoeigent-ai:mainfrom
dataCenter430:fix-electron-single-instance-lock

Conversation

@dataCenter430
Copy link

Closes: #1260

Related Issue

  1. Top-level
    as soon as the main process runs, it calls requestSingleInstanceLock(). If it returns false, the process calls app.quit() and process.exit(0).
  2. In dev
    when run the app via the dev server(npm run dev), Vite starts the dev server and then starts the Electron main process(often as a child). If you start a second instance ( npm run dev again, or launch the app again), that second main process fails to get the lock and exits immediately. The dev tooling (e.g. vite-plugin-electron) sees that child process exit and can treat it as "Electron exited," so the second dev server can shut down or behave oddly.
    So the report that "the dev server can exit when a second instance starts" is correct.

Description

Single-instance is now enforced only when not running under the Vite dev server:

  1. Top-level check
    The process only quits when it doesn't get the lock and it's not in dev:
  • Use VITE_DEV_SERVER_URL (already set by the Vite dev server) to detect dev.
  • If VITE_DEV_SERVER_URL is set, the early app.quit() / process.exit(0) is skipped, so the second instance in dev does not exit and its dev server stays up.
  1. setupSingleInstanceLock()
    In dev we skip single-instance setup entirely:
  • If VITE_DEV_SERVER_URL is set, setupSingleInstanceLock() returns without calling requestSingleInstanceLock() or app.quit(), so no second-instance handling and no quit in dev.

Result

  • production/packaged app: Unchanged: only one instance; second instance quits and the first gets second-instance.
  • development: multiple instances are allowed, so the dev server no longer exits just because a second instance was started.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Contribution Guidelines Acknowledgement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Architecture and UX Improvement

1 participant