diff --git a/src-tauri/src/app_runtime.rs b/src-tauri/src/app_runtime.rs index 227bd65..16e266c 100644 --- a/src-tauri/src/app_runtime.rs +++ b/src-tauri/src/app_runtime.rs @@ -9,6 +9,29 @@ use crate::{ DEFAULT_SHELL_LOCALE, DESKTOP_LOG_FILE, STARTUP_MODE_ENV, }; +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() +} + +#[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" + )); + } +} + fn configure_plugins(builder: Builder) -> Builder { builder .plugin(tauri_plugin_autostart::init( @@ -168,6 +191,9 @@ fn handle_run_event(app_handle: &tauri::AppHandle, event: RunEvent) { } pub(crate) fn run() { + #[cfg(target_os = "linux")] + configure_linux_webkit_workarounds(); + append_startup_log("desktop process starting"); append_startup_log(&format!( "desktop log path: {}", @@ -207,3 +233,33 @@ 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 + )); + } +}