1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use tauri_hotkey::{parse_hotkey, HotkeyManager};
#[derive(Default)]
pub struct ShortcutManager(HotkeyManager);
impl ShortcutManager {
pub fn new() -> Self {
Default::default()
}
pub fn is_registered(&self, shortcut: String) -> crate::api::Result<bool> {
let hotkey = parse_hotkey(&shortcut)?;
Ok(self.0.is_registered(&hotkey))
}
pub fn register<H: FnMut() + Send + 'static>(
&mut self,
shortcut: String,
handler: H,
) -> crate::api::Result<()> {
let hotkey = parse_hotkey(&shortcut)?;
self.0.register(hotkey, handler)?;
Ok(())
}
pub fn unregister(&mut self, shortcut: String) -> crate::api::Result<()> {
let hotkey = parse_hotkey(&shortcut)?;
self.0.unregister(&hotkey)?;
Ok(())
}
pub fn unregister_all(&mut self) -> crate::api::Result<()> {
self.0.unregister_all()?;
Ok(())
}
}