From e6cc44064cfdfa28e3b46999f4dcf0bdd1c2e5cc Mon Sep 17 00:00:00 2001 From: Kuingsmile Date: Mon, 27 Nov 2023 22:10:49 -0800 Subject: [PATCH] feat: add tooltip for tray (#24) --- src-tauri/src/core/tray.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src-tauri/src/core/tray.rs b/src-tauri/src/core/tray.rs index 01a50452fb..c792477068 100644 --- a/src-tauri/src/core/tray.rs +++ b/src-tauri/src/core/tray.rs @@ -107,6 +107,16 @@ impl Tray { } pub fn update_part(app_handle: &AppHandle) -> Result<()> { + let zh = { Config::verge().latest().language == Some("zh".into()) }; + macro_rules! t { + ($en: expr, $zh: expr) => { + if zh { + $zh + } else { + $en + } + }; + } let mode = { Config::clash() .latest() @@ -143,6 +153,22 @@ impl Tray { let _ = tray.get_item("system_proxy").set_selected(*system_proxy); let _ = tray.get_item("tun_mode").set_selected(*tun_mode); + let switch_map = { + let mut map = std::collections::HashMap::new(); + map.insert(true, t!("On", "开")); + map.insert(false, t!("Off", "关")); + map + }; + + #[cfg(not(target_os = "linux"))] + let _ = tray.set_tooltip(&format!( + "{}: {}\n{}: {}", + t!("System Proxy", "系统代理"), + switch_map[system_proxy], + t!("TUN Mode", "Tun 模式"), + switch_map[tun_mode] + )); + Ok(()) }