Skip to content

fix: prevent duplicate instances on windows by focusing existing window - #237

Merged
morgmart merged 1 commit into
mainfrom
bot-1678-windows-single-instance
Aug 27, 2026
Merged

fix: prevent duplicate instances on windows by focusing existing window#237
morgmart merged 1 commit into
mainfrom
bot-1678-windows-single-instance

Conversation

@morgmart

Copy link
Copy Markdown
Collaborator

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 serve sidecar. macOS already handles this correctly via RunEvent::Reopen.

Solution: Register tauri-plugin-single-instance as 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 existing RunEvent::Reopen handler, which does the same show() + 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 uses RunEvent::Reopen at ~line 716) is unaffected. The callback calls show() then set_focus() on the "main" webview window — show() is required because the window starts hidden (visible: false in tauri.conf.json).

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.
@morgmart
morgmart requested a review from a team August 27, 2026 00:29
@kalvinnchau kalvinnchau changed the title prevent duplicate instances on windows by focusing existing window fix: prevent duplicate instances on windows by focusing existing window Aug 27, 2026
@morgmart
morgmart merged commit 9f377e2 into main Aug 27, 2026
9 checks passed
@morgmart
morgmart deleted the bot-1678-windows-single-instance branch August 27, 2026 00:48
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.

2 participants