import { Cpu, HardDrive, MemoryStick, Plus, RefreshCw, ShieldCheck, Trash } from 'lucide-react' import React, { useEffect, useState } from 'react' import '../i18n/domains/settings.gen' import '../i18n/domains/wizard.gen' import { I18nKey, t } from '../i18n' import { formatBytes, gpuCompatHint, gpuKey, gpuMetaLine, sameGPU } from '../lib/format' import { AppState, Locale, StorageBreakdown, Task } from '../types' import { Button, IconButton } from '../ui/controls' import { api } from '../wails' import { RuntimeOnline } from './RuntimeOnline' interface Props { state: AppState locale: Locale onRefresh: () => void onNewVM?: () => void onError: (title: string, e: unknown) => void onToast?: (title: string) => void runtimeTask: Task | null onChannel: (alpha: boolean) => void onInstallRuntime: (commit: string) => void onCancelTask: (id: string) => void } export const HostView: React.FC = ({ state, locale, onRefresh, onNewVM, onError, onToast, runtimeTask, onChannel, onInstallRuntime, onCancelTask }) => { const [importing, setImporting] = useState(false) const [enabling, setEnabling] = useState(false) const [confirmDelete, setConfirmDelete] = useState('') const [removing, setRemoving] = useState('') const [storage, setStorage] = useState(null) const { host, config, runtimes } = state const tr = (k: I18nKey, v?: Record) => t(locale, k, v) useEffect(() => { let live = true api.GetStorageBreakdown().then((s) => { if (live) setStorage(s) }).catch((e) => console.warn('[host] GetStorageBreakdown failed:', e)) return () => { live = false } }, [state.config.data_root, state.vms?.length, state.runtimes?.length]) const whpx = { ready: { short: tr('whpxReady'), hint: '', tone: 'ok' }, no_hypervisor: { short: tr('whpxNoHvShort'), hint: tr('whpxNoHv'), tone: 'warn' }, missing: { short: tr('whpxMissingShort'), hint: tr('whpxMissing'), tone: 'warn' }, unsupported: { short: tr('whpxUnsupportedShort'), hint: tr('whpxUnsupported'), tone: 'warn' }, }[host.whpx] ?? { short: host.whpx, hint: '', tone: 'warn' } const guard = (fn: () => Promise) => async () => { try { await fn() onRefresh() } catch (e) { onError(tr('failGeneric'), e) } } const enableWHPX = async () => { setEnabling(true) await guard(() => api.EnableWHPX())() setEnabling(false) } const importRuntime = async () => { setImporting(true) await guard(async () => { const file = await api.PickFile(tr('importRuntime'), '*.tar.zst;*.zip') if (file) await api.InstallRuntimeArchive(file) })() setImporting(false) } const removeRuntime = async (commit: string) => { setRemoving(commit) try { await api.RemoveRuntime(commit) setConfirmDelete('') onToast?.(tr('runtimeDeleted', { commit })) onRefresh() } catch (e) { onError(tr('failDelete'), e) } finally { setRemoving('') } } const gpuKind = (k: string) => tr(k === 'discrete' ? 'gpuDiscrete' : k === 'integrated' ? 'gpuIntegrated' : k === 'virtual' ? 'gpuVirtual' : 'gpuUnknown') const realGPUs = (host.gpus ?? []).filter((g) => g.kind !== 'virtual') return (

{tr('sidebarHost')}

} onClick={onRefresh} />
{(state.vms?.length ?? 0) === 0 && host.whpx === 'ready' && !!state.active_runtime && onNewVM && (

{tr('welcomeTitle')}

{tr('welcomeSub')}

)}
{tr('whpxTitle')}
{whpx.short}
{host.whpx === 'missing' ? ( ) : whpx.hint ? (
{whpx.hint}
) : null}
{tr('hostCPU')}
{tr('hostCoresThreads', { c: host.physical_cores, t: host.logical_cpus })}
{host.p_core_count > 0 && host.e_core_count > 0 && (
{host.p_core_count}P + {host.e_core_count}E
)}
{tr('hostRAM')}
{tr('hostRAMAvail', { n: host.avail_ram_gb.toFixed(1) })}
{tr('hostRAMTotal', { n: host.total_ram_gb.toFixed(1) })} {host.memory_spec?.speed_mhz ? ` · ${host.memory_spec.speed_mhz} MHz${host.memory_spec.type_name ? ` ${host.memory_spec.type_name}` : ''}` : ''}
{tr('hostDisk')}
{host.free_disk_gb.toFixed(0)} GB
{storage && storage.total_bytes > 0 && (() => { const tot = Math.max(storage.total_bytes, 1) const vmsPct = (storage.vms_bytes / tot) * 100 const instPct = (storage.installers_bytes / tot) * 100 const rtPct = (storage.runtimes_bytes / tot) * 100 return (
{tr('storageBreakdownTitle')} {formatBytes(storage.total_bytes, locale)}
) })()}
{tr('hostRuntime')}
{(runtimes ?? []).filter((rt) => !rt.active).map((rt) => (
{rt.commit}
{rt.manifest.qemu_version.replace(/^QEMU emulator version\s*/i, 'QEMU ')}
{confirmDelete === rt.commit ? ( <> ) : ( <> } disabled={removing !== ''} onClick={() => setConfirmDelete(rt.commit)} /> )}
))}
{tr('hostGPUs')}
{realGPUs.length === 0 ? (
—
) : ( realGPUs.map((g, idx) => { const meta = gpuMetaLine(g) const hint = gpuCompatHint(locale, g) const isRec = sameGPU(host.recommended_gpu, g) return (
{g.name} {gpuKind(g.kind)} {g.compat === 'unsupported' && {tr('gpuCompatUnsupported')}} {g.compat === 'warn' && {tr('gpuCompatWarn')}} {isRec && g.compat !== 'warn' && g.compat !== 'unsupported' && {tr('gpuRecommended')}}
{meta &&
{meta}
} {hint &&
{hint}
}
) }) )}
{(host.displays?.length ?? 0) > 0 && (
{tr('hostDisplays')}
{(host.displays ?? []).map((d, idx) => (
{d.width} × {d.height} {d.refresh_hz ? ` @ ${d.refresh_hz}Hz` : ''} {d.scale_pct || 100}% {d.primary && {tr('hostDisplayPrimary')}}
))}
)}
) }