diff --git a/src-tauri/src/core/hotkey.rs b/src-tauri/src/core/hotkey.rs index d0239b8194c8d0dd959df0e818d4ff276e55dd1e..815a2e48ac02e98c03893992767dfc72d29ba464 100644 --- a/src-tauri/src/core/hotkey.rs +++ b/src-tauri/src/core/hotkey.rs @@ -4,12 +4,14 @@ use std::collections::HashMap; use tauri_hotkey::{parse_hotkey, HotkeyManager}; pub struct Hotkey { + current: Vec<String>, // ä¿å˜å½“å‰çš„çƒé”®è®¾ç½® manager: HotkeyManager, } impl Hotkey { pub fn new() -> Hotkey { Hotkey { + current: Vec::new(), manager: HotkeyManager::new(), } } @@ -30,6 +32,7 @@ impl Hotkey { log::error!(target: "app", "invalid hotkey \"{}\":\"{}\"", func.unwrap_or("None"), key.unwrap_or("None")); } } + self.current = hotkeys.clone(); } Ok(()) @@ -58,23 +61,20 @@ impl Hotkey { }; self.manager.register(hotkey, f)?; + log::info!(target: "app", "register hotkey {func} {key}"); Ok(()) } fn unregister(&mut self, key: &str) -> Result<()> { let hotkey = parse_hotkey(key.trim())?; self.manager.unregister(&hotkey)?; + log::info!(target: "app", "unregister hotkey {key}"); Ok(()) } pub fn update(&mut self, new_hotkeys: Vec<String>) -> Result<()> { - let data = Data::global(); - let mut verge = data.verge.lock(); - - let default = Vec::new(); - let old_hotkeys = verge.hotkeys.as_ref().unwrap_or(&default); - - let old_map = Self::get_map_from_vec(old_hotkeys); + let current = self.current.to_owned(); + let old_map = Self::get_map_from_vec(¤t); let new_map = Self::get_map_from_vec(&new_hotkeys); for diff in Self::get_diff(old_map, new_map).iter() { @@ -92,11 +92,7 @@ impl Hotkey { } } - verge.patch_config(Verge { - hotkeys: Some(new_hotkeys), - ..Verge::default() - })?; - + self.current = new_hotkeys; Ok(()) } diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs index e5c162f02197767c63f0f26c0e8ad9268bb6e483..3d122b3e17d521735f1d9aaf3f9668a29a67caf7 100644 --- a/src-tauri/src/core/mod.rs +++ b/src-tauri/src/core/mod.rs @@ -202,6 +202,11 @@ impl Core { handle.update_systray()?; } + if patch.hotkeys.is_some() { + let mut hotkey = self.hotkey.lock(); + hotkey.update(patch.hotkeys.unwrap())?; + } + Ok(()) } @@ -225,6 +230,7 @@ impl Core { // update tray let handle = self.handle.lock(); + handle.refresh_clash(); handle.update_systray_clash()?; Ok(()) diff --git a/src-tauri/src/feat.rs b/src-tauri/src/feat.rs index 4b9bc4c25c0441123784df6a6076b01f854b9e0c..47dabbfb0dbf9027e48ab8d46946e3520af43b0b 100644 --- a/src-tauri/src/feat.rs +++ b/src-tauri/src/feat.rs @@ -21,6 +21,9 @@ pub fn toggle_system_proxy() { enable_system_proxy: Some(enable), ..Verge::default() })); + + let handle = core.handle.lock(); + let _ = handle.refresh_verge(); } // æ‰“å¼€ç³»ç»Ÿä»£ç† @@ -30,6 +33,9 @@ pub fn enable_system_proxy() { enable_system_proxy: Some(true), ..Verge::default() })); + + let handle = core.handle.lock(); + let _ = handle.refresh_verge(); } // å…³é—ç³»ç»Ÿä»£ç† @@ -39,6 +45,9 @@ pub fn disable_system_proxy() { enable_system_proxy: Some(false), ..Verge::default() })); + + let handle = core.handle.lock(); + let _ = handle.refresh_verge(); } // 切æ¢tunæ¨¡å¼ @@ -54,6 +63,9 @@ pub fn toggle_tun_mode() { enable_tun_mode: Some(enable), ..Verge::default() })); + + let handle = core.handle.lock(); + let _ = handle.refresh_verge(); } // 打开tunæ¨¡å¼ @@ -63,6 +75,9 @@ pub fn enable_tun_mode() { enable_tun_mode: Some(true), ..Verge::default() })); + + let handle = core.handle.lock(); + let _ = handle.refresh_verge(); } // å…³é—tunæ¨¡å¼ @@ -72,4 +87,7 @@ pub fn disable_tun_mode() { enable_tun_mode: Some(false), ..Verge::default() })); + + let handle = core.handle.lock(); + let _ = handle.refresh_verge(); }