diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lock index 1b2566d..cbc8657 100644 --- a/apps/desktop/src-tauri/Cargo.lock +++ b/apps/desktop/src-tauri/Cargo.lock @@ -4034,6 +4034,22 @@ dependencies = [ "zbus", ] +[[package]] +name = "tauri-plugin-single-instance" +version = "2.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db817fe9295e19b7d8357e900af31edb93703dd9fb6de524b007b47b6afc63b0" +dependencies = [ + "serde", + "serde_json", + "tauri", + "thiserror 2.0.18", + "tokio", + "tracing", + "windows-sys 0.60.2", + "zbus", +] + [[package]] name = "tauri-plugin-store" version = "2.4.3" @@ -4246,6 +4262,7 @@ dependencies = [ "tauri-plugin-autostart", "tauri-plugin-notification", "tauri-plugin-opener", + "tauri-plugin-single-instance", "tauri-plugin-store", "tauri-plugin-updater", "tauri-plugin-window-state", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 56dd48c..7898ef9 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -16,6 +16,7 @@ tauri-plugin-store = "2" tauri-plugin-notification = "2" tauri-plugin-autostart = "2" tauri-plugin-window-state = "2" +tauri-plugin-single-instance = "2" reqwest = { version = "0.12", features = ["json"] } serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index f8bb74a..7f2364c 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -694,8 +694,24 @@ fn get_client_info() -> String { client_info_label(env!("CARGO_PKG_VERSION"), env!("APP_COMMIT")) } +/// Hauptfenster nach vorne holen. Ein minimiertes Fenster (z. B. per Win+D) +/// wird zuerst wiederhergestellt. +fn show_main_window(app: &AppHandle) { + if let Some(w) = app.get_webview_window("main") { + let _ = w.unminimize(); + let _ = w.show(); + let _ = w.set_focus(); + } +} + pub fn run() { let app = tauri::Builder::default() + // Muss als erstes Plugin stehen. Verhindert den Doppelstart (z. B. beim + // Windows-Login) mit zwei Tray-Symbolen: Ein zweiter Start holt nur das + // Fenster der laufenden Instanz nach vorne und beendet sich sofort. + .plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| { + show_main_window(app); + })) .plugin(tauri_plugin_store::Builder::new().build()) .plugin(tauri_plugin_notification::init()) .plugin(tauri_plugin_window_state::Builder::default().build()) @@ -819,21 +835,12 @@ pub fn run() { .tooltip(tray_labels(server_url.as_deref()).0) .show_menu_on_left_click(false) .on_menu_event(move |app, event| match event.id().as_ref() { - "open" => { - if let Some(w) = app.get_webview_window("main") { - // Minimiertes Fenster (z. B. per Win+D) zuerst wiederherstellen - let _ = w.unminimize(); - let _ = w.show(); - let _ = w.set_focus(); - } - } + "open" => show_main_window(app), "change_server" => { if let Some(w) = app.get_webview_window("main") { let _ = w.navigate(setup_page_url(cfg!(windows))); - let _ = w.unminimize(); - let _ = w.show(); - let _ = w.set_focus(); } + show_main_window(app); } "update" => { // `take()` verhindert Doppelklick-Downloads, der @@ -889,11 +896,7 @@ pub fn run() { .. } = event { - if let Some(w) = tray.app_handle().get_webview_window("main") { - let _ = w.unminimize(); - let _ = w.show(); - let _ = w.set_focus(); - } + show_main_window(tray.app_handle()); } }) .build(app)?;