From c88974c46815c0f7a7e1292bdffc0ca1c9bb0329 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 9 Feb 2026 13:36:57 -0600 Subject: [PATCH] feat(window): restart app on system titlebar toggle Since the window must be created with the correct decoration state (runtime toggling doesn't work on Linux/Wayland), persist the setting to the Rust backend and restart the app immediately. Add restart_app Tauri command using AppHandle::restart(). Update i18n descriptions to inform the user the app will restart. --- src-tauri/src/lib.rs | 8 ++++++++ src/lib/i18n/locales/de.json | 2 +- src/lib/i18n/locales/en.json | 2 +- src/lib/i18n/locales/es.json | 2 +- src/lib/i18n/locales/fr.json | 2 +- src/lib/stores/titleBarStore.ts | 28 +++++++++++++--------------- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8075a4eef..56f09b05a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -140,6 +140,12 @@ pub fn update_media_controls_metadata( } #[cfg_attr(mobile, tauri::mobile_entry_point)] +#[tauri::command] +fn restart_app(app: tauri::AppHandle) { + log::info!("App restart requested by user"); + app.restart(); +} + pub fn run() { // Load .env file if present (for development) // Silently ignore if not found (production builds use compile-time env vars) @@ -982,6 +988,8 @@ pub fn run() { // Window settings commands config::window_settings::get_window_settings, config::window_settings::set_use_system_titlebar, + // App lifecycle commands + restart_app, // Log capture commands logging::get_backend_logs, logging::upload_logs_to_paste, diff --git a/src/lib/i18n/locales/de.json b/src/lib/i18n/locales/de.json index 518be0579..1c5005498 100644 --- a/src/lib/i18n/locales/de.json +++ b/src/lib/i18n/locales/de.json @@ -598,7 +598,7 @@ "inAppToasts": "In-App-Benachrichtigungen", "systemNotifications": "Systembenachrichtigungen", "useSystemTitleBar": "System-Titelleiste verwenden", - "useSystemTitleBarDesc": "QBZ-eigene Titelleiste durch die native Fensterdekoration des Systems ersetzen", + "useSystemTitleBarDesc": "QBZ-eigene Titelleiste durch die native Fensterdekoration des Systems ersetzen. Die App wird neu gestartet, um diese Änderung anzuwenden.", "hideTitleBar": "Titelleiste ausblenden", "hideTitleBarDesc": "Titelleiste komplett ausblenden (für Tiling-Window-Manager-Nutzer)", "immersiveDefaultView": "Standard-Ansicht im Immersiv-Modus", diff --git a/src/lib/i18n/locales/en.json b/src/lib/i18n/locales/en.json index ede44f97a..f33fdc8dc 100644 --- a/src/lib/i18n/locales/en.json +++ b/src/lib/i18n/locales/en.json @@ -617,7 +617,7 @@ "inAppToasts": "In-app toasts notifications", "systemNotifications": "System Notifications", "useSystemTitleBar": "Use system title bar", - "useSystemTitleBarDesc": "Replace QBZ custom title bar with your system's native window decorations", + "useSystemTitleBarDesc": "Replace QBZ custom title bar with your system's native window decorations. The app will restart to apply this change.", "hideTitleBar": "Hide title bar", "hideTitleBarDesc": "Hide the title bar completely (for tiling window manager users)", "immersiveDefaultView": "Immersive default view", diff --git a/src/lib/i18n/locales/es.json b/src/lib/i18n/locales/es.json index 17f879e59..6261bdcf1 100644 --- a/src/lib/i18n/locales/es.json +++ b/src/lib/i18n/locales/es.json @@ -617,7 +617,7 @@ "inAppToasts": "Notificaciones en App", "systemNotifications": "Notificaciones del Sistema", "useSystemTitleBar": "Usar barra de título del sistema", - "useSystemTitleBarDesc": "Reemplazar la barra de título personalizada de QBZ con las decoraciones nativas de tu sistema", + "useSystemTitleBarDesc": "Reemplazar la barra de título personalizada de QBZ con las decoraciones nativas de tu sistema. La app se reiniciará para aplicar este cambio.", "hideTitleBar": "Ocultar barra de título", "hideTitleBarDesc": "Ocultar completamente la barra de título (para usuarios de gestores de ventanas en mosaico)", "immersiveDefaultView": "Vista predeterminada del modo inmersivo", diff --git a/src/lib/i18n/locales/fr.json b/src/lib/i18n/locales/fr.json index 24bd98d30..94ef9b864 100644 --- a/src/lib/i18n/locales/fr.json +++ b/src/lib/i18n/locales/fr.json @@ -598,7 +598,7 @@ "inAppToasts": "Notifications toast intégrées", "systemNotifications": "Notifications système", "useSystemTitleBar": "Utiliser la barre de titre du système", - "useSystemTitleBarDesc": "Remplacer la barre de titre personnalisée de QBZ par les décorations natives de votre système", + "useSystemTitleBarDesc": "Remplacer la barre de titre personnalisée de QBZ par les décorations natives de votre système. L'application redémarrera pour appliquer ce changement.", "hideTitleBar": "Masquer la barre de titre", "hideTitleBarDesc": "Masquer complètement la barre de titre (pour les utilisateurs de gestionnaires de fenêtres en mosaïque)", "immersiveDefaultView": "Vue par défaut du mode immersif", diff --git a/src/lib/stores/titleBarStore.ts b/src/lib/stores/titleBarStore.ts index f76501a58..7b9de7555 100644 --- a/src/lib/stores/titleBarStore.ts +++ b/src/lib/stores/titleBarStore.ts @@ -8,7 +8,6 @@ * - useSystemTitleBar: Use OS native window decorations instead of custom title bar (default: false) */ -import { getCurrentWindow } from '@tauri-apps/api/window'; import { invoke } from '@tauri-apps/api/core'; const STORAGE_KEY_HIDE = 'qbz-hide-titlebar'; @@ -107,27 +106,26 @@ export function setHideTitleBar(value: boolean): void { } /** - * Set whether to use system (OS native) title bar - * Toggles Tauri window decorations and hides the custom title bar. - * Persists to both localStorage (for fast frontend init) and Rust backend - * (so decorations are set before the window is shown on next launch). + * Set whether to use system (OS native) title bar. + * Persists to both localStorage and Rust backend, then restarts the app. + * Restart is required because the window must be created with the correct + * decorations value — runtime toggling doesn't work on Linux/Wayland. */ -export function setUseSystemTitleBar(value: boolean): void { +export async function setUseSystemTitleBar(value: boolean): Promise { useSystemTitleBar = value; try { localStorage.setItem(STORAGE_KEY_SYSTEM, String(value)); } catch (e) { console.error('[TitleBarStore] Failed to save system titlebar setting:', e); } - // Persist to Rust backend (read at startup before window creation) - invoke('set_use_system_titlebar', { value }).catch((e) => { - console.error('[TitleBarStore] Failed to persist system titlebar to backend:', e); - }); - // Apply runtime decoration change for immediate effect - getCurrentWindow().setDecorations(value).catch((e) => { - console.error('[TitleBarStore] Failed to set window decorations:', e); - }); - notifyListeners(); + // Persist to Rust backend, then restart so the window is recreated + // with the correct decoration state + try { + await invoke('set_use_system_titlebar', { value }); + await invoke('restart_app'); + } catch (e) { + console.error('[TitleBarStore] Failed to persist/restart:', e); + } } export interface TitleBarState {