Files
Reims-Go/frontend/src/components/UpdateCapsule.tsx
T
Nwflower f0b69c252c feat(update,plugin,ui): add in-app self-update, plugin locale packs, and About page
- Add shared resumable + SHA256SUMS-verified downloader (internal/fetch) and Windows executable swap/relaunch flow (internal/selfupdate, internal/app/appupdate_flow.go, --wait-pid in main.go/cli).
- Add dedicated About page and sidebar update capsule with background release checks, download progress, and restart confirmation when VMs are running.
- Implement plugin-contributed UI and backend/CLI locale packs (contributes.locales, LocalizedText extra tags, validation, runtime overlay, and PopupSelect language picker).
- Move kernel-irqchip and Windows processor scheduling controls into VM Compute > Performance settings, hide Plugins settings gear for VM-only schemas, and align locked system plugin switches.
2026-11-29 10:32:11 -07:00

78 lines
3.1 KiB
TypeScript

import { ArrowDownToLine, RotateCw, X } from 'lucide-react'
import React from 'react'
import { I18nKey, t } from '../i18n'
import { Locale, Task } from '../types'
import { Tip } from '../ui/controls'
/** Where an available update is: offered, downloading, verified and ready, or failed. */
export type UpdatePhase = 'none' | 'available' | 'downloading' | 'ready' | 'failed'
interface Props {
locale: Locale
phase: UpdatePhase
latest: string
task?: Task | null
/** Opens the About page with the full update details. */
onOpen: () => void
onDownload: () => void
onCancel: () => void
onInstall: () => void
/** Hides the card until the next release ("remind me later"). */
onDismiss: () => void
}
/** Capsule card under the sidebar brand: the update's state and one action. */
export const UpdateCapsule: React.FC<Props> = ({
locale, phase, latest, task, onOpen, onDownload, onCancel, onInstall, onDismiss,
}) => {
if (phase === 'none') return null
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
const pct = task && task.percent >= 0 ? Math.round(task.percent) : null
let title: string
let action: React.ReactNode = null
let close: React.ReactNode = null
if (phase === 'downloading') {
title = pct === null ? tr('updateCapsuleDownloading') : tr('updateCapsuleDownloadingPct', { p: pct })
close = (
<Tip label={tr('updateCancel')} side="right">
<button type="button" className="update-capsule-x" aria-label={tr('updateCancel')} onClick={onCancel}><X size={12} /></button>
</Tip>
)
} else if (phase === 'ready') {
title = tr('updateCapsuleReady', { v: latest })
action = <button type="button" className="update-capsule-btn is-primary" onClick={onInstall}>{tr('updateRestart')}</button>
} else if (phase === 'failed') {
title = tr('updateCapsuleFailed')
action = (
<button type="button" className="update-capsule-btn" onClick={onDownload}>
<RotateCw size={11} aria-hidden="true" />{tr('updateRetry')}
</button>
)
} else {
title = tr('updateCapsuleAvailable', { v: latest })
action = <button type="button" className="update-capsule-btn" onClick={onDownload}>{tr('updateDownload')}</button>
close = (
<Tip label={tr('updateLater')} side="right">
<button type="button" className="update-capsule-x" aria-label={tr('updateLater')} onClick={onDismiss}><X size={12} /></button>
</Tip>
)
}
return (
<div className={`update-capsule is-${phase}`} role="status">
<button type="button" className="update-capsule-main" onClick={onOpen} title={tr('updateCapsuleOpen')}>
<span className="update-capsule-icon" aria-hidden="true"><ArrowDownToLine size={12} /></span>
<span className="update-capsule-title">{title}</span>
</button>
{action}
{close}
{phase === 'downloading' && (
<span className="update-capsule-bar" aria-hidden="true">
<span className={pct === null ? 'is-indeterminate' : ''} style={pct === null ? undefined : { width: `${pct}%` }} />
</span>
)}
</div>
)
}