Merged
Conversation
Treat pre-action execution as a controllable running state so users can stop waiting for prerequisite programs, device polling, and startup delays before the main task queue begins. Made-with: Cursor
Contributor
There was a problem hiding this comment.
Hey - 我在这里给出了一些高层次的反馈:
- 当前的取消流程依赖于将
err.message与硬编码字符串MXU_PRE_ACTION_CANCELLED进行比较;建议考虑使用专门的错误类或错误标记(例如使用err.code),以避免在 TS/Rust 边界之间依赖脆弱的字符串比较。 - 在代码中有多处零散地检查
preActionControlledInstanceIdRef.current === instanceId及相关状态(例如isStartStopRunning、快捷键处理函数、performStop);如果将这类逻辑封装到一个小的辅助函数中(例如isInstanceInPreAction(instanceId)),可能会更容易理解和维护。
给 AI 代理的提示
Please address the comments from this code review:
## Overall Comments
- The cancellation flow relies on comparing `err.message` to the hard-coded string `MXU_PRE_ACTION_CANCELLED`; consider using a dedicated error class or tagging (e.g. `err.code`) to avoid fragile string comparisons across TS/Rust boundaries.
- There are several scattered checks of `preActionControlledInstanceIdRef.current === instanceId` and related state (e.g. `isStartStopRunning`, hotkey handlers, `performStop`); it may be easier to reason about and maintain if you encapsulate this logic in a small helper like `isInstanceInPreAction(instanceId)`.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- The cancellation flow relies on comparing
err.messageto the hard-coded stringMXU_PRE_ACTION_CANCELLED; consider using a dedicated error class or tagging (e.g.err.code) to avoid fragile string comparisons across TS/Rust boundaries. - There are several scattered checks of
preActionControlledInstanceIdRef.current === instanceIdand related state (e.g.isStartStopRunning, hotkey handlers,performStop); it may be easier to reason about and maintain if you encapsulate this logic in a small helper likeisInstanceInPreAction(instanceId).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The cancellation flow relies on comparing `err.message` to the hard-coded string `MXU_PRE_ACTION_CANCELLED`; consider using a dedicated error class or tagging (e.g. `err.code`) to avoid fragile string comparisons across TS/Rust boundaries.
- There are several scattered checks of `preActionControlledInstanceIdRef.current === instanceId` and related state (e.g. `isStartStopRunning`, hotkey handlers, `performStop`); it may be easier to reason about and maintain if you encapsulate this logic in a small helper like `isInstanceInPreAction(instanceId)`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 旨在解决 #157:在“前置程序/预动作”执行与等待期间,也能使用现有的停止按钮/快捷键来中断启动流程,并让工具栏把“前置程序控制中”的实例视为运行中,以便正确呈现 UI 状态和阻止冲突启动。
Changes:
- 前端引入“前置程序控制”状态与协作式取消检查(设备搜索、连接延时等待等)。
- 前端通过新的 Tauri 命令设置/清理“前置程序停止请求”,并在 run_action 等待退出时可被取消。
- 调整开始/停止按钮与快捷键停止逻辑:前置阶段也可停止,并区分“取消启动”与“启动失败”。
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/services/maaService.ts | runAction 传递 instanceId,并新增 setPreActionStop 调用后端停止标记。 |
| src/components/Toolbar.tsx | 增加前置控制状态、停止检查与等待封装;更新按钮/快捷键逻辑以支持前置阶段停止。 |
| src-tauri/src/lib.rs | 注册新的 set_pre_action_stop Tauri command。 |
| src-tauri/src/commands/types.rs | MaaState 新增 pre_action_stop_requests,用于跨命令保存停止请求。 |
| src-tauri/src/commands/system.rs | 实现 set_pre_action_stop;run_action 等待退出改为可轮询取消。 |
Comments suppressed due to low confidence (1)
src/services/maaService.ts:707
- runAction 新增了 instanceId 参数,但上方 JSDoc 仍标注为“Run pre-action”且缺少对 instanceId 的说明(尤其是它会影响后端取消逻辑)。建议补充
@paraminstanceId 的含义/来源,避免后续调用方漏传或误传。
/**
* Run pre-action
* @param program 程序路径
* @param args 附加参数
* @param cwd 工作目录(可选)
* @param waitForExit 是否等待进程退出(默认 true)
* @param useCmd 是否通过 cmd /c 启动(仅 Windows,默认 false)
* @returns 程序退出码(不等待时返回 0)
*/
async runAction(
instanceId: string,
program: string,
args: string,
cwd?: string,
waitForExit: boolean = true,
useCmd: boolean = false,
): Promise<number> {
Eliminated redundant invocation of setPreActionStop to streamline the pre-action control logic in the Toolbar component.
Improved the error handling logic in the Toolbar component's pre-action stop functionality. Added a flag to manage stopping behavior during pre-action requests, ensuring that the stopping state is correctly set based on the success of the stop request. This change enhances the robustness of task management during pre-action execution.
Implemented a background thread to manage the waiting of child processes when a stop request is received during pre-action execution. This change prevents potential child process leaks while ensuring that the stop request is handled gracefully.
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.
close #157
Summary by Sourcery
通过在前端和 Tauri 后端之间传递可取消的停止信号,使任务在预动作程序运行期间也可以被停止。
New Features:
Enhancements:
Original summary in English
Summary by Sourcery
Allow tasks to be stopped while a pre-action program is running by wiring a cancellable stop signal through the frontend and Tauri backend.
New Features:
Enhancements:
Summary by Sourcery
允许在预操作程序运行时停止任务,并在前端和后端之间传播取消状态。
New Features:
Bug Fixes:
Enhancements:
Original summary in English
Summary by Sourcery
Allow tasks to be stopped while a pre-action program is running and propagate cancellation through the frontend and backend.
New Features:
Bug Fixes:
Enhancements: