fix: 偶现重复触发开始任务崩溃 - #350
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
嘿——我发现了 1 个问题
提供给 AI 代理的提示
请处理此次代码审查中的评论:
## 个别评论
### 评论 1
<location path="src/components/Toolbar.tsx" line_range="1570-1571" />
<code_context>
+ // isStarting 是 state,disabled 要等重新渲染才生效,挡不住同一 tick 内的连点
+ if (startingRef.current) return;
+ startingRef.current = true;
+
// 检查是否需要管理员权限
</code_context>
<issue_to_address>
**问题(bug_risk):** 如果 `checkPermissionRequired()` 被拒绝,控制流会在进入 `try/finally` 代码块之前离开 `handleStartStop`,因此 `startingRef.current` 会保持为 true,后续所有从工具栏发起的启动尝试都会被永久忽略。
**触发条件:** 当 `maaService.isElevated()` 或其他权限检查操作失败时。
**建议修复:** 将权限检查放入同一个 `try/finally` 中,或者在 `checkPermissionRequired()` 外层的 `catch` 中重置 `startingRef.current`。
```suggestion
// 检查是否需要管理员权限
let needsElevation = false;
try {
needsElevation = await checkPermissionRequired();
} catch (err) {
startingRef.current = false;
throw err;
}
```
</issue_to_address>Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/components/Toolbar.tsx" line_range="1570-1571" />
<code_context>
+ // isStarting 是 state,disabled 要等重新渲染才生效,挡不住同一 tick 内的连点
+ if (startingRef.current) return;
+ startingRef.current = true;
+
// 检查是否需要管理员权限
</code_context>
<issue_to_address>
**issue (bug_risk):** If `checkPermissionRequired()` rejects, control leaves `handleStartStop` before entering the `try/finally` block, so `startingRef.current` remains true and every subsequent toolbar start attempt is permanently ignored.
**Triggers:** When `maaService.isElevated()` or another permission-check operation fails.
**Suggested fix:** Wrap the permission check in the same `try/finally`, or reset `startingRef.current` in a `catch` around `checkPermissionRequired()`.
```suggestion
// 检查是否需要管理员权限
let needsElevation = false;
try {
needsElevation = await checkPermissionRequired();
} catch (err) {
startingRef.current = false;
throw err;
}
```
</issue_to_address>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
重复触发两次开始任务,最终maafw内部崩溃,即使修了maafw,mxu也会收到两次回调导致一连串问题,所以先从源头防止一下。
close MaaEnd/MaaEnd#5749
opus5.0
Sourcery 总结
错误修复:
Original summary in English
Summary by Sourcery
Bug Fixes: