Skip to content

Conversation

@usvimal
Copy link
Contributor

@usvimal usvimal commented Jan 5, 2026

Summary

  • Adds tauri-plugin-single-instance to prevent multiple instances of OpenCode Desktop from running simultaneously
  • When a second instance is launched, it focuses the existing window instead of spawning a new one

Problem

When launching OpenCode Desktop multiple times (intentionally or accidentally), the app spawns multiple instances. Each instance:

  1. Calls get_sidecar_port() which binds to a random free port (since OPENCODE_PORT is typically not set)
  2. Checks is_server_running(port) which returns false for the new random port
  3. Spawns a new opencode-cli serve --port=XXXXX process

This leads to:

  • Multiple windows opening unexpectedly
  • Multiple background opencode-cli serve processes consuming resources
  • Port exhaustion in extreme cases
  • User confusion

Solution

Uses Tauri's official tauri-plugin-single-instance plugin:

  1. On app launch, the plugin acquires a system-wide lock
  2. If another instance already holds the lock, the new instance sends its arguments to the existing instance and exits
  3. The existing instance receives a callback and focuses its window

This is the standard pattern recommended by Tauri for single-instance apps.

Changes

  • Cargo.toml: Added tauri-plugin-single-instance = "2" dependency
  • lib.rs: Added single-instance plugin initialization with window focus callback

Testing

  • Launch app → works normally
  • Launch app again → existing window focuses, no new instance spawned
  • Close app → lock released, can launch fresh instance

@usvimal usvimal requested a review from adamdotdevin as a code owner January 5, 2026 08:45
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

The following comment was made by an LLM, it may be inaccurate:

Duplicate Check Results

No duplicates found

The PR you're checking appears to be unique. The only matching result across all searches is the PR itself (#6922).

The one tangentially related PR that appeared in the results:

Conclusion: This PR is safe to proceed. There are no duplicate or conflicting PRs addressing the same single-instance plugin feature for preventing multiple app instances.

@usvimal usvimal closed this Jan 5, 2026
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.

1 participant