mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-24 22:09:14 +00:00
feat(windows): the update badge and the CLI update banner in the popover
Two surfaces the mac has had and this build did not: the header badge that says an update is waiting, and the strip under the footer that says the CLI itself is behind. Both read one store (src/lib/update.ts), which is the observable half of the mac's UpdateChecker; the check itself is already in Rust and cached, so asking on mount costs nothing and the store only offers Rust the chance to re-check every twelve hours, well inside its own two-day interval. The badge is the mac's: it appears only when there is an update or a failed check, its label carries which stage failed, and the click does what the mac's does - retry a failed check, install an offered update, ask again otherwise. The banner keeps both of the mac's ways out: Update now, which runs the same one-click sequence, and the command itself, copyable, for anyone who would rather watch npm work in their own terminal. The banner's blue is the mac's Color.blue rather than the brand ember, deliberately: the star banner sits two rows below it in terracotta, and an informational strip that borrows the brand colour reads as a second one.
This commit is contained in:
parent
a68eea089c
commit
8de3aad4b9
7 changed files with 366 additions and 3 deletions
|
|
@ -42,6 +42,7 @@ import { FooterBar } from './components/FooterBar'
|
|||
import { ErrorToast } from './components/ErrorToast'
|
||||
import { FetchErrorOverlay } from './components/FetchErrorOverlay'
|
||||
import { Header } from './components/Header'
|
||||
import { CLIUpdateBanner } from './components/CLIUpdateBanner'
|
||||
import { accentById, applyAccent, type AccentPreset } from './lib/accent'
|
||||
|
||||
const payloadCache = new PayloadCache<MenubarPayload>()
|
||||
|
|
@ -647,6 +648,8 @@ export function App() {
|
|||
footnote={footnote}
|
||||
/>
|
||||
|
||||
<CLIUpdateBanner />
|
||||
|
||||
<StarBanner />
|
||||
|
||||
{/* With something already on screen the failure is an aside, not a wall. */}
|
||||
|
|
|
|||
55
windows/src/components/CLIUpdateBanner.tsx
Normal file
55
windows/src/components/CLIUpdateBanner.tsx
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
|
||||
import { EMPTY_UPDATE, performUpdate, subscribeUpdate, type UpdateState } from '../lib/update'
|
||||
import { ArrowUpRightCircleIcon, CheckIcon, CopyIcon } from './Icons'
|
||||
|
||||
/// Port of CLIUpdateBanner in mac/.../Views/MenuBarContent.swift: a strip under the footer
|
||||
/// when the installed codeburn is behind the latest release. Two ways out of it, as on the
|
||||
/// mac: one click that runs the update here, and the command itself, copyable, for anyone
|
||||
/// who would rather watch it happen in their own terminal.
|
||||
|
||||
export function CLIUpdateBanner() {
|
||||
const [update, setUpdate] = useState<UpdateState>(EMPTY_UPDATE)
|
||||
const [copied, setCopied] = useState(false)
|
||||
useEffect(() => subscribeUpdate(setUpdate), [])
|
||||
|
||||
const status = update.status
|
||||
if (!status?.cliUpdateAvailable) return null
|
||||
const command = status.cliUpdateCommand
|
||||
|
||||
const copy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(command)
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 1500)
|
||||
} catch {
|
||||
setCopied(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="cli-banner">
|
||||
<span className="cli-banner-icon" aria-hidden="true"><ArrowUpRightCircleIcon size={11} /></span>
|
||||
<span className="cli-banner-text">CLI v{status.latestCliVersion} available</span>
|
||||
<button
|
||||
type="button"
|
||||
className="cli-banner-action"
|
||||
disabled={update.updating}
|
||||
title="Update the CLI, and the tray app if one is available, automatically"
|
||||
onClick={() => { void performUpdate() }}
|
||||
>
|
||||
{update.updating ? 'Updating...' : 'Update now'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="cli-banner-copy"
|
||||
title="Copy the update command to the clipboard"
|
||||
onClick={copy}
|
||||
>
|
||||
<code>{command}</code>
|
||||
{copied ? <CheckIcon size={9} /> : <CopyIcon size={9} />}
|
||||
</button>
|
||||
<span className="cli-banner-spacer" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
import { useState } from 'react'
|
||||
import { ACCENT_PRESETS, type AccentPreset } from '../lib/accent'
|
||||
import { QuotaWarningRow } from './QuotaWarningRow'
|
||||
import { UpdateBadge } from './UpdateBadge'
|
||||
import type { QuotaState } from '../lib/quota'
|
||||
|
||||
/// Port of Header in mac/Sources/CodeBurnMenubar/Views/MenuBarContent.swift: the flame
|
||||
/// wordmark and tagline on the left, the accent picker on the right, and the quota warning
|
||||
/// row underneath. Package E adds the update badge between them.
|
||||
/// wordmark and tagline on the left, the update badge and the accent picker on the right,
|
||||
/// and the quota warning row underneath.
|
||||
|
||||
type Props = {
|
||||
quota: QuotaState
|
||||
|
|
@ -23,7 +24,10 @@ export function Header({ quota, showQuota, accent, onAccent, animate }: Props) {
|
|||
<FlameWordmark animate={animate} />
|
||||
<div className="subhead">Your AI Bill, Itemized</div>
|
||||
</div>
|
||||
<AccentPicker accent={accent} onAccent={onAccent} />
|
||||
<div className="header-actions">
|
||||
<UpdateBadge />
|
||||
<AccentPicker accent={accent} onAccent={onAccent} />
|
||||
</div>
|
||||
</div>
|
||||
{showQuota && <QuotaWarningRow quota={quota} />}
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -266,3 +266,13 @@ export function PowerIcon(p: IconProps) {
|
|||
</Svg>
|
||||
)
|
||||
}
|
||||
|
||||
/// doc.on.doc, for the copyable command in the CLI update banner.
|
||||
export function CopyIcon(p: IconProps) {
|
||||
return (
|
||||
<Svg {...p}>
|
||||
<rect x="5.5" y="5.5" width="8" height="8" rx="1.5" />
|
||||
<path d="M10.5 3.5a1.5 1.5 0 0 0-1.5-1.5H4a1.5 1.5 0 0 0-1.5 1.5V9a1.5 1.5 0 0 0 1.5 1.5" />
|
||||
</Svg>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
43
windows/src/components/UpdateBadge.tsx
Normal file
43
windows/src/components/UpdateBadge.tsx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
|
||||
import {
|
||||
EMPTY_UPDATE, badgeAction, badgeLabel, badgeVisible, checkUpdates, helpText, performUpdate,
|
||||
subscribeUpdate, type UpdateState,
|
||||
} from '../lib/update'
|
||||
import { DownloadIcon, RefreshIcon, WarningIcon } from './Icons'
|
||||
|
||||
/// Port of UpdateBadge in mac/.../Views/MenuBarContent.swift: a small prominent pill in the
|
||||
/// header, there only when there is something to say. A failed check retries the check, an
|
||||
/// offered update installs it in one click, and the tooltip carries the whole story.
|
||||
|
||||
export function UpdateBadge() {
|
||||
const [update, setUpdate] = useState<UpdateState>(EMPTY_UPDATE)
|
||||
useEffect(() => subscribeUpdate(setUpdate), [])
|
||||
|
||||
if (!update.updating && !badgeVisible(update)) return null
|
||||
|
||||
const label = badgeLabel(update)
|
||||
const help = helpText(update)
|
||||
const failed = update.status?.error != null
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="update-badge"
|
||||
title={help}
|
||||
aria-label={label}
|
||||
disabled={update.updating}
|
||||
onClick={() => {
|
||||
if (badgeAction(update) === 'update') void performUpdate()
|
||||
else void checkUpdates(true)
|
||||
}}
|
||||
>
|
||||
{update.updating
|
||||
? <span className="update-badge-spin"><RefreshIcon size={10} /></span>
|
||||
: failed
|
||||
? <WarningIcon size={10} />
|
||||
: <DownloadIcon size={10} />}
|
||||
<span>{label}</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
189
windows/src/lib/update.ts
Normal file
189
windows/src/lib/update.ts
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/// The one update source the page has. The header badge, the CLI banner and the About pane
|
||||
/// all read this store, so one answer feeds them all rather than each asking Rust its own
|
||||
/// question.
|
||||
///
|
||||
/// Port of the observable half of mac/.../Data/UpdateChecker.swift. The check itself lives
|
||||
/// in Rust (`src-tauri/src/update.rs`): it talks to GitHub, keeps the answer on disk and
|
||||
/// only spends a request once the two-day interval is up, so asking on every mount is free.
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { listen } from '@tauri-apps/api/event'
|
||||
|
||||
/// UpdateFailureStage: which half of the sequence failed, or which one is running.
|
||||
export type UpdateStage = 'check' | 'cliUpdate' | 'menubarUpdate'
|
||||
|
||||
export type UpdateStatus = {
|
||||
currentVersion: string
|
||||
latestVersion: string | null
|
||||
latestCliVersion: string | null
|
||||
installedCliVersion: string | null
|
||||
updateAvailable: boolean
|
||||
cliUpdateAvailable: boolean
|
||||
/// Too old to install the app, whether or not it is also behind the latest release.
|
||||
cliTooOld: boolean
|
||||
cliUpdateCommand: string
|
||||
checkedAt: number | null
|
||||
failureStage: UpdateStage | null
|
||||
error: string | null
|
||||
}
|
||||
|
||||
export type UpdateState = {
|
||||
status: UpdateStatus | null
|
||||
checking: boolean
|
||||
updating: boolean
|
||||
/// The stage the running update is on, for the label while it works.
|
||||
stage: UpdateStage | null
|
||||
}
|
||||
|
||||
export const EMPTY_UPDATE: UpdateState = {
|
||||
status: null,
|
||||
checking: false,
|
||||
updating: false,
|
||||
stage: null,
|
||||
}
|
||||
|
||||
/// Rust decides whether a check costs a request; this only decides how often it is offered
|
||||
/// the chance. Well inside the two-day interval, so an app left running for a week still
|
||||
/// learns about a release, and far enough apart that the `codeburn --version` each ask
|
||||
/// spawns is nothing beside the usage refresh.
|
||||
const ASK_INTERVAL_MS = 12 * 60 * 60_000
|
||||
|
||||
type Listener = (state: UpdateState) => void
|
||||
|
||||
let state: UpdateState = EMPTY_UPDATE
|
||||
let listeners: Listener[] = []
|
||||
let timer: number | undefined
|
||||
let inFlight: Promise<void> | null = null
|
||||
let stageListener: Promise<() => void> | null = null
|
||||
|
||||
function publish(next: Partial<UpdateState>) {
|
||||
state = { ...state, ...next }
|
||||
for (const listener of listeners) listener(state)
|
||||
}
|
||||
|
||||
/// `force` skips the two-day gate, which is what the buttons that say Check for Updates do.
|
||||
export async function checkUpdates(force: boolean): Promise<void> {
|
||||
if (inFlight) return inFlight
|
||||
publish({ checking: true })
|
||||
inFlight = (async () => {
|
||||
try {
|
||||
const status = await invoke<UpdateStatus>('check_updates', { force })
|
||||
publish({ status, checking: false })
|
||||
} catch (err) {
|
||||
// A command that refuses to run at all is still a failed check, and the badge says so
|
||||
// rather than staying silent about a question nobody answered.
|
||||
publish({
|
||||
checking: false,
|
||||
status: {
|
||||
...(state.status ?? blankStatus()),
|
||||
failureStage: 'check',
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
},
|
||||
})
|
||||
}
|
||||
})().finally(() => { inFlight = null })
|
||||
return inFlight
|
||||
}
|
||||
|
||||
/// One click, both updates: Rust runs the CLI update and then the app install, and reports
|
||||
/// the status the sequence ended on.
|
||||
export async function performUpdate(): Promise<void> {
|
||||
if (state.updating) return
|
||||
publish({ updating: true, stage: 'cliUpdate' })
|
||||
try {
|
||||
const status = await invoke<UpdateStatus>('perform_update')
|
||||
publish({ status, updating: false, stage: null })
|
||||
} catch (err) {
|
||||
publish({
|
||||
updating: false,
|
||||
stage: null,
|
||||
status: {
|
||||
...(state.status ?? blankStatus()),
|
||||
failureStage: 'menubarUpdate',
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function blankStatus(): UpdateStatus {
|
||||
return {
|
||||
currentVersion: '',
|
||||
latestVersion: null,
|
||||
latestCliVersion: null,
|
||||
installedCliVersion: null,
|
||||
updateAvailable: false,
|
||||
cliUpdateAvailable: false,
|
||||
cliTooOld: false,
|
||||
cliUpdateCommand: 'npm update -g codeburn',
|
||||
checkedAt: null,
|
||||
failureStage: null,
|
||||
error: null,
|
||||
}
|
||||
}
|
||||
|
||||
export function subscribeUpdate(listener: Listener): () => void {
|
||||
listeners.push(listener)
|
||||
listener(state)
|
||||
if (listeners.length === 1) {
|
||||
if (state.status === null) void checkUpdates(false)
|
||||
timer = window.setInterval(() => { void checkUpdates(false) }, ASK_INTERVAL_MS)
|
||||
// The running stage is what turns "Updating..." into something that says which half.
|
||||
stageListener = listen<UpdateStage>('codeburn://update-stage', event => {
|
||||
if (state.updating) publish({ stage: event.payload })
|
||||
})
|
||||
}
|
||||
return () => {
|
||||
listeners = listeners.filter(l => l !== listener)
|
||||
if (listeners.length === 0) {
|
||||
window.clearInterval(timer)
|
||||
stageListener?.then(fn => fn())
|
||||
stageListener = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// UpdateChecker.updateBadgeLabel.
|
||||
export function badgeLabel(state: UpdateState): string {
|
||||
if (state.updating) return 'Updating...'
|
||||
switch (state.status?.failureStage) {
|
||||
case 'check': return 'Update Check Failed'
|
||||
case 'cliUpdate': return 'CLI Update Failed'
|
||||
case 'menubarUpdate': return 'Menubar Update Failed'
|
||||
default: return 'Update'
|
||||
}
|
||||
}
|
||||
|
||||
const STAGE_SUMMARY: Record<UpdateStage, string> = {
|
||||
check: 'CodeBurn could not check GitHub for updates.',
|
||||
cliUpdate: 'CodeBurn could not update the CLI.',
|
||||
menubarUpdate: 'CodeBurn could not update the tray app.',
|
||||
}
|
||||
|
||||
const STAGE_RETRY: Record<UpdateStage, string> = {
|
||||
check: 'Click to retry the update check.',
|
||||
cliUpdate: 'Click to retry the update.',
|
||||
menubarUpdate: 'Click to retry the update.',
|
||||
}
|
||||
|
||||
/// UpdateChecker.updateHelpText.
|
||||
export function helpText(state: UpdateState): string {
|
||||
const stage = state.status?.failureStage
|
||||
const error = state.status?.error
|
||||
if (!stage || !error) return 'Update the CLI and the tray app to the latest release'
|
||||
return `${STAGE_SUMMARY[stage]}\n\n${error}\n\n${STAGE_RETRY[stage]}`
|
||||
}
|
||||
|
||||
/// What a click on the badge does, from the mac's UpdateBadge: a failed check retries the
|
||||
/// check, an offered update installs it, and anything else asks again.
|
||||
export function badgeAction(state: UpdateState): 'check' | 'update' {
|
||||
if (state.status?.failureStage === 'check') return 'check'
|
||||
if (state.status?.updateAvailable || state.status?.cliUpdateAvailable) return 'update'
|
||||
return 'check'
|
||||
}
|
||||
|
||||
export function badgeVisible(state: UpdateState): boolean {
|
||||
const status = state.status
|
||||
if (!status) return false
|
||||
return status.updateAvailable || status.cliUpdateAvailable || status.error !== null
|
||||
}
|
||||
|
|
@ -40,6 +40,9 @@
|
|||
--danger: #C83F2C;
|
||||
/* Routing waste, from the mac OptimizeInsight purple. */
|
||||
--routing-ink: #8944AB;
|
||||
/* The CLI update banner, from the mac's Color.blue: informational rather than branded,
|
||||
so it never reads as the terracotta star banner two rows below it. */
|
||||
--update-ink: #007AFF;
|
||||
|
||||
/* Quota severity, from QuotaSummary.Severity: under 50 green, then yellow, orange, red.
|
||||
Three sets, because one colour cannot do three jobs here. The bare token is the bar
|
||||
|
|
@ -116,6 +119,7 @@
|
|||
--sev-critical-tip: #C2610A;
|
||||
--sev-danger-tip: #C83F2C;
|
||||
--routing-ink: #BF5AF2;
|
||||
--update-ink: #0A84FF;
|
||||
--icon-contrast: #1C1816;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
|
@ -158,6 +162,7 @@
|
|||
--sev-critical-tip: #C2610A;
|
||||
--sev-danger-tip: #C83F2C;
|
||||
--routing-ink: #BF5AF2;
|
||||
--update-ink: #0A84FF;
|
||||
--icon-contrast: #1C1816;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
|
@ -246,7 +251,30 @@ code { font-family: var(--font-mono); }
|
|||
.subhead { font-size: 10.5px; color: var(--label-2); }
|
||||
|
||||
/* Accent picker: a dot showing the current preset, which reveals the nine swatches. */
|
||||
.header-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
|
||||
.accent-picker { display: flex; align-items: center; margin-left: auto; }
|
||||
|
||||
/* The update badge: the mac's borderedProminent mini pill in the brand tint, sitting where
|
||||
the header has room for it and gone entirely when there is nothing to update. */
|
||||
.update-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
height: 18px;
|
||||
padding: 0 7px;
|
||||
border: 0;
|
||||
border-radius: var(--radius-pill);
|
||||
background: var(--brand-accent);
|
||||
color: #FFFFFF;
|
||||
font-family: inherit;
|
||||
font-size: 10px;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.update-badge:hover:not(:disabled) { background: #B84A1A; }
|
||||
.update-badge:active:not(:disabled) { background: var(--ember-deep); }
|
||||
.update-badge:disabled { opacity: 0.75; }
|
||||
.update-badge-spin { display: inline-flex; animation: spin 0.9s linear infinite; }
|
||||
.accent-swatches {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
|
|
@ -1904,6 +1932,37 @@ code { font-family: var(--font-mono); }
|
|||
}
|
||||
.star-banner-close:hover { background: var(--fill-08); }
|
||||
|
||||
/* ---- CLI update banner ---------------------------------------------------------- */
|
||||
|
||||
.cli-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 12px;
|
||||
background: color-mix(in srgb, var(--update-ink) 8%, transparent);
|
||||
box-shadow: inset 0 0.5px 0 var(--fill-18);
|
||||
}
|
||||
.cli-banner-icon { color: var(--update-ink); display: inline-flex; flex-shrink: 0; }
|
||||
.cli-banner-text { font-size: 10.5px; font-weight: 500; color: var(--label); white-space: nowrap; }
|
||||
.cli-banner-action,
|
||||
.cli-banner-copy {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--update-ink);
|
||||
font-family: inherit;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.cli-banner-action:disabled { opacity: 0.6; }
|
||||
.cli-banner-copy code { font-family: var(--font-mono); font-size: 10px; font-weight: 500; }
|
||||
.cli-banner-copy:hover code { text-decoration: underline; }
|
||||
.cli-banner-spacer { flex: 1; }
|
||||
|
||||
/* ---- error toast --------------------------------------------------------------- */
|
||||
|
||||
.error-toast {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue