diff --git a/scripts/prepare-resources/tauri-config.test.mjs b/scripts/prepare-resources/tauri-config.test.mjs index 387c0c8..908d691 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 16e266c..7dfe2ff 100644 --- a/src-tauri/src/app_runtime.rs +++ b/src-tauri/src/app_runtime.rs @@ -3,35 +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")] +mod linux_webkit_workaround { + const WEBKIT_DISABLE_DMABUF_RENDERER_ENV: &str = "WEBKIT_DISABLE_DMABUF_RENDERER"; + const WAYLAND_DISPLAY_ENV: &str = "WAYLAND_DISPLAY"; -const WEBKIT_DISABLE_DMABUF_RENDERER_ENV: &str = "WEBKIT_DISABLE_DMABUF_RENDERER"; -const WAYLAND_DISPLAY_ENV: &str = "WAYLAND_DISPLAY"; + 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() -} + 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(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" - )); + #[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( @@ -148,6 +180,16 @@ fn configure_page_load_events(builder: Builder) -> Builder) -> Builder { builder.setup(|app| { let app_handle = app.handle().clone(); @@ -157,14 +199,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, hiding main window"); - window::actions::hide_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(()) @@ -192,7 +227,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!( @@ -233,33 +268,3 @@ pub(crate) fn run() { .expect("error while building tauri application") .run(handle_run_event); } - -#[cfg(test)] -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 - )); - } -} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 17323c4..dea23ed 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" }