mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-24 22:09:14 +00:00
feat(windows): a fetch-error overlay with Retry, and stuck-load recovery
A failed fetch put an eight-second toast over an empty window and then took the toast away, leaving a blank popover and no way to try again. The mac replaces the loading overlay with a retry card whenever the fetch failed and there is nothing cached to fall back on, and keeps a toast for the case where numbers are already on screen and the failure is an aside. Do the same, and clear the error whenever the selection changes or a fetch succeeds, since an error describes one selection. Stuck-load recovery is the mac's ladder: while the popover has nothing to show, retry at 8 s doubling to 60 s, six times, then say "Could not load X. Check that the codeburn CLI is installed and working." A fetch torn down across sleep can leave its in-flight mark behind, which would make every retry bail on the guard, so a mark older than the CLI's own 60 s timeout is cleared first. A younger one is left alone, so recovery never races a fetch that is still going to answer. The toast is anchored to the popover card rather than to the window: the card now sits inside a transparent gutter, so an absolute offset from the window is 12 px out.
This commit is contained in:
parent
5fa0263559
commit
7390236fdd
4 changed files with 138 additions and 5 deletions
|
|
@ -36,6 +36,7 @@ import { ScopeControl, type Scope } from './components/ScopeControl'
|
|||
import type { DaySelection, Period } from './components/PeriodTabs'
|
||||
import { FooterBar } from './components/FooterBar'
|
||||
import { ErrorToast } from './components/ErrorToast'
|
||||
import { FetchErrorOverlay } from './components/FetchErrorOverlay'
|
||||
import { Header } from './components/Header'
|
||||
import { applyAccent, savedAccent, type AccentPreset } from './lib/accent'
|
||||
import { SettingsPanel, type SettingsSection, type ThemeChoice } from './components/SettingsPanel'
|
||||
|
|
@ -62,6 +63,17 @@ const REFRESH_ACTIVE_MS = 60_000
|
|||
const REFRESH_IDLE_MS = 120_000
|
||||
const STALE_MS = 60_000
|
||||
|
||||
/// Stuck-load recovery, from the mac BurnLoadingOverlay task: while the popover has
|
||||
/// nothing to show, retry the fetch on a doubling delay and then give up with a message
|
||||
/// rather than spinning forever. The first delay is longer than a healthy CLI run.
|
||||
const RECOVERY_FIRST_MS = 8_000
|
||||
const RECOVERY_MAX_MS = 60_000
|
||||
const RECOVERY_ATTEMPTS = 6
|
||||
/// A fetch older than the Rust side's own 60 s timeout is an orphan, not a slow run: its
|
||||
/// in-flight mark can be cleared. A younger one is left alone so recovery never kills a
|
||||
/// fetch that is still going to answer.
|
||||
const FLIGHT_WATCHDOG_MS = 65_000
|
||||
|
||||
type FetchOptions = {
|
||||
includeOptimize: boolean
|
||||
showOverlay: boolean
|
||||
|
|
@ -136,6 +148,7 @@ export function App() {
|
|||
}
|
||||
payloadCache.set(key, json)
|
||||
if (isSelected()) {
|
||||
setError(null)
|
||||
setPayload(json)
|
||||
// "updated Xs ago" describes what the user is looking at, so only a fetch of the
|
||||
// visible key may stamp it - a background today/all tick must not.
|
||||
|
|
@ -207,6 +220,8 @@ export function App() {
|
|||
useEffect(() => {
|
||||
const key = selection.current
|
||||
const cached = payloadCache.get(key)
|
||||
// The error describes the selection that failed, so it goes with it.
|
||||
setError(null)
|
||||
setPayload(cached)
|
||||
if (!cliReady) return
|
||||
if (!cached) {
|
||||
|
|
@ -252,6 +267,34 @@ export function App() {
|
|||
}
|
||||
useEffect(readDailyBudget, [])
|
||||
|
||||
// Nothing on screen and nothing coming: retry on a doubling delay, then say so. A
|
||||
// fetch torn down across sleep can leave its in-flight mark behind, which would make
|
||||
// every retry bail on the guard, so a mark older than the watchdog is cleared first.
|
||||
const coldLoading = overlay && payload === null && error === null
|
||||
useEffect(() => {
|
||||
if (!coldLoading || !cliReady) return
|
||||
let attempt = 0
|
||||
let delay = RECOVERY_FIRST_MS
|
||||
let timer = 0
|
||||
const tick = () => {
|
||||
attempt += 1
|
||||
const key = selection.current
|
||||
if (payloadCache.flightAge(key) > FLIGHT_WATCHDOG_MS) payloadCache.clearInFlight(key)
|
||||
fetchKey(key, { includeOptimize: false, showOverlay: true })
|
||||
if (attempt >= RECOVERY_ATTEMPTS) {
|
||||
setError(`Could not load ${label}. Check that the codeburn CLI is installed and working.`)
|
||||
return
|
||||
}
|
||||
delay = Math.min(delay * 2, RECOVERY_MAX_MS)
|
||||
timer = window.setTimeout(tick, delay)
|
||||
}
|
||||
timer = window.setTimeout(tick, delay)
|
||||
return () => window.clearTimeout(timer)
|
||||
// `label` only decorates the give-up message; re-arming the ladder on a relabel
|
||||
// would restart the clock for no reason.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [coldLoading, cliReady, fetchKey])
|
||||
|
||||
// The quota store polls only while something is watching it, so it starts here and stops
|
||||
// with the page. A manual Refresh asks it for a fresh answer too.
|
||||
useEffect(() => subscribeQuota(setQuota), [])
|
||||
|
|
@ -391,6 +434,8 @@ export function App() {
|
|||
&& (payload.current?.calls ?? 0) === 0 && (payload.current?.sessions ?? 0) === 0
|
||||
&& (payload.history?.daily?.length ?? 0) === 0
|
||||
|
||||
const label = daySelectionLabel(days) ?? PERIOD_LABELS[period]
|
||||
|
||||
const footnote = [version ? `CodeBurn v${version}` : 'CodeBurn', lastUpdated ? `updated ${relativePast(lastUpdated)}` : null]
|
||||
.filter(Boolean)
|
||||
.join(' · ')
|
||||
|
|
@ -433,7 +478,7 @@ export function App() {
|
|||
<HeroSection
|
||||
payload={payload}
|
||||
currency={currency}
|
||||
periodLabel={daySelectionLabel(days) ?? PERIOD_LABELS[period]}
|
||||
periodLabel={label}
|
||||
isToday={days.length === 0 && period === 'today'}
|
||||
dailyBudget={dailyBudget}
|
||||
combinedScope={effectiveScope === 'combined'}
|
||||
|
|
@ -500,7 +545,20 @@ export function App() {
|
|||
)}
|
||||
</>
|
||||
)}
|
||||
{overlay && <LoadingOverlay periodLabel={daySelectionLabel(days) ?? PERIOD_LABELS[period]} />}
|
||||
{/* The overlay only takes over on a cold cache, so a failed background
|
||||
refresh leaves the numbers that are already on screen alone. */}
|
||||
{payload === null && error !== null ? (
|
||||
<FetchErrorOverlay
|
||||
message={error}
|
||||
periodLabel={label}
|
||||
onRetry={() => {
|
||||
setError(null)
|
||||
refreshAll({ includeOptimize: false, showOverlay: true })
|
||||
}}
|
||||
/>
|
||||
) : overlay ? (
|
||||
<LoadingOverlay periodLabel={label} />
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
|
@ -524,7 +582,10 @@ export function App() {
|
|||
|
||||
<StarBanner />
|
||||
|
||||
{error && <ErrorToast message={error} onDismiss={() => setError(null)} />}
|
||||
{/* With something already on screen the failure is an aside, not a wall. */}
|
||||
{error !== null && payload !== null && (
|
||||
<ErrorToast message={error} onDismiss={() => setError(null)} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
29
windows/src/components/FetchErrorOverlay.tsx
Normal file
29
windows/src/components/FetchErrorOverlay.tsx
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { WarningIcon } from './Icons'
|
||||
|
||||
/// Port of FetchErrorOverlay in mac/.../Views/MenuBarContent.swift. Shown in place of the
|
||||
/// loading overlay when the fetch failed and there is nothing cached to fall back on, so a
|
||||
/// failed CLI run reads as a failure with a way out rather than an endless spinner.
|
||||
|
||||
const MAX_MESSAGE = 240
|
||||
|
||||
type Props = {
|
||||
message: string
|
||||
periodLabel: string
|
||||
onRetry: () => void
|
||||
}
|
||||
|
||||
export function FetchErrorOverlay({ message, periodLabel, onRetry }: Props) {
|
||||
const trimmed = message.trim()
|
||||
const shown = trimmed.length <= MAX_MESSAGE ? trimmed : `${trimmed.slice(0, MAX_MESSAGE)}…`
|
||||
|
||||
return (
|
||||
<div className="fetch-error-overlay" role="alert">
|
||||
<div className="fetch-error-content">
|
||||
<WarningIcon size={28} className="fetch-error-icon" />
|
||||
<div className="fetch-error-title">Couldn't load {periodLabel}</div>
|
||||
<div className="fetch-error-message">{shown}</div>
|
||||
<button type="button" className="btn btn-prominent" onClick={onRetry}>Retry</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ interface CacheEntry<T> {
|
|||
|
||||
export class PayloadCache<T> {
|
||||
private store = new Map<string, CacheEntry<T>>()
|
||||
private flights = new Set<string>()
|
||||
private flights = new Map<string, number>()
|
||||
|
||||
get(selection: Selection): T | null {
|
||||
return this.store.get(selectionKey(selection))?.data ?? null
|
||||
|
|
@ -50,8 +50,15 @@ export class PayloadCache<T> {
|
|||
return this.flights.has(selectionKey(selection))
|
||||
}
|
||||
|
||||
/// Milliseconds since the in-flight fetch started, or 0 when there is none. Stuck-load
|
||||
/// recovery uses this to tell an orphaned entry from a fetch that is simply slow.
|
||||
flightAge(selection: Selection): number {
|
||||
const started = this.flights.get(selectionKey(selection))
|
||||
return started === undefined ? 0 : Date.now() - started
|
||||
}
|
||||
|
||||
markInFlight(selection: Selection): void {
|
||||
this.flights.add(selectionKey(selection))
|
||||
this.flights.set(selectionKey(selection), Date.now())
|
||||
}
|
||||
|
||||
clearInFlight(selection: Selection): void {
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ code { font-family: var(--font-mono); }
|
|||
this drop shadow follows the card radius instead of the square window frame. That is
|
||||
why the window has no DWM shadow and no DWM rounding: both trace a rectangle. */
|
||||
.popover {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin: var(--popover-gutter);
|
||||
|
|
@ -1762,6 +1763,41 @@ code { font-family: var(--font-mono); }
|
|||
.loading-content { display: flex; flex-direction: column; align-items: center; gap: 14px; }
|
||||
.loading-text { font-size: 11.5px; font-weight: 500; color: var(--label-2); }
|
||||
|
||||
/* Fetch error: the same sheet as the loading overlay, because it replaces it. */
|
||||
.fetch-error-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 30;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 20px;
|
||||
background: var(--overlay-material);
|
||||
backdrop-filter: blur(18px) saturate(160%);
|
||||
-webkit-backdrop-filter: blur(18px) saturate(160%);
|
||||
animation: fadeIn 200ms ease-in-out;
|
||||
}
|
||||
.fetch-error-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
max-width: 280px;
|
||||
text-align: center;
|
||||
}
|
||||
.fetch-error-icon { color: var(--brand-accent); }
|
||||
.fetch-error-title { font-size: 12.5px; font-weight: 600; color: var(--label); }
|
||||
.fetch-error-message {
|
||||
font-size: 10.5px;
|
||||
line-height: 1.4;
|
||||
color: var(--label-2);
|
||||
user-select: text;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.burn-flame { position: relative; }
|
||||
.burn-flame svg { position: absolute; inset: 0; }
|
||||
.burn-flame-glow path { fill: var(--ember-glow); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue