mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
refactor: Linux environment detection logic (#5108)
* fix: wayland framebuffer * refactor(utils): move linux env heuristics into platform helper * refactor(linux): let DMABUF override helper use resolved decision * fix: clippy * fix: clippy * feat: NVIDIA detection * fix: clippy
This commit is contained in:
@@ -9,6 +9,8 @@ mod feat;
|
||||
mod module;
|
||||
mod process;
|
||||
pub mod utils;
|
||||
#[cfg(target_os = "linux")]
|
||||
use crate::utils::linux;
|
||||
#[cfg(target_os = "macos")]
|
||||
use crate::utils::window_manager::WindowManager;
|
||||
use crate::{
|
||||
@@ -234,89 +236,7 @@ pub fn run() {
|
||||
|
||||
// Set Linux environment variable
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP")
|
||||
.unwrap_or_default()
|
||||
.to_uppercase();
|
||||
let session_desktop = std::env::var("XDG_SESSION_DESKTOP")
|
||||
.unwrap_or_default()
|
||||
.to_uppercase();
|
||||
let desktop_session = std::env::var("DESKTOP_SESSION")
|
||||
.unwrap_or_default()
|
||||
.to_uppercase();
|
||||
let is_kde_desktop = desktop_env.contains("KDE");
|
||||
let is_plasma_desktop = desktop_env.contains("PLASMA");
|
||||
let is_hyprland_desktop = desktop_env.contains("HYPR")
|
||||
|| session_desktop.contains("HYPR")
|
||||
|| desktop_session.contains("HYPR");
|
||||
|
||||
let is_wayland_session = std::env::var("XDG_SESSION_TYPE")
|
||||
.map(|value| value.eq_ignore_ascii_case("wayland"))
|
||||
.unwrap_or(false)
|
||||
|| std::env::var("WAYLAND_DISPLAY").is_ok();
|
||||
let prefer_native_wayland =
|
||||
is_wayland_session && (is_kde_desktop || is_plasma_desktop || is_hyprland_desktop);
|
||||
let dmabuf_override = std::env::var("WEBKIT_DISABLE_DMABUF_RENDERER");
|
||||
|
||||
if prefer_native_wayland {
|
||||
let compositor_label = if is_hyprland_desktop {
|
||||
"Hyprland"
|
||||
} else if is_plasma_desktop {
|
||||
"KDE Plasma"
|
||||
} else {
|
||||
"KDE"
|
||||
};
|
||||
|
||||
if matches!(dmabuf_override.as_deref(), Ok("1")) {
|
||||
unsafe {
|
||||
std::env::remove_var("WEBKIT_DISABLE_DMABUF_RENDERER");
|
||||
}
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
"Wayland + {} detected: Re-enabled WebKit DMABUF renderer to avoid Cairo surface failures.",
|
||||
compositor_label
|
||||
);
|
||||
} else {
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
"Wayland + {} detected: Using native Wayland backend for reliable rendering.",
|
||||
compositor_label
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if dmabuf_override.is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
||||
}
|
||||
}
|
||||
|
||||
// Force X11 backend for tray icon compatibility on Wayland
|
||||
if is_wayland_session {
|
||||
unsafe {
|
||||
std::env::set_var("GDK_BACKEND", "x11");
|
||||
std::env::remove_var("WAYLAND_DISPLAY");
|
||||
}
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
"Wayland detected: Forcing X11 backend for tray icon compatibility"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if is_kde_desktop || is_plasma_desktop {
|
||||
unsafe {
|
||||
std::env::set_var("GTK_CSD", "0");
|
||||
}
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
"KDE detected: Disabled GTK CSD for better titlebar stability."
|
||||
);
|
||||
}
|
||||
}
|
||||
linux::configure_environment();
|
||||
|
||||
// Create and configure the Tauri builder
|
||||
let builder = app_init::setup_plugins(tauri::Builder::default())
|
||||
|
||||
Reference in New Issue
Block a user