-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathshortcuts.rs
More file actions
65 lines (48 loc) · 1.58 KB
/
shortcuts.rs
File metadata and controls
65 lines (48 loc) · 1.58 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use tauri::{AppHandle, GlobalShortcutManager, Manager, Window};
use crate::window;
pub const DEFAULT_SHORTCUT: &str = "CommandOrControl+Alt+Shift+C";
pub const SETTINGS_SHORTCUT: &str = "CommandOrControl+,";
pub fn update_default(
app: &AppHandle,
old_shortcut: &str,
new_shortcut: &str,
) -> Result<(), tauri::Error> {
let window = app.get_window(window::MAIN).unwrap();
let mut shortcuts = app.global_shortcut_manager();
shortcuts.unregister(old_shortcut)?;
shortcuts.register(new_shortcut, move || {
if window.is_visible().unwrap() {
window::main_window::hide(&window).unwrap();
} else {
window::main_window::show(&window).unwrap();
}
})?;
Ok(())
}
pub fn register_settings(app: &AppHandle) -> Result<(), anyhow::Error> {
let mut shortcuts = app.global_shortcut_manager();
let settings_window = window::settings::get(app).unwrap();
shortcuts.register(SETTINGS_SHORTCUT, move || {
settings_window.show().unwrap();
settings_window.set_focus().unwrap();
})?;
Ok(())
}
pub fn unregister_settings(app: &AppHandle) -> Result<(), anyhow::Error> {
let mut shortcuts = app.global_shortcut_manager();
shortcuts.unregister(SETTINGS_SHORTCUT)?;
Ok(())
}
pub fn register_escape(window: Window) -> Result<(), tauri::Error> {
let app = window.app_handle();
let mut shortcuts = app.global_shortcut_manager();
shortcuts.register("Escape", move || {
window::main_window::hide(&window).unwrap();
})?;
Ok(())
}
pub fn unregister_escape(app: &AppHandle) -> Result<(), tauri::Error> {
let mut shortcuts = app.global_shortcut_manager();
shortcuts.unregister("Escape")?;
Ok(())
}