Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/renderer/src/components/hark/HarkInfoSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -178,7 +178,10 @@ export function HarkBillingSection({ accountId }: { accountId: string }) {
setModeState(m)
}
const [updatedAt, setUpdatedAt] = useState<Date | null>(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)
Expand All @@ -191,16 +194,27 @@ export function HarkBillingSection({ accountId }: { accountId: string }) {
if (sumRaw && typeof sumRaw === 'object') {
setSummary(sumRaw as Record<string, unknown>)
setUpdatedAt(new Date())
setRefreshFailed(false)
} else {
setRefreshFailed(true)
}
if (profRaw && typeof profRaw === 'object') setProfile(profRaw as Record<string, unknown>)
} 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()
Expand Down Expand Up @@ -311,7 +325,8 @@ export function HarkBillingSection({ accountId }: { accountId: string }) {

{updatedAt && (
<p className="border-t border-line pt-1.5 text-[11px] text-ink-muted">
{pad2(updatedAt.getHours())}:{pad2(updatedAt.getMinutes())} 更新 · 每 5 分钟自动刷新
{pad2(updatedAt.getHours())}:{pad2(updatedAt.getMinutes())} 更新 · 每分钟及每次回复后自动刷新
{refreshFailed && <span className="text-status-error"> · 刷新失败</span>}
</p>
)}
</div>
Expand Down