mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-31 11:12:07 +08:00
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user