feat: 状态栏支持 refreshInterval 定时刷新#423
Conversation
- Zod schema 补齐 refreshInterval 字段 - 通过 scheduleUpdate 复用 300ms debounce,event/settings/time 三路触发单飞 - 新增 docs/features/status-line.mdx 调研文档
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughThis PR adds time-driven refresh capability to StatusLine. A new optional ChangesStatusLine Time-Driven Refresh
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
修复前:无法定时刷新 修复后效果如下: stateline.mov |
Summary
statusLine.refreshInterval字段(反编译版缺失,导致 settings.json 里写这个字段被静默忽略)StatusLine.tsx新增 Time-driven useEffect,经scheduleUpdate复用 300ms debounce,event/settings/time 三路触发单飞docs/features/status-line.mdx深度调研文档:渲染管线、Input/Output 协议、三种触发源、安全网关、已知缺口与本次修复Background
settings.json设"refreshInterval": 1在本仓库原本静默失效——Zod schema 没声明这个字段,StatusLine.tsx也没有setInterval。现象:TTL/时钟类状态栏脚本只在新助手回复出现时才重算,秒级倒计时永远卡住。Changes
src/utils/settings/types.ts— statusLine schema 增加refreshInterval: z.number().optional()src/components/StatusLine.tsx— 新增定时器 effect:```tsx
const refreshIntervalMs = (settings?.statusLine?.refreshInterval ?? 0) * 1000;
useEffect(() => {
if (refreshIntervalMs <= 0) return;
const id = setInterval(() => scheduleUpdate(), refreshIntervalMs);
return () => clearInterval(id);
}, [refreshIntervalMs, scheduleUpdate]);
```
设计要点:
scheduleUpdate(非doUpdate)复用已有 300ms debounce,interval + event 双触发不会双跑refreshIntervalMs <= 0时不启定时器,对未启用该字段的用户零开销refreshIntervalMs,settings 热重载会自动清理旧 interval 重建新的doUpdate内部的 AbortController 保证 single-flight:上一次 shell 没跑完,新 tick 会 abort 它,不会堆积docs/features/status-line.mdx— 完整调研文档,含整体管线图、Input 字段表、Output 协议、三种触发源对比、安全网关三层拦截、自定义脚本 8 条要点、示例(Cache 命中率 + TTL 倒计时)、已知缺口对比表。Test plan
bun run precheck通过(typecheck + lint + 4076 tests pass;1 个 flaky 集成测试独立重跑通过)bun run dev验证refreshInterval: 1时 TTL 秒级倒计时正确显示refreshInterval时无新定时器创建(代码路径 early return)Need help on this PR? Tag
@codesmithwith what you need.Summary by CodeRabbit
New Features
Documentation