fix: parse hotkey (#5167)

* fix: incorrectly parse hotkey

* refactor: parse hotkey

* fix: panic on linux

* chore: update

* chore: update style

* fix: register hotkey error on windows

* chore: update style

---------

Co-authored-by: Tunglies <tunglies.dev@outlook.com>
This commit is contained in:
oomeow
2025-10-23 15:54:48 +08:00
committed by GitHub
parent 585963e751
commit d7859b07a6
6 changed files with 25 additions and 80 deletions

View File

@@ -1,8 +1,8 @@
use crate::process::AsyncHandler;
use crate::utils::notification::{NotificationEvent, notify_event};
use crate::{
config::Config, core::handle, feat, logging, logging_error,
module::lightweight::entry_lightweight_mode, singleton_with_logging, utils::logging::Type,
config::Config, core::handle, feat, logging, module::lightweight::entry_lightweight_mode,
singleton_with_logging, utils::logging::Type,
};
use anyhow::{Result, bail};
use parking_lot::Mutex;
@@ -224,7 +224,7 @@ impl Hotkey {
let is_quit = matches!(function, HotkeyFunction::Quit);
let _ = manager.on_shortcut(hotkey, move |app_handle, hotkey_event, event| {
manager.on_shortcut(hotkey, move |app_handle, hotkey_event, event| {
let hotkey_event_owned = *hotkey_event;
let event_owned = event;
let function_owned = function;
@@ -271,7 +271,7 @@ impl Hotkey {
}
}
});
});
})?;
logging!(
debug,
@@ -402,7 +402,7 @@ impl Hotkey {
});
for (key, func) in add.iter() {
logging_error!(Type::Hotkey, self.register(key, func).await);
self.register(key, func).await?;
}
// Update the current hotkeys after all async operations

View File

@@ -676,7 +676,14 @@ async fn create_tray_menu(
.filter_map(|item| {
let mut parts = item.split(',');
match (parts.next(), parts.next()) {
(Some(func), Some(key)) => Some((func.into(), key.into())),
(Some(func), Some(key)) => {
// 托盘菜单中的 `accelerator` 属性,在 Linux/Windows 中都不支持小键盘按键的解析
if key.to_uppercase().contains("NUMPAD") {
None
} else {
Some((func.into(), key.into()))
}
}
_ => None,
}
})