fix(desktop): add single-instance plugin to prevent multiple windows
Problem
When launching the desktop app on Windows with plugins that take time to load (like oh-my-opencode), multiple instances spawn continuously because there's no single-instance guard. This causes 10+ windows to open.
Solution
Add tauri-plugin-single-instance which:
- Prevents multiple app instances from running simultaneously
- Focuses existing window when user tries to launch another instance
- Unminimizes window if it was minimized
Changes
-
packages/desktop/src-tauri/Cargo.toml: Addtauri-plugin-single-instance = "2" -
packages/desktop/src-tauri/src/lib.rs: Initialize single-instance plugin with focus handler
Testing
- Build desktop app with slow-loading plugins
- Try launching app multiple times quickly
- Expected: Only one window opens, subsequent launches focus existing window
Fixes #6965
The following comment was made by an LLM, it may be inaccurate:
Potential Duplicate Found
PR #6926 - "fix(desktop): add single-instance protection to prevent multiple app spawns" https://github.com/anomalyco/opencode/pull/6926
Why they're related:
Both PRs are addressing the same problem: preventing multiple instances of the desktop app from spawning simultaneously. They appear to be implementing the same solution using the tauri-plugin-single-instance plugin to prevent multiple windows and ensure the existing window is focused when a launch is attempted.
Action required: Check if PR #6926 is already merged or open, and consolidate efforts if both are addressing the same issue.
cc @Brendonovich