import { Check, Download, LoaderCircle, Monitor, PackageOpen, RefreshCw, Rss, 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; /** Version of the copy the user is looking at, so the header needs no check. */ appVersion: 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, installError, progress, percent, check, download, install, clear, } = useUpdateFlow(); const verified = status?.state === "ready"; const available = status?.state === "available" || verified; const failed = status?.state === "error" || status?.state === "unavailable"; return (
{/* The two facts an update answer has to be read against come first: which machine and which Shift version is asking, then where updates come from. Both precede the Updates heading so a screenshot of this panel already says what was upgraded and from where. */}
{t("updateSystem")} {system ? ( {system.osVersion || system.platform} {architectureLabel(system.architecture)} Shift {system.appVersion} ) : ( {t("updateSystemPending")} )}
{t("updateFeed")} {/* 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} {feedUrl || t("updateFeedNone")}
{t("updates")}
{status ? t( status.state === "ready" ? "updateReady" : status.state === "available" ? "updateAvailable" : status.state === "current" ? "updateCurrent" : "updateUnavailable", ) : t("updateIdle")} {available && status ? ( {status.availableVersion} {status.date} ) : null}
{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} {/* An install that could not run leaves the verified download in place, so it is reported beside the button instead of rewriting the status. */} {installError ? (
{installError}
) : null}
{available && !verified ? ( ) : null} {verified ? ( ) : null} {/* An install is a countdown to this process exiting, so the row drops the choice that only resets what is already decided. */} {verified && !installing ? ( ) : null}

{t("updateBody")}

); }