feat: refresh ui when hotkey clicked
This commit is contained in:
parent
509d83365e
commit
8fa7fb3b1f
@ -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(())
|
||||
}
|
||||
|
||||
|
@ -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(())
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user