import { CalendarDays } from "lucide-react"; import { cn } from "@/components/lib/utils.js"; import { Button } from "@/components/ui/button.js"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog.js"; import { Checkbox } from "@/components/ui/checkbox.js"; import { Progress } from "@/components/ui/progress.js"; import type { IntlInstance } from "@/i18n/IntlProvider.js"; import type { UpdateStatusDialogPhase } from "@/updateStatusModel.js"; const macosDockIconUrl = new URL("../../../public/icon_512@2x.png", import.meta.url).href; type LocalizedUpdateReleaseNotes = { markdown: string; title: string; }; export function UpdateStatusDialog({ displayVersion, edgeToEdge = false, intl, isUpdateActionPending, autoDownloadAndInstallUpdates, onAutoDownloadAndInstallUpdatesChange, onCancelDownload, onDownloadUpdate, onOpenChange, onRestartUpdate, onSkipUpdate, open, phase, progressLabel, progressValue, releaseDateLabel, showOverlay = true, skippableVersion, }: { displayVersion: string; edgeToEdge?: boolean; intl: IntlInstance; isUpdateActionPending: boolean; autoDownloadAndInstallUpdates: boolean; localizedUpdateReleaseNotes: LocalizedUpdateReleaseNotes | null; onAutoDownloadAndInstallUpdatesChange: (enabled: boolean) => Promise; onCancelDownload: () => Promise; onDownloadUpdate: () => Promise; onOpenChange: (open: boolean) => void; onOpenReleaseNotesExternalUrl: (url: string) => void; onRestartUpdate: () => Promise; onSkipUpdate: () => Promise; open: boolean; phase: UpdateStatusDialogPhase; progressLabel: string | null; progressValue: number; releaseDateLabel: string | null; showOverlay?: boolean; skippableVersion: string | null; }) { const isBeforeDownload = phase === "before-download"; const isDownloading = phase === "downloading"; const isDownloaded = phase === "downloaded"; const dialogTitleId = isDownloaded ? "updateDialog.readyTitle" : isDownloading ? "updateDialog.downloadingTitle" : "updateDialog.availableTitle"; const titleParts = getDialogTitleParts({ displayVersion, intl, titleId: dialogTitleId, }); const showSkipVersion = isBeforeDownload && Boolean(skippableVersion); const showLaterButton = !isDownloading; const titleClassName = "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-ui-base font-medium leading-5 text-foreground"; const titleContent = ( <> {titleParts.prefix ? {titleParts.prefix} : null} {titleParts.hasVersion ? ( {titleParts.versionText} ) : null} {titleParts.suffix ? {titleParts.suffix} : null} ); const contentClassName = cn( "max-h-[calc(100vh-2rem)] max-w-[calc(100vw-2rem)] overflow-hidden p-5 sm:max-w-lg", edgeToEdge && !isDownloading ? // 普通/下载完成状态没有中间内容,不能继续使用 minmax(0,1fr)。 // 否则 footer 会占满剩余窗口高度,按钮被垂直居中后看起来像中间有大块空白。 "grid-rows-[auto_auto]" : "grid-rows-[auto_minmax(0,1fr)_auto]", edgeToEdge ? // 独立更新窗口已经由 BrowserWindow 提供窗口边框和阴影。 // 这里不能再保留页内 DialogContent 的边框、阴影和视口边距,否则会出现“窗中窗”。 "grid h-dvh max-h-none w-dvw max-w-none gap-5 border-0 bg-popover/98 pt-10 text-ui-base/relaxed text-foreground shadow-none sm:max-w-none [app-region:drag]" : "gap-5", ); const content = ( <>
{edgeToEdge ? (

{titleContent}

) : ( {titleContent} )} {releaseDateLabel ? (
) : null}
{isDownloading ? (
{intl.formatMessage({ id: "updateDialog.downloadProgress" })} {progressLabel ? ( {progressLabel} ) : null}
) : null}
{isBeforeDownload ? ( ) : null} {showSkipVersion ? (
) : null}
{showLaterButton ? ( ) : null} {isDownloaded ? ( ) : isDownloading ? ( ) : ( )}
); if (edgeToEdge) { if (!open) { return null; } return (
{content}
); } return ( {content} ); } function getDialogTitleParts({ displayVersion, intl, titleId, }: { displayVersion: string; intl: IntlInstance; titleId: string; }) { const marker = "__ZCODE_UPDATE_VERSION__"; const text = intl.formatMessage({ id: titleId }, { version: marker }); const index = text.indexOf(marker); const rawPrefix = index >= 0 ? text.slice(0, index) : ""; const versionPrefix = rawPrefix.endsWith("v") ? "v" : ""; const prefix = (versionPrefix ? rawPrefix.slice(0, -versionPrefix.length) : rawPrefix).trim(); return { hasVersion: index >= 0, prefix, suffix: index >= 0 ? text.slice(index + marker.length).trim() : text.trim(), versionText: `${versionPrefix}${displayVersion}`, }; }