mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
fix: improve Linux tray support and add --no-tray option (#4958)
This commit is contained in:
@@ -192,8 +192,18 @@ impl Tray {
|
|||||||
let app_handle = handle::Handle::global()
|
let app_handle = handle::Handle::global()
|
||||||
.app_handle()
|
.app_handle()
|
||||||
.ok_or_else(|| anyhow::anyhow!("Failed to get app handle for tray initialization"))?;
|
.ok_or_else(|| anyhow::anyhow!("Failed to get app handle for tray initialization"))?;
|
||||||
self.create_tray_from_handle(&app_handle).await?;
|
|
||||||
Ok(())
|
match self.create_tray_from_handle(&app_handle).await {
|
||||||
|
Ok(_) => {
|
||||||
|
log::info!(target: "app", "System tray created successfully");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!(target: "app", "System tray creation failed: {}, Application will continue running without tray icon", e);
|
||||||
|
// Don't return error, let application continue running without tray
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 更新托盘点击行为
|
/// 更新托盘点击行为
|
||||||
|
|||||||
@@ -282,6 +282,21 @@ pub fn run() {
|
|||||||
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Force X11 backend for tray icon compatibility on Wayland
|
||||||
|
let is_wayland = std::env::var("WAYLAND_DISPLAY").is_ok();
|
||||||
|
if is_wayland {
|
||||||
|
unsafe {
|
||||||
|
std::env::set_var("GDK_BACKEND", "x11");
|
||||||
|
std::env::remove_var("WAYLAND_DISPLAY");
|
||||||
|
}
|
||||||
|
logging!(
|
||||||
|
info,
|
||||||
|
Type::Setup,
|
||||||
|
true,
|
||||||
|
"Wayland detected: Forcing X11 backend for tray icon compatibility"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP")
|
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_uppercase();
|
.to_uppercase();
|
||||||
|
|||||||
@@ -2,5 +2,14 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
#[cfg(feature = "tokio-trace")]
|
#[cfg(feature = "tokio-trace")]
|
||||||
console_subscriber::init();
|
console_subscriber::init();
|
||||||
|
|
||||||
|
// Check for --no-tray command line argument
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.contains(&"--no-tray".to_string()) {
|
||||||
|
unsafe {
|
||||||
|
std::env::set_var("CLASH_VERGE_DISABLE_TRAY", "1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app_lib::run();
|
app_lib::run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,6 +204,17 @@ pub async fn init_work_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn init_tray() {
|
pub(super) async fn init_tray() {
|
||||||
|
// Check if tray should be disabled via environment variable
|
||||||
|
if std::env::var("CLASH_VERGE_DISABLE_TRAY").unwrap_or_default() == "1" {
|
||||||
|
logging!(
|
||||||
|
info,
|
||||||
|
Type::Setup,
|
||||||
|
true,
|
||||||
|
"System tray disabled via --no-tray flag"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
logging!(info, Type::Setup, true, "Initializing system tray...");
|
logging!(info, Type::Setup, true, "Initializing system tray...");
|
||||||
logging_error!(Type::Setup, true, Tray::global().init().await);
|
logging_error!(Type::Setup, true, Tray::global().init().await);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user