From c9ba3a69cfa103d844d6c76a198c263207fc5fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=B0=B8=E8=B5=AB?= <1259085392@qq.com> Date: Sun, 5 Jul 2026 21:45:57 +0900 Subject: [PATCH 1/5] fix: prevent silent launch window flash --- .../prepare-resources/tauri-config.test.mjs | 16 +++++++ src-tauri/src/app_runtime.rs | 47 ++++++++++++++++--- src-tauri/tauri.conf.json | 1 + 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/scripts/prepare-resources/tauri-config.test.mjs b/scripts/prepare-resources/tauri-config.test.mjs index 387c0c8f..908d6914 100644 --- a/scripts/prepare-resources/tauri-config.test.mjs +++ b/scripts/prepare-resources/tauri-config.test.mjs @@ -19,3 +19,19 @@ test('main Tauri window disables background throttling', async () => { 'expected the main window to disable background throttling', ); }); + +test('main Tauri window starts hidden to avoid silent-launch flash', async () => { + const tauriConfig = JSON.parse(await readFile(tauriConfigPath, 'utf8')); + const windows = tauriConfig?.app?.windows; + + assert.ok(Array.isArray(windows), 'expected tauri config app.windows to be an array'); + + const mainWindow = windows.find((windowConfig) => windowConfig.label === 'main'); + + assert.ok(mainWindow, 'expected tauri config to define a main window'); + assert.equal( + mainWindow.visible, + false, + 'expected the main window to stay hidden until startup settings are applied', + ); +}); diff --git a/src-tauri/src/app_runtime.rs b/src-tauri/src/app_runtime.rs index 16e266cc..a6822ed7 100644 --- a/src-tauri/src/app_runtime.rs +++ b/src-tauri/src/app_runtime.rs @@ -9,9 +9,18 @@ use crate::{ DEFAULT_SHELL_LOCALE, DESKTOP_LOG_FILE, STARTUP_MODE_ENV, }; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum StartupWindowAction { + KeepHidden, + Show, +} + +#[cfg(target_os = "linux")] const WEBKIT_DISABLE_DMABUF_RENDERER_ENV: &str = "WEBKIT_DISABLE_DMABUF_RENDERER"; +#[cfg(target_os = "linux")] const WAYLAND_DISPLAY_ENV: &str = "WAYLAND_DISPLAY"; +#[cfg(any(target_os = "linux", test))] fn should_set_webkit_dmabuf_renderer_env( existing_value: Option<&std::ffi::OsStr>, wayland_display: Option<&std::ffi::OsStr>, @@ -148,6 +157,14 @@ fn configure_page_load_events(builder: Builder) -> Builder StartupWindowAction { + if silent_launch { + StartupWindowAction::KeepHidden + } else { + StartupWindowAction::Show + } +} + fn configure_setup(builder: Builder) -> Builder { builder.setup(|app| { let app_handle = app.handle().clone(); @@ -157,13 +174,23 @@ fn configure_setup(builder: Builder) -> Builder { crate::windows_shutdown::install(&app_handle); let desktop_settings = app_handle.state::().get(); - if desktop_settings.silent_launch { - append_startup_log("silent launch enabled, hiding main window"); - window::actions::hide_main_window( - &app_handle, - DEFAULT_SHELL_LOCALE, - append_desktop_log, - ); + match startup_window_action(desktop_settings.silent_launch) { + StartupWindowAction::KeepHidden => { + append_startup_log("silent launch enabled, keeping main window hidden"); + tray::labels::update_tray_menu_labels_with_visibility( + &app_handle, + DEFAULT_SHELL_LOCALE, + Some(false), + append_desktop_log, + ); + } + StartupWindowAction::Show => { + window::actions::show_main_window( + &app_handle, + DEFAULT_SHELL_LOCALE, + append_desktop_log, + ); + } } startup_task::spawn_startup_task(app_handle.clone(), append_startup_log); @@ -262,4 +289,10 @@ mod tests { None )); } + + #[test] + fn startup_window_action_keeps_window_hidden_for_silent_launch() { + assert_eq!(startup_window_action(true), StartupWindowAction::KeepHidden); + assert_eq!(startup_window_action(false), StartupWindowAction::Show); + } } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 17323c40..dea23ed2 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -19,6 +19,7 @@ "minWidth": 980, "minHeight": 680, "resizable": true, + "visible": false, "fullscreen": false, "backgroundThrottling": "disabled" } From c5409f34e8a3924c51d26f2ad6153f752d1bacaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=B0=B8=E8=B5=AB?= <1259085392@qq.com> Date: Sun, 5 Jul 2026 21:50:30 +0900 Subject: [PATCH 2/5] refactor: inline silent launch window behavior --- src-tauri/src/app_runtime.rs | 51 ++++++++++-------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/src-tauri/src/app_runtime.rs b/src-tauri/src/app_runtime.rs index a6822ed7..e7597086 100644 --- a/src-tauri/src/app_runtime.rs +++ b/src-tauri/src/app_runtime.rs @@ -9,12 +9,6 @@ use crate::{ DEFAULT_SHELL_LOCALE, DESKTOP_LOG_FILE, STARTUP_MODE_ENV, }; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -enum StartupWindowAction { - KeepHidden, - Show, -} - #[cfg(target_os = "linux")] const WEBKIT_DISABLE_DMABUF_RENDERER_ENV: &str = "WEBKIT_DISABLE_DMABUF_RENDERER"; #[cfg(target_os = "linux")] @@ -157,14 +151,6 @@ fn configure_page_load_events(builder: Builder) -> Builder StartupWindowAction { - if silent_launch { - StartupWindowAction::KeepHidden - } else { - StartupWindowAction::Show - } -} - fn configure_setup(builder: Builder) -> Builder { builder.setup(|app| { let app_handle = app.handle().clone(); @@ -174,23 +160,20 @@ fn configure_setup(builder: Builder) -> Builder { crate::windows_shutdown::install(&app_handle); let desktop_settings = app_handle.state::().get(); - match startup_window_action(desktop_settings.silent_launch) { - StartupWindowAction::KeepHidden => { - append_startup_log("silent launch enabled, keeping main window hidden"); - tray::labels::update_tray_menu_labels_with_visibility( - &app_handle, - DEFAULT_SHELL_LOCALE, - Some(false), - append_desktop_log, - ); - } - StartupWindowAction::Show => { - window::actions::show_main_window( - &app_handle, - DEFAULT_SHELL_LOCALE, - append_desktop_log, - ); - } + if desktop_settings.silent_launch { + append_startup_log("silent launch enabled, keeping main window hidden"); + tray::labels::update_tray_menu_labels_with_visibility( + &app_handle, + DEFAULT_SHELL_LOCALE, + Some(false), + append_desktop_log, + ); + } else { + window::actions::show_main_window( + &app_handle, + DEFAULT_SHELL_LOCALE, + append_desktop_log, + ); } startup_task::spawn_startup_task(app_handle.clone(), append_startup_log); @@ -289,10 +272,4 @@ mod tests { None )); } - - #[test] - fn startup_window_action_keeps_window_hidden_for_silent_launch() { - assert_eq!(startup_window_action(true), StartupWindowAction::KeepHidden); - assert_eq!(startup_window_action(false), StartupWindowAction::Show); - } } From 91484f3c1eae8e939c43c0d6992627098382b247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=B0=B8=E8=B5=AB?= <1259085392@qq.com> Date: Mon, 6 Jul 2026 10:56:46 +0900 Subject: [PATCH 3/5] fix: align linux webkit workaround cfg --- src-tauri/src/app_runtime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/app_runtime.rs b/src-tauri/src/app_runtime.rs index e7597086..f85b8514 100644 --- a/src-tauri/src/app_runtime.rs +++ b/src-tauri/src/app_runtime.rs @@ -14,7 +14,7 @@ const WEBKIT_DISABLE_DMABUF_RENDERER_ENV: &str = "WEBKIT_DISABLE_DMABUF_RENDERER #[cfg(target_os = "linux")] const WAYLAND_DISPLAY_ENV: &str = "WAYLAND_DISPLAY"; -#[cfg(any(target_os = "linux", test))] +#[cfg(target_os = "linux")] fn should_set_webkit_dmabuf_renderer_env( existing_value: Option<&std::ffi::OsStr>, wayland_display: Option<&std::ffi::OsStr>, @@ -244,7 +244,7 @@ pub(crate) fn run() { .run(handle_run_event); } -#[cfg(test)] +#[cfg(all(test, target_os = "linux"))] mod tests { use super::*; From 14a6c2346d754190fd2c38c1597b77a863c6bd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=B0=B8=E8=B5=AB?= <1259085392@qq.com> Date: Mon, 6 Jul 2026 11:09:21 +0900 Subject: [PATCH 4/5] refactor: centralize startup visibility handling --- src-tauri/src/app_runtime.rs | 138 +++++++++++++++++------------------ 1 file changed, 66 insertions(+), 72 deletions(-) diff --git a/src-tauri/src/app_runtime.rs b/src-tauri/src/app_runtime.rs index f85b8514..9dd4964f 100644 --- a/src-tauri/src/app_runtime.rs +++ b/src-tauri/src/app_runtime.rs @@ -3,38 +3,67 @@ use tauri::{ Builder, Manager, RunEvent, WindowEvent, }; -use crate::{ - app_runtime_events, append_desktop_log, append_startup_log, bridge, desktop_settings, - lifecycle, runtime_paths, startup_task, tray, window, BackendState, DesktopSettingsCache, - DEFAULT_SHELL_LOCALE, DESKTOP_LOG_FILE, STARTUP_MODE_ENV, -}; - -#[cfg(target_os = "linux")] -const WEBKIT_DISABLE_DMABUF_RENDERER_ENV: &str = "WEBKIT_DISABLE_DMABUF_RENDERER"; #[cfg(target_os = "linux")] -const WAYLAND_DISPLAY_ENV: &str = "WAYLAND_DISPLAY"; +mod linux_webkit_workaround { + const WEBKIT_DISABLE_DMABUF_RENDERER_ENV: &str = "WEBKIT_DISABLE_DMABUF_RENDERER"; + const WAYLAND_DISPLAY_ENV: &str = "WAYLAND_DISPLAY"; -#[cfg(target_os = "linux")] -fn should_set_webkit_dmabuf_renderer_env( - existing_value: Option<&std::ffi::OsStr>, - wayland_display: Option<&std::ffi::OsStr>, -) -> bool { - existing_value.is_none() && wayland_display.is_some() -} + fn should_set_webkit_dmabuf_renderer_env( + existing_value: Option<&std::ffi::OsStr>, + wayland_display: Option<&std::ffi::OsStr>, + ) -> bool { + existing_value.is_none() && wayland_display.is_some() + } -#[cfg(target_os = "linux")] -fn configure_linux_webkit_workarounds() { - if should_set_webkit_dmabuf_renderer_env( - std::env::var_os(WEBKIT_DISABLE_DMABUF_RENDERER_ENV).as_deref(), - std::env::var_os(WAYLAND_DISPLAY_ENV).as_deref(), - ) { - std::env::set_var(WEBKIT_DISABLE_DMABUF_RENDERER_ENV, "1"); - append_startup_log(&format!( - "applied Linux WebKit workaround: set {WEBKIT_DISABLE_DMABUF_RENDERER_ENV}=1" - )); + pub(super) fn configure(log: impl Fn(&str)) { + if should_set_webkit_dmabuf_renderer_env( + std::env::var_os(WEBKIT_DISABLE_DMABUF_RENDERER_ENV).as_deref(), + std::env::var_os(WAYLAND_DISPLAY_ENV).as_deref(), + ) { + std::env::set_var(WEBKIT_DISABLE_DMABUF_RENDERER_ENV, "1"); + log(&format!( + "applied Linux WebKit workaround: set {WEBKIT_DISABLE_DMABUF_RENDERER_ENV}=1" + )); + } + } + + #[cfg(test)] + mod tests { + use super::should_set_webkit_dmabuf_renderer_env; + + #[test] + fn webkit_dmabuf_workaround_is_set_only_for_wayland_without_override() { + assert!(should_set_webkit_dmabuf_renderer_env( + None, + Some(std::ffi::OsStr::new("wayland-0")) + )); + assert!(!should_set_webkit_dmabuf_renderer_env(None, None)); + assert!(!should_set_webkit_dmabuf_renderer_env( + Some(std::ffi::OsStr::new("0")), + Some(std::ffi::OsStr::new("wayland-0")) + )); + assert!(!should_set_webkit_dmabuf_renderer_env( + Some(std::ffi::OsStr::new("1")), + Some(std::ffi::OsStr::new("wayland-0")) + )); + assert!(!should_set_webkit_dmabuf_renderer_env( + Some(std::ffi::OsStr::new("0")), + None + )); + assert!(!should_set_webkit_dmabuf_renderer_env( + Some(std::ffi::OsStr::new("1")), + None + )); + } } } +use crate::{ + app_runtime_events, append_desktop_log, append_startup_log, bridge, desktop_settings, + lifecycle, runtime_paths, startup_task, tray, window, BackendState, DesktopSettingsCache, + DEFAULT_SHELL_LOCALE, DESKTOP_LOG_FILE, STARTUP_MODE_ENV, +}; + fn configure_plugins(builder: Builder) -> Builder { builder .plugin(tauri_plugin_autostart::init( @@ -151,6 +180,15 @@ fn configure_page_load_events(builder: Builder) -> Builder) -> Builder { builder.setup(|app| { let app_handle = app.handle().clone(); @@ -160,21 +198,7 @@ fn configure_setup(builder: Builder) -> Builder { crate::windows_shutdown::install(&app_handle); let desktop_settings = app_handle.state::().get(); - if desktop_settings.silent_launch { - append_startup_log("silent launch enabled, keeping main window hidden"); - tray::labels::update_tray_menu_labels_with_visibility( - &app_handle, - DEFAULT_SHELL_LOCALE, - Some(false), - append_desktop_log, - ); - } else { - window::actions::show_main_window( - &app_handle, - DEFAULT_SHELL_LOCALE, - append_desktop_log, - ); - } + apply_startup_window_visibility(&app_handle, desktop_settings.silent_launch); startup_task::spawn_startup_task(app_handle.clone(), append_startup_log); Ok(()) @@ -202,7 +226,7 @@ fn handle_run_event(app_handle: &tauri::AppHandle, event: RunEvent) { pub(crate) fn run() { #[cfg(target_os = "linux")] - configure_linux_webkit_workarounds(); + linux_webkit_workaround::configure(append_startup_log); append_startup_log("desktop process starting"); append_startup_log(&format!( @@ -243,33 +267,3 @@ pub(crate) fn run() { .expect("error while building tauri application") .run(handle_run_event); } - -#[cfg(all(test, target_os = "linux"))] -mod tests { - use super::*; - - #[test] - fn webkit_dmabuf_workaround_is_set_only_for_wayland_without_override() { - assert!(should_set_webkit_dmabuf_renderer_env( - None, - Some(std::ffi::OsStr::new("wayland-0")) - )); - assert!(!should_set_webkit_dmabuf_renderer_env(None, None)); - assert!(!should_set_webkit_dmabuf_renderer_env( - Some(std::ffi::OsStr::new("0")), - Some(std::ffi::OsStr::new("wayland-0")) - )); - assert!(!should_set_webkit_dmabuf_renderer_env( - Some(std::ffi::OsStr::new("1")), - Some(std::ffi::OsStr::new("wayland-0")) - )); - assert!(!should_set_webkit_dmabuf_renderer_env( - Some(std::ffi::OsStr::new("0")), - None - )); - assert!(!should_set_webkit_dmabuf_renderer_env( - Some(std::ffi::OsStr::new("1")), - None - )); - } -} From 6470352c2f350c0b5f045df8bc2defc14d4e2c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=B0=B8=E8=B5=AB?= <1259085392@qq.com> Date: Mon, 6 Jul 2026 11:23:38 +0900 Subject: [PATCH 5/5] chore: log non-silent startup window behavior --- src-tauri/src/app_runtime.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src-tauri/src/app_runtime.rs b/src-tauri/src/app_runtime.rs index 9dd4964f..7dfe2ffd 100644 --- a/src-tauri/src/app_runtime.rs +++ b/src-tauri/src/app_runtime.rs @@ -185,6 +185,7 @@ fn apply_startup_window_visibility(app_handle: &tauri::AppHandle, silent_launch: append_startup_log("silent launch enabled, keeping main window hidden"); window::actions::hide_main_window(app_handle, DEFAULT_SHELL_LOCALE, append_desktop_log); } else { + append_startup_log("silent launch disabled, showing main window"); window::actions::show_main_window(app_handle, DEFAULT_SHELL_LOCALE, append_desktop_log); } }