Skip to content

Commit f510d17

Browse files
authored
fix(desktop): add single-instance plugin to prevent multiple windows (#6966)
1 parent 45fea65 commit f510d17

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

packages/desktop/src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ tauri-plugin-window-state = "2"
2929
tauri-plugin-clipboard-manager = "2"
3030
tauri-plugin-http = "2"
3131
tauri-plugin-notification = "2"
32+
tauri-plugin-single-instance = "2"
3233

3334
serde = { version = "1", features = ["derive"] }
3435
serde_json = "1"

packages/desktop/src-tauri/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ pub fn run() {
189189
let updater_enabled = option_env!("TAURI_SIGNING_PRIVATE_KEY").is_some();
190190

191191
let mut builder = tauri::Builder::default()
192+
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
193+
// Focus existing window when another instance is launched
194+
if let Some(window) = app.get_webview_window("main") {
195+
let _ = window.set_focus();
196+
let _ = window.unminimize();
197+
}
198+
}))
192199
.plugin(tauri_plugin_os::init())
193200
.plugin(tauri_plugin_window_state::Builder::new().build())
194201
.plugin(tauri_plugin_store::Builder::new().build())

0 commit comments

Comments
 (0)