diff --git a/src-tauri/src/core/hotkey.rs b/src-tauri/src/core/hotkey.rs index 7e21cf8b4..ed2aece9b 100755 --- a/src-tauri/src/core/hotkey.rs +++ b/src-tauri/src/core/hotkey.rs @@ -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 {