Skip to content

Commit 8706cea

Browse files
Setup ctrl+q keyboard shortcut (#618)
* register shortcut * ctrl+q keyboard shortcut closes active connections and exits
1 parent a22afa9 commit 8706cea

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src-tauri/Cargo.lock

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ x25519-dalek = { version = "2", features = [
110110
"serde",
111111
"static_secrets",
112112
] }
113+
tauri-plugin-global-shortcut = "2.3.0"
113114

114115
[target.'cfg(unix)'.dependencies]
115116
hyper-util = "0.1"

src-tauri/src/bin/defguard-client.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use log::{Level, LevelFilter};
2828
#[cfg(target_os = "macos")]
2929
use tauri::{process, Env};
3030
use tauri::{AppHandle, Builder, Manager, RunEvent, WindowEvent};
31+
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
3132
use tauri_plugin_log::{Target, TargetKind};
3233

3334
#[macro_use]
@@ -263,6 +264,20 @@ fn main() {
263264
.build(),
264265
)?;
265266

267+
// Setup ctrl-q keyboard shortcut
268+
let ctrl_q_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyQ);
269+
app_handle.plugin(
270+
tauri_plugin_global_shortcut::Builder::new()
271+
.with_handler(move |app, shortcut, event| {
272+
if shortcut == &ctrl_q_shortcut && event.state() == ShortcutState::Pressed {
273+
info!("Ctrl-Q pressed, closing active connections and exiting");
274+
app.exit(0);
275+
}
276+
})
277+
.build(),
278+
)?;
279+
app.global_shortcut().register(ctrl_q_shortcut)?;
280+
266281
let state = AppState::new(config);
267282
app.manage(state);
268283

0 commit comments

Comments
 (0)