From 2edee3163890528ad77af8caf06cc6a1f25575f4 Mon Sep 17 00:00:00 2001 From: ThendCN Date: Thu, 12 Feb 2026 22:53:33 +0800 Subject: [PATCH] fix(linux): disable WebKitGTK hardware acceleration to prevent white screen (#986) On some Linux systems with AMD GPUs (e.g., AMD Cezanne/Radeon Vega), WebKitGTK's GPU process fails to initialize EGL, causing the app to show a white screen on startup. Root cause: `amdgpu_query_info(ACCEL_WORKING)` returns EACCES (-13), which causes EGL display creation to fail with EGL_BAD_PARAMETER, crashing the GPU process. Fix: Use WebKitGTK's `set_hardware_acceleration_policy(Never)` API to disable GPU acceleration on Linux, falling back to software rendering. This is applied at startup via Tauri's `with_webview` API. Co-authored-by: Naozhong AI Co-authored-by: Claude Opus 4.6 --- src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 3 +++ src-tauri/src/lib.rs | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index d09f0ad7b..49e1759f0 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -746,6 +746,7 @@ dependencies = [ "tower-http 0.5.2", "url", "uuid", + "webkit2gtk", "winreg 0.52.0", "zip 2.4.2", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 420d6436a..7346899a6 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -65,6 +65,9 @@ uuid = { version = "1.11", features = ["v4"] } [target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))'.dependencies] tauri-plugin-single-instance = "2" +[target.'cfg(target_os = "linux")'.dependencies] +webkit2gtk = { version = "2.0.1", features = ["v2_16"] } + [target.'cfg(target_os = "windows")'.dependencies] winreg = "0.52" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 9c246ff90..e2657745a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -768,6 +768,21 @@ pub fn run() { restore_proxy_state_on_startup(&state).await; }); + // Linux: 禁用 WebKitGTK 硬件加速,防止 EGL 初始化失败导致白屏 + #[cfg(target_os = "linux")] + { + if let Some(window) = app.get_webview_window("main") { + let _ = window.with_webview(|webview| { + use webkit2gtk::{WebViewExt, SettingsExt, HardwareAccelerationPolicy}; + let wk_webview = webview.inner(); + if let Some(settings) = WebViewExt::settings(&wk_webview) { + SettingsExt::set_hardware_acceleration_policy(&settings, HardwareAccelerationPolicy::Never); + log::info!("已禁用 WebKitGTK 硬件加速"); + } + }); + } + } + // 静默启动:根据设置决定是否显示主窗口 let settings = crate::settings::get_settings(); if let Some(window) = app.get_webview_window("main") {