mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
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 <oursnoah@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Generated
+1
@@ -746,6 +746,7 @@ dependencies = [
|
||||
"tower-http 0.5.2",
|
||||
"url",
|
||||
"uuid",
|
||||
"webkit2gtk",
|
||||
"winreg 0.52.0",
|
||||
"zip 2.4.2",
|
||||
]
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user