Skip to content

Commit

Permalink
feat: add tooltip for tray (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile authored Nov 28, 2023
1 parent 7e7ce41 commit e6cc440
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src-tauri/src/core/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(())
}

Expand Down

0 comments on commit e6cc440

Please sign in to comment.