From 19f228a324e7462d3e3a6ec3921c30f0cb2a5415 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Sat, 4 Apr 2026 23:11:39 +0800 Subject: Update src-tauri/src/main.rs Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- src-tauri/src/main.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 5109182..952d250 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -863,19 +863,34 @@ async fn start_game( } // On Linux, inject GPU environment variables for hybrid graphics support + // but do not override values that are already set in the environment. #[cfg(target_os = "linux")] { + let mut injected_any = false; + // NVIDIA Prime Render Offload - enables discrete NVIDIA GPU on hybrid systems - command.env("__NV_PRIME_RENDER_OFFLOAD", "1"); - command.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia"); - + if std::env::var_os("__NV_PRIME_RENDER_OFFLOAD").is_none() { + command.env("__NV_PRIME_RENDER_OFFLOAD", "1"); + injected_any = true; + } + + if std::env::var_os("__GLX_VENDOR_LIBRARY_NAME").is_none() { + command.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia"); + injected_any = true; + } + // AMD DRI_PRIME - enables discrete AMD GPU on hybrid systems - command.env("DRI_PRIME", "1"); - - emit_log!( - window, - "Injected GPU environment variables for Linux (NVIDIA Prime & AMD DRI_PRIME)".to_string() - ); + if std::env::var_os("DRI_PRIME").is_none() { + command.env("DRI_PRIME", "1"); + injected_any = true; + } + + if injected_any { + emit_log!( + window, + "Injected default GPU environment variables for Linux (NVIDIA Prime & AMD DRI_PRIME, only where unset)".to_string() + ); + } } // Spawn and handle output -- cgit v1.2.3-70-g09d2