import { Check, Monitor, Download, LoaderCircle, PackageOpen, RefreshCw, ShieldCheck, Sparkle, X, } from "lucide-react"; import { useI18n } from "../i18n"; import { useUpdateFlow } from "../lib/useUpdate"; import { formatBytes } from "../lib/utils"; interface Props { /** Raw URL of the manifest, so the panel can name the feed it just queried. */ feedUrl: string; autoCheck: boolean; onAutoCheckChange: (enabled: boolean) => void; /** * The host this build is running on. The panel needs it because the update * question is per-operating-system: which artifact the feed will serve, and * whether a download can be installed at all, both follow from it. */ system: UpdateSystemInfo | null; } /** Operating-system facts, read from the same probe the Runtime tab uses. */ export interface UpdateSystemInfo { platform: string; osVersion: string; architecture: string; } /** Rust reports `std::env::consts::ARCH`; the channel names the same thing differently. */ function architectureLabel(arch: string): string { if (arch === "aarch64") return "ARM64"; if (arch === "x86_64") return "x64"; return arch; } /** * Update channel backed by the git repository itself: the release branch carries * the installers plus a manifest of SHA256 hashes, and this panel is the only * place a download can be trusted. A hash mismatch is shown as an error and the * file is deleted, so a half-good download can never be launched. */ export function UpdatePanel({ feedUrl, autoCheck, onAutoCheckChange, system }: Props) { const { t } = useI18n(); // One state machine shared with any other view of the channel, driven by the // events Rust already broadcasts, so two views cannot offer different actions. const { status, checking, downloading, installing, progress, percent, check, download, install, clear } = useUpdateFlow(); const verified = status?.state === "ready"; // Rust reports the key it resolved; the panel only repeats it. const artifactKey = status?.artifactKey ?? ""; const available = status?.state === "available" || verified; const failed = status?.state === "error" || status?.state === "unavailable"; return (
{t("updates")}
{t("updateFeed")} {feedUrl || t("updateFeedNone")} {/* Only a status backed by a manifest may claim anything about trust: an errored check has no manifest to have verified. */} {status && status.state !== "error" ? ( {t(status.signed ? "updateSigned" : "updateUnsigned")} ) : null}
{/* Which artifact the feed serves, and whether it can be installed at all, are both decided by the host. Saying it here is what makes an "no artifact for this platform" answer explain itself. */}
{t("updateSystem")} {system ? ( {system.osVersion || system.platform} {architectureLabel(system.architecture)} ) : ( {t("updateSystemPending")} )} {artifactKey ? ( {t("updateSystemArtifact", { key: artifactKey })} ) : status && status.state === "unavailable" ? ( {t("updateSystemArtifactUnknown")} ) : null}
{status?.currentVersion ?? "-"} {available && status ? ( {status.availableVersion} {status.date} ) : null} {status ? t( status.state === "ready" ? "updateReady" : status.state === "available" ? "updateAvailable" : status.state === "current" ? "updateCurrent" : "updateUnavailable", ) : t("updateIdle")}
{status?.notes ?

{status.notes}

: null} {status?.fileName ? (
{status.fileName} {formatBytes(status.size)}
) : null} {percent !== null ? (
{progress ? `${formatBytes(progress.downloaded)} / ${formatBytes(progress.total)}` : ""}
) : null} {status?.sha256 ? ( SHA256 {verified ? status.sha256 : `${status.sha256.slice(0, 16)}…`} ) : null} {status?.message && (failed || verified) ? (
{verified ? t("updateVerified") : status.message}
) : null}
{available && !verified ? ( ) : null} {verified ? ( ) : null} {verified ? ( ) : null}

{t("updateBody")}

); }