import { AppWindow, ArrowRight, Boxes, ChevronRight, CircuitBoard, CircleGauge, Cpu, HardDrive, MemoryStick, MonitorCog, ScanSearch, Sparkles, WandSparkles, Waypoints, } from "lucide-react"; import type { ReactNode } from "react"; import { useI18n } from "../i18n"; import { formatBytes, formatCount, formatMemory, percent } from "../lib/format"; import type { Bootstrap, SystemSnapshot, Volume } from "../types"; import type { ScanWorkspace } from "../hooks/useScanWorkspace"; import type { PageId } from "../types"; import { CategorySummary } from "../components/CleanupView"; import { Button, PageHeader, ProgressCard, SectionTitle, UsageBar, } from "../components/ui"; function greeting(lang: "zh" | "en"): string { const hour = new Date().getHours(); if (lang === "zh") { if (hour < 6) return "夜深了"; if (hour < 12) return "早上好"; if (hour < 18) return "下午好"; return "晚上好"; } if (hour < 12) return "Good morning"; if (hour < 18) return "Good afternoon"; return "Good evening"; } /// Windows mounts read `C:\`; everything else shows its own label. function driveLabel(volume: Volume): string { return /^[A-Za-z]:/.exec(volume.mount_point)?.[0] ?? volume.mount_point; } function SpecRow({ icon, label, value, t, }: { icon: ReactNode; label: string; value: string; t: (en: string, zh: string) => string; }) { return (
{icon} {label} {value || t("—", "—")}
); } export function OverviewPage({ bootstrap, snapshot, cleanup, purge, onNavigate, }: { bootstrap: Bootstrap; snapshot: SystemSnapshot | null; cleanup: ScanWorkspace; purge: ScanWorkspace; onNavigate: (page: PageId) => void; }) { const { t, lang } = useI18n(); const volumes = snapshot?.volumes ?? []; const rootVolume = volumes.find((candidate) => candidate.is_root) ?? volumes[0] ?? null; const memoryInstalled = snapshot ? Math.max(snapshot.memory.installed, snapshot.memory.total) : 0; const memoryReserved = snapshot ? Math.max(0, memoryInstalled - snapshot.memory.total) : 0; const scanned = Boolean(cleanup.result || purge.result); const scanning = cleanup.scanning || purge.scanning; const found = [cleanup, purge].reduce( (sum, workspace) => sum + (workspace.result ? workspace.result.items .filter((item) => !item.lock) .reduce((total, item) => total + item.onDisk, 0) : 0), 0, ); // 智能扫描 lives on the 空间清理 page now; the workspaces are app-level so // kicking both stages from here simply continues on that page. It uses the // default deep-scan settings — tweak them there and re-scan if needed. const smartScan = () => { if (!scanned) { void cleanup.runScan().then(() => purge.runScan({ // Empty = engine auto-discovery of project containers. roots: [], minAgeDays: bootstrap.settings.purgeMinAgeDays || 7, force: false, }), ); } onNavigate("space"); }; const hardware = bootstrap.hardwareInfo; const ramBrands = [ ...new Set(hardware.memory_sticks.map((stick) => stick.manufacturer).filter(Boolean)), ].join(" / "); const ramSpeed = hardware.memory_sticks.reduce( (top, stick) => Math.max(top, stick.speed_mhz), 0, ); const specs = { os: bootstrap.osVersion, board: hardware.board || bootstrap.hardware, cpu: snapshot ? `${snapshot.cpu.brand} · ${snapshot.cpu.physical_cores} ${t("cores", "核")} / ${ snapshot.cpu.logical_cores } ${t("threads", "线程")}` : hardware.cpu_model, memory: [ memoryInstalled ? formatMemory(memoryInstalled) : "", ramBrands, ramSpeed ? `${ramSpeed} MT/s` : "", ] .filter(Boolean) .join(" · ") || (memoryReserved ? formatMemory(memoryInstalled) : ""), disk: [ [hardware.disk_vendor, hardware.disk_model].filter(Boolean).join(" "), hardware.disk_size_bytes ? formatBytes(hardware.disk_size_bytes) : "", hardware.disk_bus, ] .filter(Boolean) .join(" · "), gpu: [ hardware.gpu_model && hardware.gpu_model.toLowerCase().startsWith(hardware.gpu_vendor.toLowerCase()) ? hardware.gpu_model : [hardware.gpu_vendor, hardware.gpu_model].filter(Boolean).join(" "), hardware.gpu_vram_bytes ? formatBytes(hardware.gpu_vram_bytes) : "", ] .filter(Boolean) .join(" · "), }; return (
} onClick={smartScan} disabled={scanning} > {scanned ? t("Review scan", "查看扫描结果") : t("Smart scan", "智能扫描")} } />
{t("Smart Care", "智能维护")}

{scanned ? t( `${formatBytes(found)} found safely.`, `安全发现 ${formatBytes(found)} 可清理空间。`, ) : t("A lighter, faster machine.", "更轻盈,更顺畅。")}

{scanned ? t( "Review each category before anything is removed. Locked files stay untouched.", "清理前可逐项检查,锁定文件始终不会被处理。", ) : t( "Squid looks for rebuildable caches, old logs and build leftovers without touching your documents.", "Squid 会查找可重建的缓存、旧日志与构建残留,不会触碰您的文档。", )}

{t("Local only", "仅在本地")} {t("Policy checked", "安全策略校验")} {t("Undo available", "支持还原")}
{t("This machine", "本机配置")} } label={t("System", "操作系统")} value={specs.os} t={t} /> } label={t("Motherboard", "主板")} value={specs.board} t={t} /> } label={t("Processor", "处理器")} value={specs.cpu} t={t} /> } label={t("Memory", "内存")} value={specs.memory} t={t} /> } label={t("Primary disk", "主硬盘")} value={specs.disk} t={t} /> } label={t("Graphics", "显卡")} value={specs.gpu} t={t} />
{scanning ? ( void (cleanup.scanning ? cleanup.cancel() : purge.cancel())} /> ) : null} {scanned && !scanning ? (
onNavigate("space")}> {t("Open space cleaning", "打开空间清理")} } /> {cleanup.result ? ( onNavigate("space")} /> ) : null}
) : null}
{t("Processor", "处理器")} {snapshot ? `${snapshot.cpu.physical_cores} ${t("cores", "核")} / ${snapshot.cpu.logical_cores} ${t("threads", "线程")}` : t("Sampling…", "正在采样…")}
{Math.round(snapshot?.cpu.total ?? 0)}%
{snapshot?.cpu.brand || t("Processor details unavailable", "暂无处理器信息")}
{t("Memory", "内存")} {snapshot ? `${formatMemory(snapshot.memory.used)} / ${formatMemory(memoryInstalled)}` : t("Sampling…", "正在采样…")}
{Math.round( snapshot ? percent(snapshot.memory.used, snapshot.memory.total) : 0, )} %
{memoryReserved > 0 ? t( `Hardware reserved (integrated graphics): ${formatMemory(memoryReserved)}`, `硬件保留(含核显):${formatMemory(memoryReserved)}`, ) : snapshot ? t( `${formatCount(snapshot.processes)} processes running`, `${formatCount(snapshot.processes)} 个进程正在运行`, ) : t("Reading activity", "正在读取活动")}
{t("Storage", "存储空间")} {volumes.length > 0 ? t( `${volumes.length} drives`, `${volumes.length} 个分区`, ) : t("Reading volumes…", "正在读取磁盘…")}
{volumes.slice(0, 4).map((volume) => { const usedPercent = percent(volume.total - volume.free, volume.total); return (
{driveLabel(volume)} {volume.name && volume.name !== driveLabel(volume) ? ` · ${volume.name}` : ""} {Math.round(usedPercent)}% {t( `total ${formatBytes(volume.total)} · ${formatBytes(volume.free)} free`, `总 ${formatBytes(volume.total)} · 可用 ${formatBytes(volume.free)}`, )}
85 ? "red" : "green"} />
); })}
); }