From f31fe1440d68a8b2489b79e16fabdbcbeb70141b Mon Sep 17 00:00:00 2001 From: huzibaca Date: Tue, 17 Sep 2024 10:59:39 +0800 Subject: [PATCH] fix: hotkey status not accurately processed, resulting in two triggers --- src-tauri/src/core/hotkey.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) mode change 100644 => 100755 src-tauri/src/core/hotkey.rs diff --git a/src-tauri/src/core/hotkey.rs b/src-tauri/src/core/hotkey.rs old mode 100644 new mode 100755 index e53fdffc..281d935b --- a/src-tauri/src/core/hotkey.rs +++ b/src-tauri/src/core/hotkey.rs @@ -4,8 +4,7 @@ use once_cell::sync::OnceCell; use parking_lot::Mutex; use std::{collections::HashMap, sync::Arc}; use tauri::AppHandle; -use tauri_plugin_global_shortcut::GlobalShortcutExt; - +use tauri_plugin_global_shortcut::{GlobalShortcutExt, ShortcutState}; pub struct Hotkey { current: Arc>>, // 保存当前的热键设置 app_handle: Arc>>, @@ -69,7 +68,11 @@ impl Hotkey { _ => bail!("invalid function \"{func}\""), }; - let _ = manager.on_shortcut(hotkey, move |_, _, _| f()); + let _ = manager.on_shortcut(hotkey, move |_app_handle, _hotkey, event| { + if event.state == ShortcutState::Pressed { + f() + } + }); log::info!(target: "app", "register hotkey {hotkey} {func}"); Ok(()) }