diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs index 4aedc4a..c9c2a3f 100644 --- a/desktop/src-tauri/src/lib.rs +++ b/desktop/src-tauri/src/lib.rs @@ -10,6 +10,9 @@ mod integration; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { + #[cfg(target_os = "linux")] + harden_linux_webkit_rendering(); + tauri::Builder::default() .invoke_handler(tauri::generate_handler![ integration::integration_status, @@ -19,3 +22,33 @@ pub fn run() { .run(tauri::generate_context!()) .expect("error while running the ThoughtSync desktop app"); } + +/// WebKitGTK's GPU-accelerated rendering (the DMA-BUF renderer + EGL compositing) fails +/// to initialize on a wide range of Linux GPU/driver/Wayland setups — "Could not create +/// default EGL display: EGL_BAD_PARAMETER" → a black/blank window. This is a well-known +/// WebKitGTK issue that hits Tauri apps broadly, NOT app-specific. Tauri's guidance +/// (https://v2.tauri.app/develop/debug/linux-graphics/) is to force the software +/// fallbacks at startup, before the webview is created, so end users don't have to. +/// +/// We apply the fix ONLY for AppImage launches (where these failures cluster and where +/// bundled libs are in play), leaving each var overridable — native (.deb) installs use +/// system libs and keep GPU acceleration untouched. WebKit software rendering is plenty +/// for this UI. +#[cfg(target_os = "linux")] +fn harden_linux_webkit_rendering() { + let is_appimage = + std::env::var_os("APPIMAGE").is_some() || std::env::var_os("APPDIR").is_some(); + if !is_appimage { + return; + } + // Ordered per Tauri's escalation ladder; each set only if the user hasn't chosen. + for (key, value) in [ + ("__NV_DISABLE_EXPLICIT_SYNC", "1"), + ("WEBKIT_DISABLE_DMABUF_RENDERER", "1"), + ("WEBKIT_DISABLE_COMPOSITING_MODE", "1"), + ] { + if std::env::var_os(key).is_none() { + std::env::set_var(key, value); + } + } +}