fix: prevent duplicate instances on windows by focusing existing window - #237
Merged
Conversation
Register tauri-plugin-single-instance as the first plugin on the builder, gated behind #[cfg(target_os = "windows")]. The callback shows and focuses the existing main window when a second instance is launched. macOS already handles this via RunEvent::Reopen.
kalvinnchau
approved these changes
Aug 27, 2026
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.
Category: fix
User Impact: On Windows, clicking the app icon when Berd is already running now focuses the existing window instead of launching a duplicate instance.
Problem: On Windows, launching Berd when it's already running starts a second full instance — duplicating log files, database connections, and the
goose servesidecar. macOS already handles this correctly viaRunEvent::Reopen.Solution: Register
tauri-plugin-single-instanceas the first plugin in the builder chain, gated behind#[cfg(target_os = "windows")]. The plugin uses a named mutex to detect an existing instance; the second instance exits early (before initializing any other plugins) and sends a message that triggers the existing instance to show and focus the main window. macOS continues using its existingRunEvent::Reopenhandler, which does the sameshow()+set_focus()pattern.Linear: BOT-1678
File changes
src-tauri/Cargo.toml
Added
tauri-plugin-single-instance = "2"dependency, matching the version pattern of all other tauri-plugin-* deps.src-tauri/Cargo.lock
Auto-generated lockfile entry for tauri-plugin-single-instance 2.4.3 and its transitive dependencies.
src-tauri/src/lib.rs
Registered the single-instance plugin as the first
.plugin()call on the builder, before all other plugins. Gated behind#[cfg(target_os = "windows")]so macOS (which usesRunEvent::Reopenat ~line 716) is unaffected. The callback callsshow()thenset_focus()on the"main"webview window —show()is required because the window starts hidden (visible: falsein tauri.conf.json).