fix: debounce toggle hotkeys #6796 (#6905)

This commit is contained in:
Tunglies
2026-04-29 05:03:08 +00:00
committed by GitHub
parent f7c21c2e60
commit 13fb18ceaf
+25 -3
View File
@@ -7,7 +7,15 @@ use anyhow::{Result, bail};
use arc_swap::ArcSwap;
use clash_verge_logging::{Type, logging};
use smartstring::alias::String;
use std::{collections::HashMap, fmt, str::FromStr, sync::Arc};
use std::{
collections::HashMap,
fmt,
str::FromStr,
sync::{
Arc,
atomic::{AtomicBool, Ordering},
},
};
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt as _, ShortcutState};
/// Enum representing all available hotkey functions
@@ -234,9 +242,23 @@ impl Hotkey {
}
let is_quit = matches!(function, HotkeyFunction::Quit);
let pressed = AtomicBool::new(false);
manager.on_shortcut(hotkey, move |_app_handle, hotkey_event, event| match event.state {
ShortcutState::Released => {
pressed.store(false, Ordering::Relaxed);
}
ShortcutState::Pressed => {
if pressed.swap(true, Ordering::Relaxed) {
logging!(
debug,
Type::Hotkey,
"Ignoring repeated hotkey press: {:?}",
hotkey_event
);
return;
}
manager.on_shortcut(hotkey, move |_app_handle, hotkey_event, event| {
if event.state == ShortcutState::Pressed {
logging!(debug, Type::Hotkey, "Hotkey pressed: {:?}", hotkey_event);
let hotkey = hotkey_event.key;
if hotkey == Code::KeyQ && is_quit {