Conversation
There was a problem hiding this comment.
Hey - 我已经审查了你的更改,看起来非常棒!
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据这些反馈来改进对你代码的评审。
Original comment in English
Hey - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
该 PR 主要围绕定时器/定时任务触发逻辑进行重构(对应 issue #1459),将原先在 Toolbar 内部的整点定时触发改为独立的 ScheduleService 轮询 + 补偿检查机制,并顺带抽取更新下载代理选择逻辑以消除重复。
Changes:
- 新增
ScheduleService:按分钟轮询整点时间槽,并在窗口 focus/可见性变化时触发补偿检查。 - 更新
Toolbar:移除旧的整点setTimeout + setInterval实现,改为挂载调度服务回调。 - 抽取更新下载代理选择逻辑为
proxySettingsForUpdateDownload,并同步更新 App/设置页/更新面板调用;新增“补偿执行”日志文案的多语言翻译键。
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/services/scheduleService.ts | 新增调度服务:轮询、补偿检查、触发去重与 localStorage 记录 |
| src/components/Toolbar.tsx | 接入 scheduleService,用回调触发定时任务启动与日志写入 |
| src/services/proxyService.ts | 新增 proxySettingsForUpdateDownload 统一更新下载代理选择规则 |
| src/App.tsx | 自动下载更新时改用 proxySettingsForUpdateDownload |
| src/components/UpdatePanel.tsx | 手动下载更新时改用 proxySettingsForUpdateDownload |
| src/components/settings/UpdateSection.tsx | 设置页下载更新时改用 proxySettingsForUpdateDownload |
| src/i18n/locales/zh-CN.ts | 新增 logs.messages.scheduleCompensating 文案 |
| src/i18n/locales/zh-TW.ts | 新增 logs.messages.scheduleCompensating 文案 |
| src/i18n/locales/en-US.ts | 新增 logs.messages.scheduleCompensating 文案 |
| src/i18n/locales/ja-JP.ts | 新增 logs.messages.scheduleCompensating 文案 |
| src/i18n/locales/ko-KR.ts | 新增 logs.messages.scheduleCompensating 文案 |
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - 我在这里给出一些整体性的反馈:
- 在
ScheduleService.check中,useAppStore.getState()在嵌套循环里被反复调用(每个 slot 一次,并且在重新获取freshInst时对每个 instance 再调用一次);建议在每次检查时只获取一次 state,或者至少每个 slot 获取一次,以避免不必要的重复 store 读取,并减少单次运行中可能出现的不一致问题。 normalizeTriggeredSlotKey的逻辑假设instanceId中不会包含:,并在遇到第一个冒号时截断;如果 instance ID 有可能包含:,这可能会把不同的 ID 折叠为同一个 key,从而导致触发遗漏或重复。更安全的做法可能是存储一个结构化对象,或者使用一种不可能出现在 ID 中的分隔符。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- In `ScheduleService.check`, `useAppStore.getState()` is called repeatedly inside the nested loops (once per slot and again per instance when re-fetching `freshInst`); consider fetching state once per check or at least once per slot to avoid unnecessary repeated store reads and potential inconsistency within a single run.
- The `normalizeTriggeredSlotKey` logic assumes `instanceId` has no `:` and truncates at the first colon; if instance IDs could ever contain `:`, this may collapse distinct IDs into the same key and cause missed or duplicated triggers, so it may be safer to store a structured object or use a delimiter that cannot appear in IDs.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进之后的 Review。
Original comment in English
Hey - I've left some high level feedback:
- In
ScheduleService.check,useAppStore.getState()is called repeatedly inside the nested loops (once per slot and again per instance when re-fetchingfreshInst); consider fetching state once per check or at least once per slot to avoid unnecessary repeated store reads and potential inconsistency within a single run. - The
normalizeTriggeredSlotKeylogic assumesinstanceIdhas no:and truncates at the first colon; if instance IDs could ever contain:, this may collapse distinct IDs into the same key and cause missed or duplicated triggers, so it may be safer to store a structured object or use a delimiter that cannot appear in IDs.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ScheduleService.check`, `useAppStore.getState()` is called repeatedly inside the nested loops (once per slot and again per instance when re-fetching `freshInst`); consider fetching state once per check or at least once per slot to avoid unnecessary repeated store reads and potential inconsistency within a single run.
- The `normalizeTriggeredSlotKey` logic assumes `instanceId` has no `:` and truncates at the first colon; if instance IDs could ever contain `:`, this may collapse distinct IDs into the same key and cause missed or duplicated triggers, so it may be safer to store a structured object or use a delimiter that cannot appear in IDs.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
|
||
| private getLastCheckAt(): number { | ||
| const val = localStorage.getItem(STORAGE_KEY_LAST_CHECK); | ||
| return val ? parseInt(val, 10) : 0; |
There was a problem hiding this comment.
getLastCheckAt() 直接 parseInt 可能返回 NaN(例如 localStorage 值被手动修改或历史版本写入异常),后续比较/构造 Date 会导致本轮调度扫描被跳过。建议在这里对 NaN 做兜底(例如无效时当作 0 并重置该 key)。
| return val ? parseInt(val, 10) : 0; | |
| if (!val) { | |
| return 0; | |
| } | |
| const parsed = parseInt(val, 10); | |
| if (Number.isNaN(parsed)) { | |
| // 数据被污染或历史版本写入异常,重置为 0 以避免本轮调度被跳过 | |
| this.setLastCheckAt(0); | |
| return 0; | |
| } | |
| return parsed; |
| } | ||
|
|
||
| return normalized; | ||
| } catch { | ||
| return new Set(); | ||
| } |
There was a problem hiding this comment.
getTriggeredSlots() 在 JSON 解析失败时直接吞掉异常并返回空集合,会导致调度去重状态悄悄失效且之后每次轮询都重复触发同样的异常。建议在 catch 中记录一次 warn 并清理/重置 mxu_schedule_triggeredSlots,以便自愈并避免持续的异常开销。
fix MaaEnd/MaaEnd#1459
fix MaaEnd/MaaEnd#1448
由 Sourcery 提供的摘要
将定时任务处理重构为一个集中式服务,并在整个应用中统一更新下载时的代理行为。
错误修复:
增强改进:
Original summary in English
Summary by Sourcery
Refactor scheduled task handling into a centralized service and align update download proxy behavior across the app.
Bug Fixes:
Enhancements:
Summary by Sourcery
将定时任务处理重构为集中式调度服务,并统一应用内更新下载的代理行为。
Bug Fixes:
Enhancements:
Original summary in English
Summary by Sourcery
Refactor scheduled task handling into a centralized scheduling service and align update download proxy behavior across the app.
Bug Fixes:
Enhancements: