From 0b44d40b39f8409bb334344933981dd3303e7898 Mon Sep 17 00:00:00 2001 From: huzibaca Date: Wed, 1 Jan 2025 08:14:15 +0800 Subject: [PATCH] feat: the tray displays the shortcut keys that have been set --- src-tauri/src/core/tray/mod.rs | 28 ++++++++++++++++++++++------ src-tauri/src/feat.rs | 1 + 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/core/tray/mod.rs b/src-tauri/src/core/tray/mod.rs index 55fab91f..62face10 100644 --- a/src-tauri/src/core/tray/mod.rs +++ b/src-tauri/src/core/tray/mod.rs @@ -334,13 +334,29 @@ fn create_tray_menu( let mode = mode.unwrap_or(""); let use_zh = { Config::verge().latest().language == Some("zh".into()) }; let version = VERSION.get().unwrap(); + let hotkeys = Config::verge() + .latest() + .hotkeys + .as_ref() + .map(|h| { + h.iter() + .filter_map(|item| { + let mut parts = item.split(','); + match (parts.next(), parts.next()) { + (Some(func), Some(key)) => Some((func.to_string(), key.to_string())), + _ => None, + } + }) + .collect::>() + }) + .unwrap_or_default(); let open_window = &MenuItem::with_id( app_handle, "open_window", t!("Dashboard", "打开面板", use_zh), true, - None::<&str>, + hotkeys.get("open_or_close_dashboard").map(|s| s.as_str()), ) .unwrap(); @@ -350,7 +366,7 @@ fn create_tray_menu( t!("Rule Mode", "规则模式", use_zh), true, mode == "rule", - None::<&str>, + hotkeys.get("clash_mode_rule").map(|s| s.as_str()), ) .unwrap(); @@ -360,7 +376,7 @@ fn create_tray_menu( t!("Global Mode", "全局模式", use_zh), true, mode == "global", - None::<&str>, + hotkeys.get("clash_mode_global").map(|s| s.as_str()), ) .unwrap(); @@ -370,7 +386,7 @@ fn create_tray_menu( t!("Direct Mode", "直连模式", use_zh), true, mode == "direct", - None::<&str>, + hotkeys.get("clash_mode_direct").map(|s| s.as_str()), ) .unwrap(); @@ -380,7 +396,7 @@ fn create_tray_menu( t!("System Proxy", "系统代理", use_zh), true, system_proxy_enabled, - None::<&str>, + hotkeys.get("toggle_system_proxy").map(|s| s.as_str()), ) .unwrap(); @@ -390,7 +406,7 @@ fn create_tray_menu( t!("TUN Mode", "Tun模式", use_zh), true, tun_mode_enabled, - None::<&str>, + hotkeys.get("toggle_tun_mode").map(|s| s.as_str()), ) .unwrap(); diff --git a/src-tauri/src/feat.rs b/src-tauri/src/feat.rs index 040f1779..1debb1d4 100644 --- a/src-tauri/src/feat.rs +++ b/src-tauri/src/feat.rs @@ -264,6 +264,7 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> { if let Some(hotkeys) = patch.hotkeys { hotkey::Hotkey::global().update(hotkeys)?; + tray::Tray::global().update_menu()?; } if should_update_systray_icon {