diff --git a/src/renderer/src/components/hark/HarkInfoSections.tsx b/src/renderer/src/components/hark/HarkInfoSections.tsx index da388dc..b374fd5 100644 --- a/src/renderer/src/components/hark/HarkInfoSections.tsx +++ b/src/renderer/src/components/hark/HarkInfoSections.tsx @@ -93,7 +93,7 @@ function fmtTokens(n: number): string { type QuotaMode = 'used' | 'left' const QUOTA_MODE_KEY = 'botark.hark.quotaMode' -const QUOTA_REFRESH_MS = 5 * 60_000 +const QUOTA_REFRESH_MS = 60_000 /** First parseable time among `keys` on any of `objs` (ISO string, seconds or ms). Field names are guessed: none → no line. */ const pad2 = (n: number): string => String(n).padStart(2, '0') @@ -178,7 +178,10 @@ export function HarkBillingSection({ accountId }: { accountId: string }) { setModeState(m) } const [updatedAt, setUpdatedAt] = useState(null) + const [refreshFailed, setRefreshFailed] = useState(false) const [now, setNow] = useState(() => new Date()) + const status = useBotStore((s) => s.accounts[accountId]?.status) + const prevStatus = useRef(status) const refresh = useCallback(async () => { setLoading(true) @@ -191,16 +194,27 @@ export function HarkBillingSection({ accountId }: { accountId: string }) { if (sumRaw && typeof sumRaw === 'object') { setSummary(sumRaw as Record) setUpdatedAt(new Date()) + setRefreshFailed(false) + } else { + setRefreshFailed(true) } if (profRaw && typeof profRaw === 'object') setProfile(profRaw as Record) } catch (err) { setError(cleanSidebarError(err)) + setRefreshFailed(true) } finally { setLoading(false) setNow(new Date()) } }, [accountId]) + // A Hark reply just finished (busy → online): usage moved, pull it now. + useEffect(() => { + const prev = prevStatus.current + prevStatus.current = status + if (prev === 'busy' && status === 'online') void refresh() + }, [status, refresh]) + useEffect(() => { if (!connected) return void refresh() @@ -311,7 +325,8 @@ export function HarkBillingSection({ accountId }: { accountId: string }) { {updatedAt && (

- {pad2(updatedAt.getHours())}:{pad2(updatedAt.getMinutes())} 更新 · 每 5 分钟自动刷新 + {pad2(updatedAt.getHours())}:{pad2(updatedAt.getMinutes())} 更新 · 每分钟及每次回复后自动刷新 + {refreshFailed && · 刷新失败}

)}