fix(desktop): prevent multiple app instances with single-instance plugin #6922
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
tauri-plugin-single-instanceto prevent multiple instances of OpenCode Desktop from running simultaneouslyProblem
When launching OpenCode Desktop multiple times (intentionally or accidentally), the app spawns multiple instances. Each instance:
get_sidecar_port()which binds to a random free port (sinceOPENCODE_PORTis typically not set)is_server_running(port)which returnsfalsefor the new random portopencode-cli serve --port=XXXXXprocessThis leads to:
opencode-cli serveprocesses consuming resourcesSolution
Uses Tauri's official
tauri-plugin-single-instanceplugin:This is the standard pattern recommended by Tauri for single-instance apps.
Changes
Cargo.toml: Addedtauri-plugin-single-instance = "2"dependencylib.rs: Added single-instance plugin initialization with window focus callbackTesting