Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scripts/prepare-resources/tauri-config.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
});
129 changes: 67 additions & 62 deletions src-tauri/src/app_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<tauri::Wry>) -> Builder<tauri::Wry> {
builder
.plugin(tauri_plugin_autostart::init(
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Expand Down Expand Up @@ -148,6 +180,16 @@ fn configure_page_load_events(builder: Builder<tauri::Wry>) -> Builder<tauri::Wr
})
}

fn apply_startup_window_visibility(app_handle: &tauri::AppHandle, silent_launch: bool) {
if 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);
}
}

fn configure_setup(builder: Builder<tauri::Wry>) -> Builder<tauri::Wry> {
builder.setup(|app| {
let app_handle = app.handle().clone();
Expand All @@ -157,14 +199,7 @@ fn configure_setup(builder: Builder<tauri::Wry>) -> Builder<tauri::Wry> {
crate::windows_shutdown::install(&app_handle);

let desktop_settings = app_handle.state::<DesktopSettingsCache>().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(())
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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
));
}
}
1 change: 1 addition & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"minWidth": 980,
"minHeight": 680,
"resizable": true,
"visible": false,
"fullscreen": false,
"backgroundThrottling": "disabled"
}
Expand Down