892 lines
35 KiB
TypeScript
892 lines
35 KiB
TypeScript
import { Check, ChevronRight, CircleAlert, CircleCheck, CloudDownload, Copy, Disc3, HardDrive, LucideIcon, Package } from 'lucide-react'
|
||
import React, { Suspense, lazy, useEffect, useState } from 'react'
|
||
import '../i18n/domains/wizard.gen'
|
||
import '../i18n/domains/settings.gen'
|
||
import { I18nKey, locText, parseAppError, t } from '../i18n'
|
||
import {
|
||
GUEST_LANG_PRESETS,
|
||
guestLangOptions,
|
||
MEMORY_MARKS,
|
||
controllerLabel,
|
||
defaultGuestLang,
|
||
findGPU,
|
||
formatMemory,
|
||
gpuCompatHint,
|
||
gpuLabel,
|
||
gpuOptionValue,
|
||
guestLangLabel,
|
||
memorySafeLimitGB,
|
||
parseMemoryGB,
|
||
recommendedCPUs,
|
||
canKeepDisplayPreset,
|
||
fullscreenDisplayPresets,
|
||
FullscreenDisplayPreset,
|
||
hidpiLooksLike,
|
||
hostDisplayAdvice,
|
||
hostDisplayDesc,
|
||
windowDisplayPresets,
|
||
recommendedMemoryGB,
|
||
recommendedResolution,
|
||
shortGPUName,
|
||
splitLangLabel,
|
||
sshCommand,
|
||
} from '../lib/format'
|
||
import { CachedInstaller, CreateOpts, DriverSummary, HostReport, Locale, Release, Task, ValidationIssue } from '../types'
|
||
import { findActiveOfflineTask, taskInstallerPhase } from '../lib/tasks'
|
||
import { Button, IconButton } from '../ui/controls'
|
||
import { NumberField, PopupSelect, RangeField, Segmented, SetGroup, SetRow, Switch } from '../ui/settings'
|
||
import { Modal } from '../ui/dialog'
|
||
import { api } from '../wails'
|
||
|
||
const SchemaForm = lazy(() => import('./SchemaForm').then((m) => ({ default: m.SchemaForm })))
|
||
const BUILTIN_MACOS_DRIVER = 'builtin.driver.reims-macos'
|
||
|
||
/** Reopen the wizard where the user left it (e.g. after a failed create). */
|
||
export interface WizardDraft {
|
||
opts: CreateOpts
|
||
step: number
|
||
}
|
||
|
||
interface Props {
|
||
locale: Locale
|
||
host: HostReport
|
||
fixedModeSupported?: boolean
|
||
tasks?: Task[]
|
||
draft?: WizardDraft | null
|
||
onClose: () => void
|
||
/** Called with the cleaned payload; the caller runs the create in the background. */
|
||
onSubmit: (payload: CreateOpts, draft: WizardDraft) => void
|
||
}
|
||
|
||
const REVIEW_STEP = 5
|
||
|
||
// Which wizard step owns each ValidationIssue.field (internal/macos/reims/reims.go ValidateCreate).
|
||
const STEP_OF_FIELD: Record<string, number> = {
|
||
installer: 1, disk: 1, macos: 1, guest_lang: 1,
|
||
cpus: 2, memory: 2,
|
||
disk_size: 3, disk_controller: 3,
|
||
graphics: 4, gpu: 4, resolution: 4, displays: 4, ssh_port: 4,
|
||
}
|
||
const stepOfIssue = (i: ValidationIssue) => STEP_OF_FIELD[i.field] ?? REVIEW_STEP
|
||
|
||
// Step ① as large cards, one per way to get macOS (Parallels / UTM style).
|
||
const SOURCES: { mode: 'offline' | 'apple' | 'installer' | 'disk'; icon: LucideIcon; title: I18nKey; sub: I18nKey }[] = [
|
||
{ mode: 'offline', icon: Package, title: 'srcOfflineTitle', sub: 'srcOfflineSub' },
|
||
{ mode: 'apple', icon: CloudDownload, title: 'srcAppleTitle', sub: 'srcAppleSub' },
|
||
{ mode: 'installer', icon: Disc3, title: 'srcInstallerTitle', sub: 'srcInstallerSub' },
|
||
{ mode: 'disk', icon: HardDrive, title: 'srcDiskTitle', sub: 'srcDiskSub' },
|
||
]
|
||
|
||
export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported = false, tasks = [], draft, onClose, onSubmit }) => {
|
||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||
const [step, setStep] = useState(draft?.step ?? 1)
|
||
// Once the user has reached the review step, keep validating so step markers stay current.
|
||
const [reviewed, setReviewed] = useState(draft?.step === REVIEW_STEP)
|
||
const [checking, setChecking] = useState(false)
|
||
const [err, setErr] = useState('')
|
||
const [issues, setIssues] = useState<ValidationIssue[]>([])
|
||
const [cmdPreview, setCmdPreview] = useState('')
|
||
const [drivers, setDrivers] = useState<DriverSummary[]>([])
|
||
const [driverID, setDriverID] = useState(BUILTIN_MACOS_DRIVER)
|
||
const [driverOpts, setDriverOpts] = useState<Record<string, unknown>>({})
|
||
const [driverCreating, setDriverCreating] = useState(false)
|
||
|
||
useEffect(() => {
|
||
let live = true
|
||
api.ListDrivers().then((list) => { if (live) setDrivers(list ?? []) }).catch((e) => console.warn('[wizard] ListDrivers failed:', e))
|
||
return () => { live = false }
|
||
}, [])
|
||
const activeDriver = drivers.find((d) => d.id === driverID)
|
||
const isCustomDriver = driverID !== BUILTIN_MACOS_DRIVER && !!activeDriver
|
||
|
||
const [opts, setOpts] = useState<CreateOpts>(draft?.opts ?? {
|
||
name: 'macos-tahoe',
|
||
dir: '',
|
||
// Offline by default: installs an exact release without guest network access
|
||
// (`reims-ctl create --help`, upstream 3731afd).
|
||
source_mode: 'offline',
|
||
macos: '',
|
||
offline: true,
|
||
installer: '',
|
||
cpus: recommendedCPUs(host),
|
||
memory: `${recommendedMemoryGB(host)}G`,
|
||
disk_size: '128G',
|
||
disk: '',
|
||
disk_mode: 'copy',
|
||
disk_controller: 'nvme',
|
||
graphics: host.recommended_gpu ? 'reims-vgpu' : 'vmware-svga',
|
||
// Default to "auto" rather than a DriverStore FileRepository ICD path so
|
||
// Windows GPU driver updates never break existing VM configs.
|
||
gpu: 'auto',
|
||
resolution: recommendedResolution(host),
|
||
displays: 1,
|
||
borderless: false,
|
||
capture: false,
|
||
audio: true,
|
||
network: false,
|
||
ssh_port: 0,
|
||
logs: true,
|
||
guest_lang: defaultGuestLang(locale),
|
||
start: true,
|
||
})
|
||
const set = (patch: Partial<CreateOpts>) => setOpts((o) => ({ ...o, ...patch }))
|
||
const windowPresets = windowDisplayPresets(host, fixedModeSupported)
|
||
const fullscreenPresets = fullscreenDisplayPresets(host)
|
||
|
||
const buildPayload = (): CreateOpts => {
|
||
const p: CreateOpts = { ...opts, offline: opts.source_mode === 'offline' }
|
||
if (p.source_mode === 'offline') {
|
||
p.installer = ''
|
||
p.disk = ''
|
||
} else if (p.source_mode === 'apple') {
|
||
p.installer = ''
|
||
p.disk = ''
|
||
} else if (p.source_mode === 'installer') {
|
||
p.macos = ''
|
||
p.disk = ''
|
||
} else {
|
||
p.macos = ''
|
||
p.installer = ''
|
||
p.disk_size = ''
|
||
}
|
||
return p
|
||
}
|
||
|
||
useEffect(() => {
|
||
if (step === REVIEW_STEP) setReviewed(true)
|
||
}, [step])
|
||
|
||
// Offline releases come from Apple's catalog (a few seconds); downloaded ones are marked.
|
||
const [releases, setReleases] = useState<Release[] | null>(null)
|
||
const [cached, setCached] = useState<CachedInstaller[]>([])
|
||
const [releasesErr, setReleasesErr] = useState('')
|
||
useEffect(() => {
|
||
if (opts.source_mode !== 'offline' || releases) return
|
||
let live = true
|
||
api.ListInstallers().then((l) => { if (live) setCached(l ?? []) }).catch((e) => console.warn('[wizard] ListInstallers failed:', e))
|
||
api.ListOfflineReleases()
|
||
.then((list) => {
|
||
if (!live) return
|
||
setReleases(list ?? [])
|
||
if (!opts.macos && list && list.length > 0) set({ macos: list[0].version })
|
||
})
|
||
.catch((e) => { if (live) setReleasesErr(String(e).replace(/^Error:\s*/, '')) })
|
||
return () => { live = false }
|
||
}, [opts.source_mode])
|
||
const isCached = (v: string) => cached.some((c) => c.kind === 'offline' && !c.partial && c.version === v)
|
||
const activeRelease = (v: string) => findActiveOfflineTask(tasks, v)
|
||
const chosenRelease = releases?.find((r) => r.version === opts.macos)
|
||
// reims-util pre-allocates the whole image as it starts (19.7 GB for an 18.4 GB release, measured).
|
||
const needGB = chosenRelease && !isCached(chosenRelease.version) && !activeRelease(chosenRelease.version)
|
||
? Math.ceil((chosenRelease.size * 1.1) / 1e9)
|
||
: 0
|
||
|
||
useEffect(() => {
|
||
if (!reviewed && step !== REVIEW_STEP) return
|
||
let live = true
|
||
setChecking(true)
|
||
const timer = setTimeout(() => {
|
||
const payload = buildPayload()
|
||
Promise.all([api.ValidateCreate(payload), api.PreviewCreate(payload)])
|
||
.then(([iss, cmd]) => {
|
||
if (!live) return
|
||
setIssues(iss ?? [])
|
||
setCmdPreview(cmd)
|
||
setErr('')
|
||
})
|
||
.catch((e) => { if (live) setErr(parseAppError(e).summary) })
|
||
.finally(() => { if (live) setChecking(false) })
|
||
}, 200)
|
||
return () => { live = false; clearTimeout(timer) }
|
||
}, [step, reviewed, opts])
|
||
|
||
const pickDir = async () => {
|
||
const dir = await api.PickDirectory(tr('vmDir'))
|
||
if (dir) set({ dir })
|
||
}
|
||
|
||
const pickFile = async (field: 'installer' | 'disk', pattern: string) => {
|
||
const f = await api.PickFile(tr(field === 'installer' ? 'sourceInstaller' : 'sourceDisk'), pattern)
|
||
if (f) set({ [field]: f })
|
||
}
|
||
|
||
const handleCreate = () => onSubmit(buildPayload(), { opts, step: REVIEW_STEP })
|
||
const issueSteps = new Set(reviewed ? issues.map(stepOfIssue) : [])
|
||
|
||
const realGPUs = (host.gpus ?? []).filter((g) => g.kind !== 'virtual')
|
||
const selectedGPU = findGPU(host, opts.gpu)
|
||
const selectedGPUHint = gpuCompatHint(locale, selectedGPU)
|
||
const threads = Math.max(host.logical_cpus || 0, 1)
|
||
const cpuRec = recommendedCPUs(host)
|
||
const memRec = recommendedMemoryGB(host)
|
||
const memSafe = memorySafeLimitGB(host)
|
||
const memMax = Math.max(Math.floor((host.total_ram_gb || 16) * 0.85), memRec, 4)
|
||
const memGB = Math.round(parseMemoryGB(opts.memory) ?? memRec)
|
||
const steps: I18nKey[] = ['step1', 'step2', 'step3', 'step4', 'step5']
|
||
|
||
|
||
return (
|
||
<Modal className="wizard-dialog" title={tr('wizardTitle')} closeLabel={tr('close')} onClose={onClose}>
|
||
<nav className="wizard-steps" aria-label={tr('wizardTitle')}>
|
||
{steps.map((key, idx) => {
|
||
const n = idx + 1
|
||
const bad = issueSteps.has(n) && n !== REVIEW_STEP
|
||
const done = !bad && (step > n || (reviewed && n < REVIEW_STEP))
|
||
return (
|
||
<button
|
||
key={key}
|
||
type="button"
|
||
className={`wizard-step${done ? ' done' : ''}${bad ? ' has-issue' : ''}`}
|
||
aria-current={step === n ? 'step' : undefined}
|
||
onClick={() => setStep(n)}
|
||
>
|
||
{bad ? <CircleAlert size={12} /> : done && <Check size={12} />}
|
||
{tr(key)}
|
||
</button>
|
||
)
|
||
})}
|
||
</nav>
|
||
|
||
<div className="dialog-body">
|
||
{err && <div className="notice notice-error">{err}</div>}
|
||
|
||
<div key={step} className="step-anim">
|
||
{step === 1 && (
|
||
<>
|
||
{drivers.length > 1 && (
|
||
<SetGroup title={tr('wizardDriverGroup')}>
|
||
<SetRow
|
||
title={tr('wizardDriverType')}
|
||
control={
|
||
<PopupSelect
|
||
label={tr('wizardDriverType')}
|
||
value={driverID}
|
||
options={drivers.map((d) => ({
|
||
value: d.id,
|
||
label: locText(d.name, locale, d.id),
|
||
}))}
|
||
onChange={(id) => { setDriverID(id); setErr('') }}
|
||
/>
|
||
}
|
||
/>
|
||
</SetGroup>
|
||
)}
|
||
{isCustomDriver ? (
|
||
<div className="stack-3">
|
||
<SetGroup title={tr('wizardBasics')}>
|
||
<SetRow
|
||
title={tr('vmName')}
|
||
control={<input className="input rg-p-input" value={opts.name} onChange={(e) => set({ name: e.target.value })} />}
|
||
/>
|
||
</SetGroup>
|
||
{activeDriver.create_schema && (
|
||
<Suspense fallback={null}>
|
||
<SchemaForm
|
||
locale={locale}
|
||
schema={activeDriver.create_schema}
|
||
values={driverOpts}
|
||
onChange={setDriverOpts}
|
||
/>
|
||
</Suspense>
|
||
)}
|
||
</div>
|
||
) : (
|
||
<>
|
||
<div className="source-cards" role="radiogroup" aria-label={tr('step1')}>
|
||
{SOURCES.map((s) => {
|
||
const Icon = s.icon
|
||
const on = opts.source_mode === s.mode
|
||
return (
|
||
<label key={s.mode} className="source-card" data-selected={on || undefined}>
|
||
<input
|
||
type="radio"
|
||
name="source"
|
||
checked={on}
|
||
onChange={() => set({
|
||
source_mode: s.mode,
|
||
network: s.mode !== 'offline',
|
||
...(s.mode === 'apple' ? { macos: 'tahoe' } : {}),
|
||
...(s.mode === 'offline' ? { macos: releases?.[0]?.version ?? '' } : {}),
|
||
})}
|
||
/>
|
||
<span className={`source-icon source-icon-${s.mode}`} aria-hidden="true"><Icon size={20} /></span>
|
||
<span className="source-title">
|
||
{tr(s.title)}
|
||
{s.mode === 'offline' && <span className="badge rg-p-badge badge-accent">{tr('recommendedBadge')}</span>}
|
||
</span>
|
||
<span className="source-sub">{tr(s.sub)}</span>
|
||
</label>
|
||
)
|
||
})}
|
||
</div>
|
||
<div className="rg-slot-anchor" data-rg-slot="create.source" />
|
||
|
||
<SetGroup>
|
||
{opts.source_mode === 'apple' && (
|
||
<SetRow
|
||
title={tr('macosVersion')}
|
||
control={<PopupSelect id="vm-macos" label={tr('macosVersion')} value={opts.macos} onChange={(macos) => set({ macos })} options={[{ value: 'tahoe', label: 'macOS Tahoe' }]} />}
|
||
/>
|
||
)}
|
||
{opts.source_mode === 'offline' && (
|
||
<SetRow
|
||
title={tr('macosVersion')}
|
||
desc={releasesErr
|
||
? <span className="warn-text">{tr('offlineListFailedDetail', { err: releasesErr })}</span>
|
||
: needGB > 0 && host.free_disk_gb > 0 && host.free_disk_gb < needGB + 10
|
||
? <span className="warn-text">{tr('offlineSpaceWarn', { free: host.free_disk_gb.toFixed(0), need: needGB })}</span>
|
||
: tr('offlineHint')}
|
||
control={!releases
|
||
? <span className="muted">{releasesErr ? '—' : tr('offlineLoading')}</span>
|
||
: (
|
||
<PopupSelect
|
||
id="vm-release"
|
||
label={tr('macosVersion')}
|
||
value={opts.macos}
|
||
onChange={(macos) => set({ macos })}
|
||
options={releases.map((r) => {
|
||
const active = activeRelease(r.version)
|
||
const statusTag = isCached(r.version)
|
||
? tr('offlineCached')
|
||
: active
|
||
? tr(taskInstallerPhase(active.primary) === 'queued' ? 'offlineQueued' : 'offlineDownloading')
|
||
: ''
|
||
return {
|
||
value: r.version,
|
||
label: `macOS ${r.version}`,
|
||
detail: `${(r.size / 1e9).toFixed(1)} GB${statusTag ? ` · ${statusTag}` : ''}`,
|
||
}
|
||
})}
|
||
/>
|
||
)}
|
||
/>
|
||
)}
|
||
{(opts.source_mode === 'installer' || opts.source_mode === 'disk') && (() => {
|
||
const isInstaller = opts.source_mode === 'installer'
|
||
const file = (isInstaller ? opts.installer : opts.disk) ?? ''
|
||
return (
|
||
<SetRow
|
||
title={tr(isInstaller ? 'srcInstallerTitle' : 'srcDiskTitle')}
|
||
desc={file ? <span className="mono path-text" title={file}>{file}</span> : tr('wizNoFile')}
|
||
control={
|
||
<Button onClick={() => (isInstaller
|
||
? pickFile('installer', '*.img;*.dmg')
|
||
: pickFile('disk', '*.qcow2;*.img;*.vmdk;*.raw'))}
|
||
>
|
||
{tr('wizChooseFile')}
|
||
</Button>
|
||
}
|
||
/>
|
||
)
|
||
})()}
|
||
<SetRow
|
||
title={tr('guestLangShort')}
|
||
desc={tr('guestLangHint')}
|
||
control={
|
||
<PopupSelect
|
||
id="vm-guest-lang"
|
||
label={tr('guestLangShort')}
|
||
value={opts.guest_lang || defaultGuestLang(locale)}
|
||
onChange={(guest_lang) => set({ guest_lang })}
|
||
options={guestLangOptions(locale)}
|
||
/>
|
||
}
|
||
/>
|
||
</SetGroup>
|
||
</>
|
||
)}
|
||
</>
|
||
)}
|
||
|
||
{step === 2 && (
|
||
<SetGroup>
|
||
<SetRow
|
||
title={tr('vcpus')}
|
||
desc={(opts.cpus ?? 0) > threads - 2 && threads > 2
|
||
? <span className="warn-text">{tr('cpuOverHint')}</span>
|
||
: tr('cpuRecHint', { rec: cpuRec, n: threads })}
|
||
block={
|
||
<RangeField
|
||
label={tr('vcpus')}
|
||
value={opts.cpus ?? cpuRec}
|
||
min={1}
|
||
max={threads}
|
||
unit={tr('coresUnit')}
|
||
onChange={(cpus) => set({ cpus })}
|
||
recommend={[Math.min(4, cpuRec), cpuRec]}
|
||
warnFrom={threads > 2 ? threads - 1 : undefined}
|
||
marks={[1, 2, 4, 6, 8, 12, 16, 24, 32, 48, 64].concat(threads).map((n) => ({ value: n, label: String(n) }))}
|
||
/>
|
||
}
|
||
/>
|
||
<SetRow
|
||
title={tr('guestMemory')}
|
||
desc={memGB > memSafe
|
||
? <span className="warn-text">{tr('memOverHint')}</span>
|
||
: host.commit_avail_gb > 0
|
||
? tr('memCommitHint', { avail: host.commit_avail_gb.toFixed(1), rec: memRec })
|
||
: tr('memRecHint', { rec: memRec, n: host.total_ram_gb.toFixed(0) })}
|
||
block={
|
||
<RangeField
|
||
label={tr('guestMemory')}
|
||
value={memGB}
|
||
min={2}
|
||
max={memMax}
|
||
unit="GB"
|
||
onChange={(gb) => set({ memory: `${gb}G` })}
|
||
recommend={[Math.min(4, memRec), memRec]}
|
||
warnFrom={memSafe + 1}
|
||
marks={MEMORY_MARKS.concat(memMax).map((n) => ({ value: n, label: String(n) }))}
|
||
/>
|
||
}
|
||
/>
|
||
</SetGroup>
|
||
)}
|
||
|
||
{step === 3 && (
|
||
<SetGroup>
|
||
{opts.source_mode !== 'disk' ? (
|
||
<SetRow
|
||
title={tr('diskSize')}
|
||
desc={tr('diskSizeHint')}
|
||
control={
|
||
<Segmented
|
||
label={tr('diskSize')}
|
||
value={opts.disk_size}
|
||
onChange={(disk_size) => set({ disk_size })}
|
||
options={Array.from(new Set(['64G', '128G', '256G', '512G', opts.disk_size ?? '128G'])).map((v) => ({ value: v, label: formatMemory(v) }))}
|
||
/>
|
||
}
|
||
/>
|
||
) : (
|
||
<SetRow
|
||
title={tr('diskMode')}
|
||
control={
|
||
<Segmented
|
||
label={tr('diskMode')}
|
||
value={opts.disk_mode}
|
||
onChange={(disk_mode) => set({ disk_mode })}
|
||
options={[
|
||
{ value: 'copy' as const, label: tr('diskModeCopy') },
|
||
{ value: 'in-place' as const, label: tr('diskModeInPlace') },
|
||
]}
|
||
/>
|
||
}
|
||
/>
|
||
)}
|
||
<SetRow
|
||
title={tr('diskController')}
|
||
desc={tr('diskControllerNvmeHint')}
|
||
control={
|
||
<Segmented
|
||
label={tr('diskController')}
|
||
value={opts.disk_controller ?? 'nvme'}
|
||
onChange={(disk_controller) => set({ disk_controller })}
|
||
options={[
|
||
{ value: 'nvme' as const, label: 'NVMe' },
|
||
{ value: 'ahci' as const, label: 'SATA' },
|
||
...(opts.source_mode === 'disk' ? [{ value: 'virtio' as const, label: 'VirtIO' }] : []),
|
||
]}
|
||
/>
|
||
}
|
||
/>
|
||
</SetGroup>
|
||
)}
|
||
|
||
{step === 4 && (
|
||
<>
|
||
<SetGroup title={tr('groupGraphics')}>
|
||
<SetRow
|
||
title={tr('graphicsBackend')}
|
||
desc={opts.graphics === 'vmware-svga' ? tr('graphicsSvgaDesc') : tr('graphicsReimsDesc')}
|
||
control={
|
||
<Segmented
|
||
label={tr('graphicsBackend')}
|
||
value={opts.graphics}
|
||
onChange={(graphics) => set({ graphics })}
|
||
options={[
|
||
{ value: 'reims-vgpu' as const, label: tr('graphicsReimsShort') },
|
||
{ value: 'vmware-svga' as const, label: tr('graphicsSvgaShort') },
|
||
]}
|
||
/>
|
||
}
|
||
/>
|
||
<SetRow
|
||
title={tr('gpuSelect')}
|
||
disabled={opts.graphics !== 'reims-vgpu'}
|
||
reason={tr('gpuSvgaReason')}
|
||
desc={
|
||
realGPUs.length === 0 ? (
|
||
<span className="warn-text">{tr('gpuUnavailableHint')}</span>
|
||
) : selectedGPUHint ? (
|
||
<span className="warn-text">
|
||
{selectedGPUHint}{' '}
|
||
<button
|
||
type="button"
|
||
className="link-btn"
|
||
onClick={() => set({ graphics: 'vmware-svga' })}
|
||
>
|
||
{tr('gpuSwitchSvga')}
|
||
</button>
|
||
</span>
|
||
) : undefined
|
||
}
|
||
control={
|
||
<PopupSelect
|
||
id="vm-gpu"
|
||
label={tr('gpuSelect')}
|
||
value={opts.gpu}
|
||
onChange={(gpu) => set({ gpu })}
|
||
options={[
|
||
{ value: 'auto', label: tr('gpuAutoTitle'), detail: host.recommended_gpu ? shortGPUName(host.recommended_gpu.name) : undefined },
|
||
...realGPUs.map((g) => ({
|
||
value: gpuOptionValue(g, realGPUs),
|
||
label: shortGPUName(g.name),
|
||
detail:
|
||
g.compat === 'unsupported'
|
||
? tr('gpuCompatUnsupported')
|
||
: g.compat === 'warn'
|
||
? tr('gpuCompatWarn')
|
||
: g.vulkan_version
|
||
? `Vulkan ${g.vulkan_version}`
|
||
: undefined,
|
||
})),
|
||
]}
|
||
/>
|
||
}
|
||
/>
|
||
<SetRow
|
||
title={tr('resolution')}
|
||
disabled={opts.graphics !== 'reims-vgpu'}
|
||
reason={tr('gpuSvgaReason')}
|
||
desc={[hostDisplayDesc(host, tr), !opts.borderless ? hostDisplayAdvice(host, tr, windowPresets) : undefined].filter(Boolean).join(' · ') || undefined}
|
||
control={
|
||
<PopupSelect
|
||
id="vm-res"
|
||
label={tr('resolution')}
|
||
value={opts.resolution}
|
||
onChange={(resolution) => set({ resolution })}
|
||
options={(opts.borderless ? fullscreenPresets : windowPresets).map((p: FullscreenDisplayPreset) => ({
|
||
value: p.resolution,
|
||
label: p.label,
|
||
detail: [
|
||
p.hidpi ? `${tr('hidpiPresetBadge')} · ${hidpiLooksLike(p.resolution, tr) ?? ''}` : '',
|
||
p.scaleBadge ?? '',
|
||
p.native ? tr('resNativeBadge') : '',
|
||
p.scaleToFit ? tr('resScaleToFitWindow') : '',
|
||
p.recommended ? tr('recommendedBadge') : '',
|
||
].filter(Boolean).join(' · ') || undefined,
|
||
}))}
|
||
/>
|
||
}
|
||
/>
|
||
<SetRow
|
||
title={tr('displays')}
|
||
disabled={opts.graphics !== 'reims-vgpu'}
|
||
reason={tr('gpuSvgaReason')}
|
||
control={
|
||
<Segmented
|
||
label={tr('displays')}
|
||
value={opts.displays}
|
||
onChange={(displays) => set({ displays })}
|
||
options={[1, 2, 3, 4].map((d) => ({ value: d, label: String(d) }))}
|
||
/>
|
||
}
|
||
/>
|
||
</SetGroup>
|
||
|
||
<SetGroup title={tr('wizOptions')}>
|
||
<SetRow
|
||
title={tr('networkTitle')}
|
||
desc={opts.source_mode === 'offline' ? tr('networkOfflineHint') : tr('networkDesc')}
|
||
control={<Switch label={tr('networkTitle')} checked={!!opts.network} onChange={(network) => set({ network })} />}
|
||
/>
|
||
<SetRow
|
||
title={tr('sshForward')}
|
||
desc={(opts.ssh_port ?? 0) > 0 ? <code className="inline-code">{sshCommand(opts.ssh_port ?? 0)}</code> : tr('sshOffDesc')}
|
||
disabled={!opts.network}
|
||
reason={tr('sshNeedsNetwork')}
|
||
control={
|
||
<div className="hstack">
|
||
{(opts.ssh_port ?? 0) > 0 && (
|
||
<NumberField label={tr('sshPort')} value={opts.ssh_port ?? 0} min={1} max={65535} onChange={(ssh_port) => set({ ssh_port })} />
|
||
)}
|
||
<Switch label={tr('sshForward')} checked={(opts.ssh_port ?? 0) > 0} onChange={(on) => set({ ssh_port: on ? 2222 : 0 })} />
|
||
</div>
|
||
}
|
||
/>
|
||
<SetRow
|
||
title={tr('enableAudio')}
|
||
control={<Switch label={tr('enableAudio')} checked={!!opts.audio} onChange={(audio) => set({ audio })} />}
|
||
/>
|
||
<SetRow
|
||
title={tr('captureInput')}
|
||
desc={tr('captureInputHint')}
|
||
control={<Switch label={tr('captureInput')} checked={!!opts.capture} onChange={(capture) => set({ capture })} />}
|
||
/>
|
||
<SetRow
|
||
title={tr('fullscreenLaunch')}
|
||
desc={opts.borderless ? tr('fullscreenDecoupledHint') : tr('fullscreenLaunchHint')}
|
||
control={
|
||
<Switch
|
||
label={tr('fullscreenLaunch')}
|
||
checked={!!opts.borderless}
|
||
onChange={(borderless) => {
|
||
const list = borderless ? fullscreenPresets : windowPresets
|
||
const keep = list.some((p) => canKeepDisplayPreset(p, opts.resolution, borderless))
|
||
const fallback = list.find((p) => p.recommended)?.resolution ?? list[0]?.resolution ?? opts.resolution
|
||
set(keep ? { borderless } : { borderless, resolution: fallback })
|
||
}}
|
||
/>
|
||
}
|
||
/>
|
||
<SetRow
|
||
title={tr('enableLogs')}
|
||
control={<Switch label={tr('enableLogs')} checked={!!opts.logs} onChange={(logs) => set({ logs })} />}
|
||
/>
|
||
</SetGroup>
|
||
</>
|
||
)}
|
||
|
||
{step === 5 && (
|
||
<Review
|
||
locale={locale}
|
||
host={host}
|
||
opts={opts}
|
||
issues={issues}
|
||
checking={checking}
|
||
command={cmdPreview}
|
||
onEdit={setStep}
|
||
onName={(name) => set({ name })}
|
||
onPickDir={pickDir}
|
||
onDir={(dir) => set({ dir })}
|
||
onStartAfter={(start) => set({ start })}
|
||
/>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="dialog-foot">
|
||
<Button variant="ghost" disabled={step === 1 || isCustomDriver} onClick={() => setStep(step - 1)}>{tr('back')}</Button>
|
||
{isCustomDriver ? (
|
||
<Button
|
||
variant="primary"
|
||
busy={driverCreating}
|
||
disabled={!opts.name.trim() || driverCreating}
|
||
onClick={async () => {
|
||
setDriverCreating(true)
|
||
setErr('')
|
||
try {
|
||
await api.CreateVMWithDriver({
|
||
driver_id: driverID,
|
||
name: opts.name.trim(),
|
||
dir: opts.dir,
|
||
options: driverOpts,
|
||
})
|
||
onClose()
|
||
} catch (e) {
|
||
setErr(parseAppError(e).summary)
|
||
} finally {
|
||
setDriverCreating(false)
|
||
}
|
||
}}
|
||
>
|
||
{tr('createNow')}
|
||
</Button>
|
||
) : step < REVIEW_STEP ? (
|
||
<Button variant="primary" onClick={() => setStep(step + 1)}>{tr('next')}</Button>
|
||
) : (
|
||
<Button
|
||
variant="primary"
|
||
disabled={checking || !!err || issues.length > 0 || !cmdPreview}
|
||
title={tr('createStartedHint')}
|
||
onClick={handleCreate}
|
||
>
|
||
{tr('createNow')}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
</Modal>
|
||
)
|
||
}
|
||
|
||
interface ReviewProps {
|
||
locale: Locale
|
||
host: HostReport
|
||
opts: CreateOpts
|
||
issues: ValidationIssue[]
|
||
checking: boolean
|
||
command: string
|
||
onEdit: (step: number) => void
|
||
onName: (name: string) => void
|
||
onDir: (dir: string) => void
|
||
onPickDir: () => void
|
||
onStartAfter: (start: boolean) => void
|
||
}
|
||
|
||
type Row = { label: string; value: string; mono?: boolean }
|
||
|
||
const fileName = (p?: string) => (p ?? '').split(/[\\/]/).pop() || (p ?? '')
|
||
|
||
/** Step ⑤: what will be created, grouped by the step that set it, with the CLI equivalent folded away. */
|
||
const Review: React.FC<ReviewProps> = ({ locale, host, opts, issues, checking, command, onEdit, onName, onDir, onPickDir, onStartAfter }) => {
|
||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||
const [copied, setCopied] = useState(false)
|
||
const onOff = (b?: boolean) => tr(b ? 'summaryOn' : 'off')
|
||
|
||
const source = opts.source_mode === 'offline'
|
||
? tr('summaryOfflineSource', { v: opts.macos ?? '' })
|
||
: opts.source_mode === 'apple'
|
||
? tr('summaryAppleSource', { v: opts.macos === 'tahoe' ? 'macOS 26 Tahoe' : (opts.macos ?? '') })
|
||
: opts.source_mode === 'installer'
|
||
? tr('summaryInstallerSource', { file: fileName(opts.installer) })
|
||
: tr('summaryDiskSource', { file: fileName(opts.disk) })
|
||
|
||
const res = (opts.resolution ?? '').replace(/x/i, ' × ')
|
||
const graphicsRows: Row[] = opts.graphics === 'reims-vgpu'
|
||
? [
|
||
{ label: tr('factGraphics'), value: `${gpuLabel(locale, opts.gpu, host)} · reims-vgpu` },
|
||
{ label: tr('resolution'), value: (opts.displays ?? 1) > 1 ? `${opts.displays} × (${res})` : res },
|
||
]
|
||
: [{ label: tr('factGraphics'), value: `${tr('softwareGraphics')} · vmware-svga` }]
|
||
|
||
const groups: { step: number; title: I18nKey; rows: Row[] }[] = [
|
||
{
|
||
step: 1,
|
||
title: 'step1',
|
||
rows: [
|
||
{ label: tr('summarySource'), value: source },
|
||
{ label: tr('guestLangShort'), value: guestLangLabel(locale, opts.guest_lang) },
|
||
],
|
||
},
|
||
{
|
||
step: 2,
|
||
title: 'step2',
|
||
rows: [
|
||
{ label: tr('factCPU'), value: tr('cores', { n: opts.cpus }) },
|
||
{ label: tr('factMemory'), value: formatMemory(opts.memory) },
|
||
],
|
||
},
|
||
{
|
||
step: 3,
|
||
title: 'step3',
|
||
rows: [
|
||
...(opts.source_mode !== 'disk'
|
||
? [{ label: tr('diskSize'), value: tr('summaryDiskGrow', { size: formatMemory(opts.disk_size ?? '') }) }]
|
||
: [{ label: tr('diskMode'), value: tr(opts.disk_mode === 'in-place' ? 'diskModeInPlace' : 'diskModeCopy') }]),
|
||
{ label: tr('diskController'), value: controllerLabel(opts.disk_controller ?? 'nvme') },
|
||
],
|
||
},
|
||
{
|
||
step: 4,
|
||
title: 'step4',
|
||
rows: [
|
||
...graphicsRows,
|
||
{ label: tr('fieldAudio'), value: onOff(opts.audio) },
|
||
{ label: tr('fieldNetwork'), value: onOff(opts.network) },
|
||
{ label: tr('captureInput'), value: onOff(opts.capture) },
|
||
{ label: tr('summarySSH'), value: opts.ssh_port ? tr('summarySSHPort', { n: opts.ssh_port }) : tr('off') },
|
||
{ label: tr('summaryLogs'), value: onOff(opts.logs) },
|
||
],
|
||
},
|
||
]
|
||
|
||
const nameIssue = issues.find((i) => i.field === 'name')?.message
|
||
const general = issues.filter((i) => stepOfIssue(i) === REVIEW_STEP && i.field !== 'name')
|
||
|
||
const copy = async () => {
|
||
try {
|
||
await navigator.clipboard.writeText(command)
|
||
setCopied(true)
|
||
setTimeout(() => setCopied(false), 1500)
|
||
} catch (e) {
|
||
// clipboard unavailable; the text stays selectable
|
||
console.warn('[wizard] clipboard write failed:', e)
|
||
}
|
||
}
|
||
|
||
return (
|
||
<>
|
||
<SetGroup>
|
||
<SetRow
|
||
title={tr('vmName')}
|
||
error={nameIssue}
|
||
control={<input className="input rg-p-input name-input" aria-label={tr('vmName')} value={opts.name} onChange={(e) => onName(e.target.value)} spellCheck={false} />}
|
||
/>
|
||
<SetRow
|
||
title={tr('vmDir')}
|
||
desc={opts.dir ? <span className="mono path-text" title={opts.dir}>{opts.dir}</span> : tr('summaryDefaultDir')}
|
||
control={
|
||
<div className="hstack">
|
||
{opts.dir && <Button variant="ghost" onClick={() => onDir('')}>{tr('useDefault')}</Button>}
|
||
<Button onClick={onPickDir}>{tr('wizChooseFile')}</Button>
|
||
</div>
|
||
}
|
||
/>
|
||
<SetRow
|
||
title={tr('startAfterCreate')}
|
||
control={<Switch label={tr('startAfterCreate')} checked={!!opts.start} onChange={onStartAfter} />}
|
||
/>
|
||
</SetGroup>
|
||
|
||
{checking && issues.length === 0 ? (
|
||
<div className="review-status">{tr('validationChecking')}</div>
|
||
) : issues.length > 0 ? (
|
||
<div className="review-status bad"><CircleAlert size={14} />{tr('issuesCount', { n: issues.length })}</div>
|
||
) : (
|
||
<div className="review-status ok"><CircleCheck size={14} />{tr('validationPassed')}</div>
|
||
)}
|
||
|
||
{general.length > 0 && (
|
||
<div className="notice notice-error">
|
||
<ul>{general.map((i) => <li key={i.field + i.code}>{i.message}</li>)}</ul>
|
||
</div>
|
||
)}
|
||
|
||
<div className="review-groups">
|
||
{groups.map((g) => {
|
||
const own = issues.filter((i) => stepOfIssue(i) === g.step)
|
||
return (
|
||
<section key={g.step} className={`review-group${own.length ? ' has-issue' : ''}`} aria-label={tr(g.title)}>
|
||
<header className="review-head">
|
||
<span className="review-title">{tr(g.title)}</span>
|
||
<button type="button" className="link-btn" onClick={() => onEdit(g.step)}>{tr('summaryEdit')}</button>
|
||
</header>
|
||
<dl className="review-rows">
|
||
{g.rows.map((r) => (
|
||
<React.Fragment key={r.label}>
|
||
<dt>{r.label}</dt>
|
||
<dd className={r.mono ? 'mono' : undefined} title={r.value}>{r.value}</dd>
|
||
</React.Fragment>
|
||
))}
|
||
</dl>
|
||
{own.length > 0 && (
|
||
<ul className="review-issues">
|
||
{own.map((i) => <li key={i.field + i.code}><CircleAlert size={12} />{i.message}</li>)}
|
||
</ul>
|
||
)}
|
||
</section>
|
||
)
|
||
})}
|
||
</div>
|
||
|
||
<details className="review-cmd">
|
||
<summary><ChevronRight size={14} />{tr('commandToggle')}</summary>
|
||
<div className="review-cmd-body">
|
||
<span className="hint">{tr('commandToggleHint')}</span>
|
||
<div className="review-cmd-box">
|
||
<div className="code">{command || '…'}</div>
|
||
<IconButton
|
||
small
|
||
label={copied ? tr('toastCopied') : tr('copy')}
|
||
icon={copied ? <Check size={14} /> : <Copy size={14} />}
|
||
disabled={!command}
|
||
onClick={copy}
|
||
/>
|
||
</div>
|
||
</div>
|
||
</details>
|
||
</>
|
||
)
|
||
}
|