Skip to content

Commit c9f89f3

Browse files
Fix ctrl+q keyboard shortcut (#632)
* Revert "Setup ctrl+q keyboard shortcut (#618)" This reverts commit 8706cea. * ctrl+q keyboard shortcut using the process plugin * update cargo-deny ignores * fix deny.toml comments * use useHotkeys react hook
1 parent fa11096 commit c9f89f3

File tree

8 files changed

+54
-57
lines changed

8 files changed

+54
-57
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@tauri-apps/plugin-notification": "^2.3.1",
6565
"@tauri-apps/plugin-opener": "^2.5.0",
6666
"@tauri-apps/plugin-os": "^2.3.1",
67+
"@tauri-apps/plugin-process": "^2.3.0",
6768
"@tauri-apps/plugin-window-state": "^2.4.0",
6869
"@types/byte-size": "^8.1.2",
6970
"@use-gesture/react": "^10.3.1",
@@ -92,6 +93,7 @@
9293
"react-click-away-listener": "^2.4.0",
9394
"react-dom": "^19.1.1",
9495
"react-hook-form": "^7.63.0",
96+
"react-hotkeys-hook": "^5.2.1",
9597
"react-loading-skeleton": "^3.5.0",
9698
"react-markdown": "^10.1.0",
9799
"react-qr-code": "^2.0.18",

pnpm-lock.yaml

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

src-tauri/Cargo.lock

Lines changed: 11 additions & 40 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ x25519-dalek = { version = "2", features = [
110110
"serde",
111111
"static_secrets",
112112
] }
113-
tauri-plugin-global-shortcut = "2.3.0"
113+
tauri-plugin-process = "2.3.0"
114114

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

src-tauri/capabilities/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"os:allow-hostname",
4949
"dialog:default",
5050
"clipboard-manager:allow-write-text",
51+
"process:allow-exit",
5152
{
5253
"identifier": "http:default",
5354
"allow": [

src-tauri/deny.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ ignore = [
8787
{ id = "RUSTSEC-2024-0420", reason = "Tauri v2 GTK3 dependency (unmaintained)" },
8888
{ id = "RUSTSEC-2025-0052", reason = "Discontinued, but dark-light v2.0.0 needs it" },
8989
{ id = "RUSTSEC-2025-0057", reason = "Tauri needs it" },
90+
{ id = "RUSTSEC-2025-0075", reason = "Tauri v2 dependency (unmaintained)" },
91+
{ id = "RUSTSEC-2025-0080", reason = "Tauri v2 dependency (unmaintained)" },
92+
{ id = "RUSTSEC-2025-0081", reason = "Tauri v2 dependency (unmaintained)" },
93+
{ id = "RUSTSEC-2025-0098", reason = "Tauri v2 dependency (unmaintained)" },
94+
{ id = "RUSTSEC-2025-0100", reason = "Tauri v2 dependency (unmaintained)" },
9095
]
9196
# If this is true, then cargo deny will use the git executable to fetch advisory database.
9297
# If this is false, then it uses a built-in git library.

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ 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};
3231
use tauri_plugin_log::{Target, TargetKind};
3332

3433
#[macro_use]
@@ -185,6 +184,7 @@ fn main() {
185184
.plugin(tauri_plugin_window_state::Builder::new().build())
186185
.plugin(tauri_plugin_opener::init())
187186
.plugin(tauri_plugin_os::init())
187+
.plugin(tauri_plugin_process::init())
188188
.setup(|app| {
189189
// Register for linux and dev windows builds
190190
#[cfg(any(target_os = "linux", all(debug_assertions, windows)))]
@@ -264,20 +264,6 @@ fn main() {
264264
.build(),
265265
)?;
266266

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-
281267
let state = AppState::new(config);
282268
app.manage(state);
283269

src/components/App/App.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import '../../shared/scss/index.scss';
44

55
import { QueryClient } from '@tanstack/query-core';
66
import { QueryClientProvider } from '@tanstack/react-query';
7-
import { debug } from '@tauri-apps/plugin-log';
7+
import { debug, info } from '@tauri-apps/plugin-log';
88
import { openUrl } from '@tauri-apps/plugin-opener';
99
import dayjs from 'dayjs';
1010
import customParseData from 'dayjs/plugin/customParseFormat';
@@ -38,6 +38,8 @@ import { useTheme } from '../../shared/defguard-ui/hooks/theme/useTheme';
3838
import { ThemeProvider } from '../../shared/providers/ThemeProvider/ThemeProvider';
3939
import { routes } from '../../shared/routes';
4040
import { ApplicationUpdateManager } from '../ApplicationUpdateManager/ApplicationUpdateManager';
41+
import { exit } from '@tauri-apps/plugin-process';
42+
import { useHotkeys } from 'react-hotkeys-hook';
4143

4244
dayjs.extend(duration);
4345
dayjs.extend(utc);
@@ -186,6 +188,12 @@ export const App = () => {
186188
};
187189
}, []);
188190

191+
// register ctrl+q keyboard shortcut
192+
useHotkeys('ctrl+q', () => {
193+
info("Ctrl-Q pressed, exiting.");
194+
exit(0);
195+
});
196+
189197
if (!appLoaded) return null;
190198

191199
return (

0 commit comments

Comments
 (0)