fix(desktop): nur eine Instanz — zweiter Start holt das Fenster nach vorne

- tauri-plugin-single-instance als erstes Plugin registriert
- show_main_window-Helper ersetzt die dreifach duplizierte Fenster-Sequenz

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-29 09:26:44 +02:00
parent bc260100f6
commit c0b145a9b0
3 changed files with 37 additions and 16 deletions
+17
View File
@@ -4034,6 +4034,22 @@ dependencies = [
"zbus", "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]] [[package]]
name = "tauri-plugin-store" name = "tauri-plugin-store"
version = "2.4.3" version = "2.4.3"
@@ -4246,6 +4262,7 @@ dependencies = [
"tauri-plugin-autostart", "tauri-plugin-autostart",
"tauri-plugin-notification", "tauri-plugin-notification",
"tauri-plugin-opener", "tauri-plugin-opener",
"tauri-plugin-single-instance",
"tauri-plugin-store", "tauri-plugin-store",
"tauri-plugin-updater", "tauri-plugin-updater",
"tauri-plugin-window-state", "tauri-plugin-window-state",
+1
View File
@@ -16,6 +16,7 @@ tauri-plugin-store = "2"
tauri-plugin-notification = "2" tauri-plugin-notification = "2"
tauri-plugin-autostart = "2" tauri-plugin-autostart = "2"
tauri-plugin-window-state = "2" tauri-plugin-window-state = "2"
tauri-plugin-single-instance = "2"
reqwest = { version = "0.12", features = ["json"] } reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
+19 -16
View File
@@ -694,8 +694,24 @@ fn get_client_info() -> String {
client_info_label(env!("CARGO_PKG_VERSION"), env!("APP_COMMIT")) 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() { pub fn run() {
let app = tauri::Builder::default() 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_store::Builder::new().build())
.plugin(tauri_plugin_notification::init()) .plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_window_state::Builder::default().build()) .plugin(tauri_plugin_window_state::Builder::default().build())
@@ -819,21 +835,12 @@ pub fn run() {
.tooltip(tray_labels(server_url.as_deref()).0) .tooltip(tray_labels(server_url.as_deref()).0)
.show_menu_on_left_click(false) .show_menu_on_left_click(false)
.on_menu_event(move |app, event| match event.id().as_ref() { .on_menu_event(move |app, event| match event.id().as_ref() {
"open" => { "open" => show_main_window(app),
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();
}
}
"change_server" => { "change_server" => {
if let Some(w) = app.get_webview_window("main") { if let Some(w) = app.get_webview_window("main") {
let _ = w.navigate(setup_page_url(cfg!(windows))); let _ = w.navigate(setup_page_url(cfg!(windows)));
let _ = w.unminimize();
let _ = w.show();
let _ = w.set_focus();
} }
show_main_window(app);
} }
"update" => { "update" => {
// `take()` verhindert Doppelklick-Downloads, der // `take()` verhindert Doppelklick-Downloads, der
@@ -889,11 +896,7 @@ pub fn run() {
.. ..
} = event } = event
{ {
if let Some(w) = tray.app_handle().get_webview_window("main") { show_main_window(tray.app_handle());
let _ = w.unminimize();
let _ = w.show();
let _ = w.set_focus();
}
} }
}) })
.build(app)?; .build(app)?;