start work on invoking shortcuts from CLI
This commit is contained in:
parent
1047818fdc
commit
47a3e1cfef
51
src-tauri/src/shortcuts.rs
Normal file
51
src-tauri/src/shortcuts.rs
Normal file
@ -0,0 +1,51 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use tauri::{
|
||||
AppHandle,
|
||||
Manager,
|
||||
};
|
||||
|
||||
use crate::app::APP;
|
||||
use crate::config::HotkeysConfig;
|
||||
use crate::terminal;
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum ShortcutAction {
|
||||
ShowWindow,
|
||||
LaunchTerminal,
|
||||
}
|
||||
|
||||
|
||||
pub fn exec_shortcut(action: ShortcutAction) {
|
||||
match action {
|
||||
ShowWindow => {
|
||||
let app = APP.get().unwrap();
|
||||
app.get_window("main").map(|w| w.show());
|
||||
},
|
||||
LaunchTerminal => terminal::launch(false),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn register_hotkeys(hotkeys: &HotkeysConfig) -> tauri::Result<()> {
|
||||
let app = APP.get().unwrap();
|
||||
let mut manager = app.global_shortcut_manager();
|
||||
manager.unregister_all()?;
|
||||
|
||||
if hotkeys.show_window.enabled {
|
||||
manager.register(
|
||||
hotkeys.show_window.keys,
|
||||
|| exec_shortcut(ShortcutAction::ShowWindow)
|
||||
)?;
|
||||
}
|
||||
|
||||
if hotkeys.launch_terminal.enabled {
|
||||
manager.register(
|
||||
&hotkeys.launch_terminal.keys,
|
||||
|| exec_shortcut(ShortcutAction::LaunchTerminal)
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user