Skip to content

feat: 全局快捷键禁用F1-F24外单独按键 - #375

Open
zmdyy0318 wants to merge 1 commit into
MistEO:mainfrom
zmdyy0318:feat/restrict-bare-hotkeys
Open

zmdyy0318 wants to merge 1 commit into
MistEO:mainfrom
zmdyy0318:feat/restrict-bare-hotkeys

Conversation

@zmdyy0318

@zmdyy0318 zmdyy0318 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

逻辑参考腾讯QQ
image
close MaaEnd/MaaEnd#6313

Summary

  • 开始/结束任务的快捷键在单独按键时只接受 F1–F24,其他单键不会保存,并提示需要再加修饰键。
  • 已经保存的非法单键不再在窗口内触发,也不会注册为全局热键。
  • 流水线选项里的热键仍可单独设置字母键。

Test plan

  • 在设置里按下 A、1 或空格,确认不写入并出现修饰键提示
  • 设置 F10 或 Ctrl+A,确认可以保存,窗口内和全局模式都能触发
  • 开启全局快捷键后,已保存的非法单键不会占用系统热键
  • 流水线选项热键仍可录入单个字母

Made with Cursor

Sourcery 总结

在保持管道热键配置灵活性的同时,确保任务开始和停止操作使用安全的热键。

新功能:

  • 将开始和停止设置热键限制为独立的 F1–F24 键,或包含有效修饰键的组合键。
  • 当输入或已保存不受支持的独立按键时,显示本地化提示。

错误修复:

  • 防止已保存的无效独立热键触发窗口内操作,或被注册为全局快捷键。

增强功能:

  • 保留为管道选项热键输入独立字母键的功能。
Original summary in English

Summary by Sourcery

Enforce safe hotkey requirements for task start and stop actions while keeping pipeline hotkey configuration flexible.

New Features:

  • Restrict start and stop settings hotkeys to standalone F1–F24 keys or combinations containing valid modifier keys.
  • Show localized guidance when an unsupported standalone key is entered or already saved.

Bug Fixes:

  • Prevent invalid saved standalone hotkeys from triggering in-window actions or being registered as global shortcuts.

Enhancements:

  • Preserve standalone letter-key entry for pipeline option hotkeys.

Co-authored-by: Cursor <cursoragent@cursor.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我发现了 2 个问题

AI Agent 提示词
请处理本次代码审查中的评论:

## 单独评论

### 评论 1
<location path="src/App.tsx" line_range="1677-1689" />
<code_context>
-        registeringKey = stopKey;
-        // 避免重复注册相同的键
-        if (stopKey !== startKey) {
+        if (startAllowed) {
+          registeringKey = startKey;
+          await register(toTauriKey(startKey), () => {
+            const now = Date.now();
+            if (now - lastStartTime < GLOBAL_HOTKEY_THROTTLE_MS) return;
+            lastStartTime = now;
+            document.dispatchEvent(
+              new CustomEvent('mxu-start-tasks', {
+                detail: { source: 'global-hotkey', combo: startKey },
+              }),
+            );
+          });
+        }
+        if (stopAllowed) {
+          registeringKey = stopKey;
</code_context>
<issue_to_address>
**过期的快捷键仍在运行**

当全局快捷键在 `registerKeys` 正等待快捷键加载或注册期间被更改或禁用时,effect 清理会异步调用 `unregisterAll()`,但待处理的 `registerKeys` 调用可能会在之后注册旧的快捷键。当两个快捷键都变为不允许使用时,`bj` 处的分支不会开始任何替代注册,因此过期的回调仍处于活动状态,并可能为设置中已不再显示的快捷键分发任务。

请取消待处理的注册,或以其他方式保护它们,确保清理操作之后不会发生过期注册,包括两个快捷键都不允许使用的情况。

另请查看 `src/App.tsx:1665-1668`。
</issue_to_address>

### 评论 2
<location path="src/components/FormControls.tsx" line_range="314" />
<code_context>
+/** 设置里的开始/结束快捷键:单独按键仅 F1–F24,其余必须带修饰键。 */
+export function isAllowedSettingsHotkey(combo: string): boolean {
+  const parts = combo.split('+').filter(Boolean);
+  if (parts.length === 0) return false;
+
+  const key = parts[parts.length - 1];
</code_context>
<issue_to_address>
**带加号的快捷键会被拒绝**

当用户在捕获任务快捷键时按下带修饰键的加号键,`buildHotkeyCombo` 会使用相邻的 `+` 字符对快捷键进行编码,但 `isAllowedSettingsHotkey` 在拆分时会过滤掉空部分,从而丢失该按键。验证器会拒绝该快捷键,捕获界面则显示需要修饰键的警告。

解析带加号的快捷键时,不要丢弃由拆分结果中的空部分所表示的按键。
</issue_to_address>

Sourcery 对开源项目免费——如果你喜欢我们的审查,请考虑分享它们 ✨
Original comment in English

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/App.tsx" line_range="1677-1689" />
<code_context>
-        registeringKey = stopKey;
-        // 避免重复注册相同的键
-        if (stopKey !== startKey) {
+        if (startAllowed) {
+          registeringKey = startKey;
+          await register(toTauriKey(startKey), () => {
+            const now = Date.now();
+            if (now - lastStartTime < GLOBAL_HOTKEY_THROTTLE_MS) return;
+            lastStartTime = now;
+            document.dispatchEvent(
+              new CustomEvent('mxu-start-tasks', {
+                detail: { source: 'global-hotkey', combo: startKey },
+              }),
+            );
+          });
+        }
+        if (stopAllowed) {
+          registeringKey = stopKey;
</code_context>
<issue_to_address>
**Stale shortcuts keep running**

When global hotkeys are changed or disabled while `registerKeys` is awaiting shortcut loading or registration, the effect cleanup calls `unregisterAll()` asynchronously, but a pending `registerKeys` call can register its old key afterward. When both keys become disallowed, the branch at `bj` starts no replacement registration, so the stale callback remains active and can dispatch tasks for a shortcut no longer shown in settings.

Cancel or otherwise guard pending registrations so cleanup cannot be followed by a stale registration, including when both keys are disallowed.

Also at `src/App.tsx:1665-1668`.
</issue_to_address>

### Comment 2
<location path="src/components/FormControls.tsx" line_range="314" />
<code_context>
+/** 设置里的开始/结束快捷键:单独按键仅 F1–F24,其余必须带修饰键。 */
+export function isAllowedSettingsHotkey(combo: string): boolean {
+  const parts = combo.split('+').filter(Boolean);
+  if (parts.length === 0) return false;
+
+  const key = parts[parts.length - 1];
</code_context>
<issue_to_address>
**Plus-key shortcuts are rejected**

When the user presses a modified plus key while capturing a task shortcut, `buildHotkeyCombo` encodes the shortcut with adjacent `+` characters, but `isAllowedSettingsHotkey` filters out empty parts when splitting it, losing the key. The validator rejects the shortcut and capture shows the modifier-required warning.

Parse plus-key shortcuts without discarding the key represented by the empty split part.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/App.tsx
Comment on lines +1677 to +1689
if (startAllowed) {
registeringKey = startKey;
await register(toTauriKey(startKey), () => {
const now = Date.now();
if (now - lastStartTime < GLOBAL_HOTKEY_THROTTLE_MS) return;
lastStartTime = now;
document.dispatchEvent(
new CustomEvent('mxu-start-tasks', {
detail: { source: 'global-hotkey', combo: startKey },
}),
);
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中等 · 过期的快捷键仍在运行

当全局快捷键在 registerKeys 正等待快捷键加载或注册期间被更改或禁用时,effect 清理会异步调用 unregisterAll(),但待处理的 registerKeys 调用可能会在之后注册旧的快捷键。当两个快捷键都变为不允许使用时,bj 处的分支不会开始任何替代注册,因此过期的回调仍处于活动状态,并可能为设置中已不再显示的快捷键分发任务。

请取消待处理的注册,或以其他方式保护它们,确保清理操作之后不会发生过期注册,包括两个快捷键都不允许使用的情况。

另请查看 src/App.tsx:1665-1668。

AI Agent 提示词
在 `src/App.tsx` 第 1677–1689 行:

**过期的快捷键仍在运行**

当全局快捷键在 `registerKeys` 正等待快捷键加载或注册期间被更改或禁用时,effect 清理会异步调用 `unregisterAll()`,但待处理的 `registerKeys` 调用可能会在之后注册旧的快捷键。当两个快捷键都变为不允许使用时,`bj` 处的分支不会开始任何替代注册,因此过期的回调仍处于活动状态,并可能为设置中已不再显示的快捷键分发任务。

请取消待处理的注册,或以其他方式保护它们,确保清理操作之后不会发生过期注册,包括两个快捷键都不允许使用的情况。

另请查看 `src/App.tsx:1665-1668`。
Original comment in English

🟡 Medium · Stale shortcuts keep running

When global hotkeys are changed or disabled while registerKeys is awaiting shortcut loading or registration, the effect cleanup calls unregisterAll() asynchronously, but a pending registerKeys call can register its old key afterward. When both keys become disallowed, the branch at bj starts no replacement registration, so the stale callback remains active and can dispatch tasks for a shortcut no longer shown in settings.

Cancel or otherwise guard pending registrations so cleanup cannot be followed by a stale registration, including when both keys are disallowed.

Also at src/App.tsx:1665-1668.

Prompt for AI agents
In `src/App.tsx` at lines 1677-1689:

**Stale shortcuts keep running**

When global hotkeys are changed or disabled while `registerKeys` is awaiting shortcut loading or registration, the effect cleanup calls `unregisterAll()` asynchronously, but a pending `registerKeys` call can register its old key afterward. When both keys become disallowed, the branch at `bj` starts no replacement registration, so the stale callback remains active and can dispatch tasks for a shortcut no longer shown in settings.

Cancel or otherwise guard pending registrations so cleanup cannot be followed by a stale registration, including when both keys are disallowed.

Also at `src/App.tsx:1665-1668`.

/** 设置里的开始/结束快捷键:单独按键仅 F1–F24,其余必须带修饰键。 */
export function isAllowedSettingsHotkey(combo: string): boolean {
const parts = combo.split('+').filter(Boolean);
if (parts.length === 0) return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中等 · 带加号的快捷键会被拒绝

当用户在捕获任务快捷键时按下带修饰键的加号键,buildHotkeyCombo 会使用相邻的 + 字符对快捷键进行编码,但 isAllowedSettingsHotkey 在拆分时会过滤掉空部分,从而丢失该按键。验证器会拒绝该快捷键,捕获界面则显示需要修饰键的警告。

解析带加号的快捷键时,不要丢弃由拆分结果中的空部分所表示的按键。

AI Agent 提示词
在 `src/components/FormControls.tsx` 第 314 行:

**带加号的快捷键会被拒绝**

当用户在捕获任务快捷键时按下带修饰键的加号键,`buildHotkeyCombo` 会使用相邻的 `+` 字符对快捷键进行编码,但 `isAllowedSettingsHotkey` 在拆分时会过滤掉空部分,从而丢失该按键。验证器会拒绝该快捷键,捕获界面则显示需要修饰键的警告。

解析带加号的快捷键时,不要丢弃由拆分结果中的空部分所表示的按键。
Original comment in English

🟡 Medium · Plus-key shortcuts are rejected

When the user presses a modified plus key while capturing a task shortcut, buildHotkeyCombo encodes the shortcut with adjacent + characters, but isAllowedSettingsHotkey filters out empty parts when splitting it, losing the key. The validator rejects the shortcut and capture shows the modifier-required warning.

Parse plus-key shortcuts without discarding the key represented by the empty split part.

Prompt for AI agents
In `src/components/FormControls.tsx` at line 314:

**Plus-key shortcuts are rejected**

When the user presses a modified plus key while capturing a task shortcut, `buildHotkeyCombo` encodes the shortcut with adjacent `+` characters, but `isAllowedSettingsHotkey` filters out empty parts when splitting it, losing the key. The validator rejects the shortcut and capture shows the modifier-required warning.

Parse plus-key shortcuts without discarding the key represented by the empty split part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

全局快捷键设为「小键盘 .」后,主键盘句号键在整机范围内失效

1 participant