1013 lines
40 KiB
TypeScript
1013 lines
40 KiB
TypeScript
import { CircleAlert, Cpu, HardDrive, Info, Keyboard, LucideIcon, Monitor, Wrench } from 'lucide-react'
|
||
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
||
import '../i18n/domains/settings.gen'
|
||
import { I18nKey, parseAppError, t } from '../i18n'
|
||
import {
|
||
GUEST_LANG_PRESETS,
|
||
guestLangOptions,
|
||
MEMORY_MARKS,
|
||
findGPU,
|
||
formatBytes,
|
||
gpuCompatHint,
|
||
gpuOptionValue,
|
||
memorySafeLimitGB,
|
||
parseMemoryGB,
|
||
recommendedCPUs,
|
||
hidpiLooksLike,
|
||
hostDisplayAdvice,
|
||
hostDisplayDesc,
|
||
recommendedMemoryGB,
|
||
shortGPUName,
|
||
sshCommand,
|
||
} from '../lib/format'
|
||
import {
|
||
buildResolutionOptions,
|
||
buildSettingsSaveDiff,
|
||
countChangedSettingsFields,
|
||
deriveSettingsResolutionState,
|
||
expandTouchedSettingsFields,
|
||
normalizeResolution,
|
||
reconcileSettingsFormOnBaseChange,
|
||
resolveCustomResBlur,
|
||
selectSettingsResolution,
|
||
switchSettingsGraphics,
|
||
toggleSettingsBorderless,
|
||
} from '../lib/displayResolution'
|
||
import { applyKernelIrqchip, findOptimization, kernelIrqchipHint, parseKernelIrqchip } from '../lib/optimizations'
|
||
import { useVMStats } from '../lib/vmStats'
|
||
import { HostReport, Locale, Optimization, SetOpts, ValidationIssue, VMAffinityStatus, VMDetail, VMStats, DiskCache } from '../types'
|
||
import { Button } from '../ui/controls'
|
||
import { Modal } from '../ui/dialog'
|
||
import { NumberField, OptionCards, PopupSelect, RangeField, ScreenArt, Segmented, SetGroup, SetRow, SetValue, Switch } from '../ui/settings'
|
||
import type { ToastInput } from '../ui/toast'
|
||
import { api } from '../wails'
|
||
import { formatAffinitySummary } from './AffinityDialog'
|
||
import { VMNetworkSettings } from './VMNetworkSettings'
|
||
import { DefenderExclusionRow, DiskMaintenanceRows, useDiskMaintenance } from './vmSettings/disk'
|
||
import { DiskCacheRow } from './vmSettings/diskCache'
|
||
import { KeymapSection, useKeymap } from './vmSettings/keymap'
|
||
import { useVMPluginSettings, VMPluginGroup } from './vmSettings/plugins'
|
||
import { DriveShareSection, SharedFolderSection, useDriveShares, useSharedFolders, WritableFolderDialog } from './vmSettings/sharing'
|
||
import { SMBIOSDialog, SMBIOSSection, useSMBIOS } from './vmSettings/smbios'
|
||
import { TargetDisplayRow, useTargetDisplay } from './vmSettings/targetDisplay'
|
||
import { GuestTimezoneRow, useGuestTimezone } from './vmSettings/timezone'
|
||
|
||
// VM settings (see docs/design-guidelines.md): edits are staged here and written in
|
||
// one `reims-ctl set` on Save, because upstream applies every change on the
|
||
// next start. Each row marks itself when it differs from the VM's current
|
||
// value and can be put back on its own.
|
||
|
||
type Cat = 'general' | 'compute' | 'display' | 'storage' | 'input' | 'advanced'
|
||
|
||
const CATS: { id: Cat; label: I18nKey; icon: LucideIcon }[] = [
|
||
{ id: 'general', label: 'catGeneral', icon: Info },
|
||
{ id: 'compute', label: 'catCompute', icon: Cpu },
|
||
{ id: 'display', label: 'catGraphics', icon: Monitor },
|
||
{ id: 'storage', label: 'catStorageNet', icon: HardDrive },
|
||
{ id: 'input', label: 'catInputAudio', icon: Keyboard },
|
||
{ id: 'advanced', label: 'catAdvanced', icon: Wrench },
|
||
]
|
||
|
||
type Field = Exclude<keyof SetOpts, 'name' | 'env'>
|
||
|
||
const FIELD_CAT: Record<Field, Cat> = {
|
||
guest_lang: 'general',
|
||
cpus: 'compute',
|
||
memory: 'compute',
|
||
nested_virt: 'compute',
|
||
graphics: 'display',
|
||
gpu: 'display',
|
||
resolution: 'display',
|
||
auto_resolution: 'display',
|
||
displays: 'display',
|
||
borderless: 'display',
|
||
disk_controller: 'storage',
|
||
disk_cache: 'storage',
|
||
network: 'storage',
|
||
ssh_port: 'storage',
|
||
capture: 'input',
|
||
audio: 'input',
|
||
audio_backend: 'input',
|
||
logs: 'advanced',
|
||
log_level: 'advanced',
|
||
stop_timeout: 'advanced',
|
||
extra_args: 'advanced',
|
||
}
|
||
const FIELDS = Object.keys(FIELD_CAT) as Field[]
|
||
|
||
const LOG_LEVELS = ['error', 'warn', 'info', 'debug', 'trace'] as const
|
||
const CUSTOM = '__custom'
|
||
|
||
|
||
const normPath = (s: string | undefined) => (s ?? '').replace(/\//g, '\\').toLowerCase()
|
||
|
||
/** Whether two values of a field mean the same thing to reims-ctl. */
|
||
function same(field: Field, a: SetOpts[Field], b: SetOpts[Field]): boolean {
|
||
switch (field) {
|
||
case 'memory': return parseMemoryGB(a as string) === parseMemoryGB(b as string)
|
||
case 'gpu': return normPath(a as string) === normPath(b as string)
|
||
case 'resolution': return normalizeResolution(a as string) === normalizeResolution(b as string)
|
||
case 'log_level':
|
||
case 'extra_args':
|
||
case 'audio_backend':
|
||
case 'disk_cache':
|
||
case 'guest_lang': return String(a ?? '').trim() === String(b ?? '').trim()
|
||
default: return a === b
|
||
}
|
||
}
|
||
|
||
function baseline(detail: VMDetail, host: HostReport): SetOpts {
|
||
// Match the stored ICD path to the host's spelling so the GPU card lights up.
|
||
const icd = (host.gpus ?? []).find((g) => normPath(g.vulkan_icd) === normPath(detail.gpu))?.vulkan_icd
|
||
return {
|
||
name: detail.name,
|
||
cpus: detail.cpus,
|
||
memory: detail.memory,
|
||
nested_virt: detail.nested_virt,
|
||
graphics: detail.graphics,
|
||
displays: detail.displays || 1,
|
||
disk_controller: detail.disk_controller,
|
||
disk_cache: (detail.disk_cache as DiskCache) || 'default',
|
||
resolution: detail.resolution,
|
||
auto_resolution: !!detail.auto_resolution,
|
||
borderless: detail.borderless,
|
||
...(detail.capture_supported ? { capture: detail.capture } : {}),
|
||
gpu: icd ?? (detail.gpu || 'auto'),
|
||
logs: detail.logs,
|
||
log_level: detail.log_level,
|
||
audio: detail.audio,
|
||
audio_backend: detail.audio_backend || 'auto',
|
||
network: detail.network,
|
||
ssh_port: detail.ssh_port,
|
||
stop_timeout: detail.stop_timeout,
|
||
extra_args: detail.extra_args,
|
||
guest_lang: detail.guest_lang || 'en-US:0',
|
||
}
|
||
}
|
||
|
||
interface Props {
|
||
locale: Locale
|
||
detail: VMDetail
|
||
driverID: string
|
||
stats?: VMStats | null
|
||
host: HostReport
|
||
fixedModeSupported?: boolean
|
||
diskCacheSupported?: boolean
|
||
optimizations?: Optimization[]
|
||
running: boolean
|
||
onCopy?: (text: string) => void
|
||
onDiskChanged?: () => void
|
||
onOpenAffinity?: () => void
|
||
affinityVersion?: number
|
||
/** Re-probe the host, e.g. after Windows' processor scheduling may have changed. */
|
||
onHostChanged?: () => void
|
||
onToast: (toast: ToastInput) => void
|
||
onClose: () => void
|
||
onSaved: () => void
|
||
}
|
||
|
||
export const SettingsModal: React.FC<Props> = ({ locale, detail, driverID, stats, host, fixedModeSupported = false, diskCacheSupported = false, optimizations, running, onCopy, onDiskChanged, onOpenAffinity, affinityVersion = 0, onHostChanged, onToast, onClose, onSaved }) => {
|
||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||
const irqOpt = findOptimization(optimizations, 'kernel_irqchip')
|
||
const base = useMemo(() => baseline(detail, host), [detail, host])
|
||
|
||
const [cat, setCat] = useState<Cat>('compute')
|
||
const [busy, setBusy] = useState(false)
|
||
const [issues, setIssues] = useState<ValidationIssue[]>([])
|
||
const [err, setErr] = useState('')
|
||
const [form, setForm] = useState<SetOpts>(base)
|
||
const liveStats = useVMStats(driverID, detail.name, running) ?? stats
|
||
const toolsConnected = liveStats?.guest_tools_connected ?? detail.guest_tools_connected ?? false
|
||
const toolsVersion = toolsConnected ? liveStats?.guest_tools_agent_version ?? detail.guest_tools_agent_version ?? 0 : 0
|
||
const [affinityStatus, setAffinityStatus] = useState<VMAffinityStatus | null>(null)
|
||
const drives = useDriveShares(detail.name)
|
||
const folders = useSharedFolders(detail.name, locale)
|
||
const smbios = useSMBIOS(detail, running)
|
||
const keymap = useKeymap(detail.name, running, cat === 'input')
|
||
const plugins = useVMPluginSettings(`${driverID}:${detail.name}`, setErr)
|
||
const disk = useDiskMaintenance({ locale, driverID, vm: detail.name, diskPath: detail.disk, running, stats, onError: setErr, onDiskChanged })
|
||
const timezone = useGuestTimezone(driverID, detail.name, running, cat === 'general')
|
||
const display = useTargetDisplay({
|
||
locale, driverID, vm: detail.name, running, host, shown: cat === 'display', onToast,
|
||
isBlocked: () => busy || timezone.isWriting(),
|
||
})
|
||
const { displayBusy, connectedDisplays, activeTargetDisplay, activeTargetDisplayTitle, displayProfile } = display
|
||
const tzBusy = timezone.tzBusy
|
||
const pane = useRef<HTMLDivElement>(null)
|
||
|
||
const [forceCustomRes, setCustomRes] = useState(false)
|
||
const { presets, fsPresets, activePresets, autoPreset, customRes, resValue, resBad } = deriveSettingsResolutionState({
|
||
form,
|
||
displayProfile,
|
||
fixedModeSupported,
|
||
forceCustomRes,
|
||
})
|
||
const [customLog, setCustomLog] = useState(!!form.log_level && !(LOG_LEVELS as readonly string[]).includes(form.log_level))
|
||
|
||
// The detail the panel opened with can be a stale one (reopened right after
|
||
// a save, before the refreshed detail arrives) or refreshed in the background:
|
||
// sync untouched fields from the latest baseline while preserving user edits.
|
||
const vmIdentity = `${driverID}:${detail.name}`
|
||
const vmIdentityRef = useRef(vmIdentity)
|
||
const touchedFieldsRef = useRef<Set<Field>>(new Set())
|
||
useEffect(() => {
|
||
const prevKey = vmIdentityRef.current
|
||
vmIdentityRef.current = vmIdentity
|
||
if (prevKey !== vmIdentity) {
|
||
touchedFieldsRef.current.clear()
|
||
setIssues([])
|
||
setErr('')
|
||
setCustomRes(false)
|
||
setCustomLog(!!base.log_level && !(LOG_LEVELS as readonly string[]).includes(base.log_level))
|
||
} else {
|
||
const touched = touchedFieldsRef.current
|
||
if (!touched.has('resolution') && !touched.has('auto_resolution')) {
|
||
setCustomRes(false)
|
||
}
|
||
if (!touched.has('log_level')) {
|
||
setCustomLog(!!base.log_level && !(LOG_LEVELS as readonly string[]).includes(base.log_level))
|
||
}
|
||
}
|
||
setForm((cur) => reconcileSettingsFormOnBaseChange({
|
||
previousVMKey: prevKey,
|
||
nextVMKey: vmIdentity,
|
||
form: cur,
|
||
base,
|
||
touchedFields: touchedFieldsRef.current,
|
||
}).form)
|
||
}, [base, vmIdentity])
|
||
|
||
useEffect(() => {
|
||
setForm((f) => {
|
||
if (!detail.capture_supported) {
|
||
return f.capture === undefined ? f : { ...f, capture: undefined }
|
||
}
|
||
return f.capture === undefined ? { ...f, capture: detail.capture } : f
|
||
})
|
||
}, [detail.capture_supported, detail.capture])
|
||
|
||
const set = (patch: Partial<SetOpts>) => {
|
||
const touched = expandTouchedSettingsFields(Object.keys(patch)) as Field[]
|
||
for (const f of touched) touchedFieldsRef.current.add(f)
|
||
setForm((f) => ({ ...f, ...patch }))
|
||
setIssues((list) => list.filter((i) => !touched.includes(i.field as Field)))
|
||
}
|
||
const dirty = (f: Field) => (f === 'capture' && !detail.capture_supported ? false : !same(f, form[f], base[f]))
|
||
const reset = (f: Field) => () => {
|
||
const toClear = expandTouchedSettingsFields([f]) as Field[]
|
||
for (const field of toClear) touchedFieldsRef.current.delete(field)
|
||
setForm((cur) => {
|
||
const next = { ...cur }
|
||
for (const field of toClear) {
|
||
;(next as unknown as Record<string, unknown>)[field] = (base as unknown as Record<string, unknown>)[field]
|
||
}
|
||
return next
|
||
})
|
||
setIssues((list) => list.filter((i) => !toClear.includes(i.field as Field)))
|
||
if (f === 'resolution' || f === 'auto_resolution' || f === 'borderless') setCustomRes(false)
|
||
if (f === 'log_level') setCustomLog(!!base.log_level && !(LOG_LEVELS as readonly string[]).includes(base.log_level))
|
||
}
|
||
const changed = FIELDS.filter(dirty)
|
||
const changedCount = countChangedSettingsFields(changed)
|
||
const changedIn = (c: Cat) => countChangedSettingsFields(changed.filter((f) => FIELD_CAT[f] === c))
|
||
const issueOf = (f: Field) => issues.find((i) => i.field === f)?.message
|
||
const issueIn = (c: Cat) => issues.some((i) => FIELD_CAT[i.field as Field] === c) || (c === 'display' && resBad)
|
||
const strayIssues = issues.filter((i) => !(i.field in FIELD_CAT))
|
||
|
||
// Inline checks the backend would also reject, so the row says it first.
|
||
const sshOn = (form.ssh_port ?? 0) > 0
|
||
const localBlock = resBad
|
||
const nestedVirtAvailable = host.whpx === 'ready' && host.whpx_caps?.nested_vmx && !host.needs_cold_reboot_workaround
|
||
|
||
const rowProps = (f: Field) => ({
|
||
field: f,
|
||
dirty: dirty(f),
|
||
onReset: reset(f),
|
||
resetLabel: tr('resetField'),
|
||
error: issueOf(f),
|
||
})
|
||
|
||
// Scroll the first row with an error into view after switching to its page.
|
||
useEffect(() => {
|
||
if (issues.length === 0) return
|
||
const el = pane.current?.querySelector<HTMLElement>('[data-error]')
|
||
el?.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
|
||
}, [issues, cat])
|
||
|
||
useEffect(() => {
|
||
let active = true
|
||
api.GetVMAffinity(driverID, detail.name)
|
||
.then((st) => { if (active) setAffinityStatus(st) })
|
||
.catch((e) => console.warn('[settings] GetVMAffinity failed:', e))
|
||
return () => { active = false }
|
||
}, [detail.name, running, affinityVersion])
|
||
|
||
// Windows-wide, not staged with Save: one UAC prompt opens Windows' own
|
||
// Performance Options, and the new choice shows after the host refresh.
|
||
const [openingSched, setOpeningSched] = useState(false)
|
||
const openScheduling = async () => {
|
||
setOpeningSched(true)
|
||
try {
|
||
await api.OpenProcessorScheduling()
|
||
onHostChanged?.()
|
||
} catch (e) {
|
||
setErr(parseAppError(e).summary)
|
||
} finally {
|
||
setOpeningSched(false)
|
||
}
|
||
}
|
||
|
||
const handleSave = async () => {
|
||
if (busy || display.isBusy() || timezone.isWriting() || changed.length === 0 || localBlock) return
|
||
setErr('')
|
||
setIssues([])
|
||
setBusy(true)
|
||
try {
|
||
const diff = buildSettingsSaveDiff(detail.name, changed, form, base)
|
||
const iss = await api.ValidateSet(diff)
|
||
if (iss && iss.length > 0) {
|
||
setIssues(iss)
|
||
const first = iss.map((i) => FIELD_CAT[i.field as Field]).find(Boolean)
|
||
if (first) setCat(first)
|
||
return
|
||
}
|
||
await api.ApplyVMSettings(diff)
|
||
onSaved()
|
||
} catch (e) {
|
||
setErr(parseAppError(e).summary)
|
||
} finally {
|
||
setBusy(false)
|
||
}
|
||
}
|
||
|
||
const resetAll = () => {
|
||
touchedFieldsRef.current.clear()
|
||
setForm(base)
|
||
setIssues([])
|
||
setCustomRes(false)
|
||
setCustomLog(!!base.log_level && !(LOG_LEVELS as readonly string[]).includes(base.log_level))
|
||
}
|
||
|
||
const onKeyDown = (e: React.KeyboardEvent) => {
|
||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') {
|
||
e.preventDefault()
|
||
void handleSave()
|
||
}
|
||
}
|
||
|
||
const realGPUs = (host.gpus ?? []).filter((g) => g.kind !== 'virtual')
|
||
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(form.memory) ?? memRec)
|
||
|
||
// ── Pages ────────────────────────────────────────────────
|
||
|
||
const general = (
|
||
<>
|
||
<SetGroup title={tr('groupMacOS')}>
|
||
<SetRow
|
||
{...rowProps('guest_lang')}
|
||
title={tr('guestLangShort')}
|
||
desc={tr('guestLangSettingsHint')}
|
||
control={
|
||
<PopupSelect
|
||
label={tr('guestLangShort')}
|
||
value={form.guest_lang || 'en-US:0'}
|
||
onChange={(guest_lang) => set({ guest_lang })}
|
||
options={[
|
||
...guestLangOptions(locale),
|
||
...(form.guest_lang && !GUEST_LANG_PRESETS.some((p) => p.value === form.guest_lang)
|
||
? [{ value: form.guest_lang, label: form.guest_lang }]
|
||
: []),
|
||
]}
|
||
/>
|
||
}
|
||
/>
|
||
<GuestTimezoneRow
|
||
locale={locale}
|
||
detail={detail}
|
||
hostTimezone={host.timezone}
|
||
state={timezone}
|
||
disabled={displayBusy || busy}
|
||
isBlocked={() => busy || display.isBusy()}
|
||
onToast={onToast}
|
||
onCopy={onCopy}
|
||
/>
|
||
</SetGroup>
|
||
<SetGroup note={!detail.has_opencore ? tr('platformReadonly') : undefined}>
|
||
<SetValue title={tr('vmName')} value={detail.name} />
|
||
<SetValue title={tr('fieldKind')} value={detail.kind || '—'} />
|
||
<SetValue title={tr('fieldCPUModel')} value={detail.cpu_model || '—'} mono />
|
||
<SetValue title={tr('opencore')} value={detail.has_opencore ? tr('configured') : '—'} />
|
||
<SetValue title={tr('fieldDir')} value={detail.directory} mono />
|
||
</SetGroup>
|
||
{detail.has_opencore && <SMBIOSSection locale={locale} state={smbios} onCopy={onCopy} />}
|
||
<VMPluginGroup locale={locale} group="collaboration" state={plugins} />
|
||
</>
|
||
)
|
||
|
||
const irqMode = parseKernelIrqchip(form.extra_args)
|
||
const cpuOver = (form.cpus ?? 0) > threads - 2 && threads > 2
|
||
const memOver = memGB > memSafe
|
||
const compute = (
|
||
<>
|
||
<SetGroup title={tr('factCPU')}>
|
||
<SetRow
|
||
{...rowProps('cpus')}
|
||
title={tr('vcpus')}
|
||
desc={cpuOver ? <span className="warn-text">{tr('cpuOverHint')}</span> : tr('cpuRecHint', { rec: cpuRec, n: threads })}
|
||
block={
|
||
<RangeField
|
||
label={tr('vcpus')}
|
||
value={form.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) }))}
|
||
/>
|
||
}
|
||
/>
|
||
{onOpenAffinity && (
|
||
<SetRow
|
||
title={tr('affinityTitle')}
|
||
desc={affinityStatus ? `${formatAffinitySummary(locale, affinityStatus)} · ${tr('affinityRowDesc')}` : tr('affinityRowDesc')}
|
||
control={
|
||
<Button variant="secondary" icon={<Cpu size={13} aria-hidden="true" />} onClick={onOpenAffinity}>
|
||
{tr('affinityConfigure')}
|
||
</Button>
|
||
}
|
||
/>
|
||
)}
|
||
</SetGroup>
|
||
<SetGroup title={tr('factMemory')}>
|
||
<SetRow
|
||
{...rowProps('memory')}
|
||
title={tr('guestMemory')}
|
||
desc={memOver
|
||
? <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>
|
||
<SetGroup title={tr('groupPerformance')}>
|
||
<SetRow
|
||
{...rowProps('extra_args')}
|
||
dirty={parseKernelIrqchip(form.extra_args) !== parseKernelIrqchip(base.extra_args)}
|
||
onReset={() => set({ extra_args: applyKernelIrqchip(form.extra_args, parseKernelIrqchip(base.extra_args)) })}
|
||
error={undefined}
|
||
field={undefined}
|
||
title={tr('kernelIrqchipLabel')}
|
||
desc={<span className={irqOpt?.detail?.startsWith('0x') ? 'warn-text' : undefined}>{kernelIrqchipHint(locale, irqOpt)}</span>}
|
||
control={
|
||
<Segmented
|
||
label={tr('kernelIrqchipLabel')}
|
||
value={irqMode}
|
||
onChange={(mode) => set({ extra_args: applyKernelIrqchip(form.extra_args, mode) })}
|
||
options={[
|
||
{ value: 'auto', label: tr('kernelIrqchipAuto') },
|
||
{ value: 'on', label: tr('kernelIrqchipOn'), disabled: !irqOpt?.supported },
|
||
{ value: 'off', label: tr('kernelIrqchipOff') },
|
||
]}
|
||
/>
|
||
}
|
||
/>
|
||
<SetRow
|
||
{...rowProps('nested_virt')}
|
||
title={tr('nestedVirtLabel')}
|
||
desc={tr(nestedVirtAvailable ? 'nestedVirtDesc' : 'nestedVirtUnavailable')}
|
||
error={detail.nested_virt_invalid && !dirty('nested_virt') ? tr('nestedVirtInvalid') : issueOf('nested_virt')}
|
||
control={<Switch label={tr('nestedVirtLabel')} checked={!!form.nested_virt} disabled={!nestedVirtAvailable && !form.nested_virt} onChange={(nested_virt) => set({ nested_virt })} />}
|
||
/>
|
||
<SetRow
|
||
title={tr('optSchedTitle')}
|
||
desc={
|
||
host.processor_scheduling === 'background'
|
||
? tr('optSchedNowBackground')
|
||
: host.processor_scheduling
|
||
? <span className="warn-text">{tr('optSchedNowPrograms')}</span>
|
||
: tr('optSchedSub')
|
||
}
|
||
control={<Button variant="secondary" busy={openingSched} onClick={openScheduling}>{tr('optSchedOpen')}</Button>}
|
||
/>
|
||
</SetGroup>
|
||
</>
|
||
)
|
||
|
||
const gpuOptions = [
|
||
{
|
||
value: 'auto',
|
||
title: tr('gpuAutoTitle'),
|
||
sub: host.recommended_gpu ? tr('gpuAutoSub', { name: shortGPUName(host.recommended_gpu.name) }) : tr('gpuAutoOption'),
|
||
},
|
||
...realGPUs.map((g) => ({
|
||
value: gpuOptionValue(g, realGPUs),
|
||
title: shortGPUName(g.name),
|
||
sub: [
|
||
g.kind === 'discrete' ? tr('gpuKindDiscrete') : g.kind === 'integrated' ? tr('gpuKindIntegrated') : '',
|
||
g.compat === 'unsupported' ? tr('gpuCompatUnsupported') : g.compat === 'warn' ? tr('gpuCompatWarn') : '',
|
||
]
|
||
.filter(Boolean)
|
||
.join(' · ') || undefined,
|
||
})),
|
||
]
|
||
if (form.gpu && form.gpu !== 'auto' && !gpuOptions.some((o) => normPath(o.value) === normPath(form.gpu))) {
|
||
gpuOptions.push({ value: form.gpu, title: form.gpu.split(/[\\/]/).pop() || form.gpu, sub: tr('gpuCustomIcd') })
|
||
}
|
||
const selectedGPU = findGPU(host, form.gpu)
|
||
const selectedGPUHint = gpuCompatHint(locale, selectedGPU)
|
||
const vgpu = form.graphics !== 'vmware-svga'
|
||
const targetDisp = activeTargetDisplay
|
||
const hidpiAdvice = hostDisplayAdvice(displayProfile, tr, presets)
|
||
const changeGraphics = (graphics: string) => {
|
||
const next = switchSettingsGraphics(graphics)
|
||
if (next.forceCustomRes !== undefined) setCustomRes(next.forceCustomRes)
|
||
set(next.patch)
|
||
}
|
||
const toggleBorderless = (borderless: boolean) => {
|
||
set(toggleSettingsBorderless({
|
||
borderless,
|
||
form,
|
||
displayProfile,
|
||
targetDisplay: targetDisp,
|
||
presets,
|
||
fsPresets,
|
||
customRes,
|
||
}))
|
||
}
|
||
const resArt = (r: string) => {
|
||
const m = /^(\d+)\s*[x×]\s*(\d+)$/i.exec(r)
|
||
return m ? <ScreenArt w={Number(m[1])} h={Number(m[2])} /> : <ScreenArt w={16} h={10} />
|
||
}
|
||
const displayPage = (
|
||
<>
|
||
<SetGroup title={tr('groupGraphics')}>
|
||
<SetRow
|
||
{...rowProps('graphics')}
|
||
title={tr('graphicsBackend')}
|
||
desc={vgpu ? tr('graphicsReimsDesc') : tr('graphicsSvgaDesc')}
|
||
disabled={running}
|
||
reason={tr('graphicsRunningReason')}
|
||
control={
|
||
<Segmented
|
||
label={tr('graphicsBackend')}
|
||
value={form.graphics}
|
||
onChange={changeGraphics}
|
||
options={[
|
||
{ value: 'reims-vgpu', label: tr('graphicsReimsShort') },
|
||
{ value: 'vmware-svga', label: tr('graphicsSvgaShort') },
|
||
]}
|
||
/>
|
||
}
|
||
/>
|
||
<SetRow
|
||
{...rowProps('gpu')}
|
||
title={tr('gpuSelect')}
|
||
desc={
|
||
realGPUs.length === 0 ? (
|
||
<span className="warn-text">{tr('gpuUnavailableHint')}</span>
|
||
) : selectedGPUHint ? (
|
||
<span className="warn-text">
|
||
{selectedGPUHint}
|
||
{!running && vgpu && (
|
||
<>
|
||
{' '}
|
||
<button
|
||
type="button"
|
||
className="link-btn"
|
||
onClick={() => changeGraphics('vmware-svga')}
|
||
>
|
||
{tr('gpuSwitchSvga')}
|
||
</button>
|
||
</>
|
||
)}
|
||
</span>
|
||
) : undefined
|
||
}
|
||
disabled={!vgpu}
|
||
reason={tr('gpuSvgaReason')}
|
||
block={<OptionCards label={tr('gpuSelect')} value={gpuOptions.find((o) => normPath(o.value) === normPath(form.gpu))?.value} onChange={(gpu) => set({ gpu })} options={gpuOptions} />}
|
||
/>
|
||
</SetGroup>
|
||
<SetGroup title={tr('displayGroup')}>
|
||
<TargetDisplayRow locale={locale} running={running} disabled={busy} state={display} />
|
||
<SetRow
|
||
{...rowProps('borderless')}
|
||
title={tr('fullscreenLaunch')}
|
||
desc={form.borderless ? tr('fullscreenDecoupledHint') : tr('fullscreenLaunchHint')}
|
||
control={<Switch label={tr('fullscreenLaunch')} checked={!!form.borderless} onChange={toggleBorderless} />}
|
||
/>
|
||
<SetRow
|
||
{...rowProps('resolution')}
|
||
dirty={dirty('resolution') || dirty('auto_resolution')}
|
||
onReset={reset('resolution')}
|
||
disabled={!vgpu}
|
||
reason={tr('gpuSvgaReason')}
|
||
error={issueOf('resolution') ?? issueOf('auto_resolution') ?? (resBad ? tr('resInvalid') : undefined)}
|
||
title={tr('resolution')}
|
||
desc={hostDisplayDesc(host, tr, activeTargetDisplay, (d) =>
|
||
tr('targetDisplayHint', {
|
||
name: activeTargetDisplayTitle,
|
||
w: d.width,
|
||
h: d.height,
|
||
scale: d.scale_pct || 100,
|
||
}),
|
||
)}
|
||
block={
|
||
<>
|
||
<OptionCards
|
||
label={tr('resolution')}
|
||
value={resValue}
|
||
onChange={(v) => {
|
||
const next = selectSettingsResolution({ value: v, form, base, autoPreset })
|
||
setCustomRes(next.forceCustomRes)
|
||
set(next.patch)
|
||
}}
|
||
options={buildResolutionOptions({
|
||
graphics: form.graphics,
|
||
autoPreset,
|
||
activePresets,
|
||
includeCustom: true,
|
||
}).map((item) => {
|
||
if (item.kind === 'auto') {
|
||
const p = item.preset!
|
||
return {
|
||
value: item.value,
|
||
title: tr('resAuto'),
|
||
sub: tr('resAutoSub', { res: p.label }),
|
||
art: resArt(p.resolution),
|
||
badges: [
|
||
p.hidpi ? tr('hidpiPresetBadge') : '',
|
||
p.scaleBadge ?? '',
|
||
tr('recommendedBadge'),
|
||
].filter(Boolean),
|
||
}
|
||
}
|
||
if (item.kind === 'custom') {
|
||
return {
|
||
value: item.value,
|
||
title: tr('resCustom'),
|
||
sub: tr('resCustomSub'),
|
||
art: <span className="screen-art custom" aria-hidden="true" />,
|
||
}
|
||
}
|
||
const p = item.preset!
|
||
return {
|
||
value: item.value,
|
||
title: p.label,
|
||
sub: p.hidpi ? hidpiLooksLike(p.resolution, tr) : undefined,
|
||
art: resArt(p.resolution),
|
||
badges: [
|
||
p.hidpi ? tr('hidpiPresetBadge') : '',
|
||
p.scaleBadge ?? '',
|
||
p.native ? tr('resNativeBadge') : '',
|
||
p.scaleToFit ? tr('resScaleToFitWindow') : '',
|
||
p.recommended ? tr('recommendedBadge') : '',
|
||
].filter(Boolean),
|
||
}
|
||
})}
|
||
/>
|
||
{customRes && (
|
||
<input
|
||
className="input rg-p-input mono res-input"
|
||
aria-label={tr('resolution')}
|
||
placeholder={form.borderless ? '5120x2880' : '2560x1600'}
|
||
autoFocus
|
||
value={form.resolution ?? ''}
|
||
onChange={(e) => set({ resolution: e.target.value })}
|
||
onBlur={() => {
|
||
const blurred = resolveCustomResBlur({
|
||
resolution: form.resolution,
|
||
autoResolution: form.auto_resolution,
|
||
forceCustomRes,
|
||
activePresets,
|
||
})
|
||
if (blurred.nextResolution !== undefined && blurred.nextResolution !== form.resolution) {
|
||
set({ resolution: blurred.nextResolution })
|
||
}
|
||
if (blurred.exitCustom) {
|
||
setCustomRes(false)
|
||
}
|
||
}}
|
||
/>
|
||
)}
|
||
{!form.borderless && hidpiAdvice && <div className="srow-desc res-advice">{hidpiAdvice}</div>}
|
||
</>
|
||
}
|
||
/>
|
||
<SetRow
|
||
{...rowProps('displays')}
|
||
title={tr('displays')}
|
||
desc={connectedDisplays.length > 1 ? tr('multiDisplayHint', { n: connectedDisplays.length }) : undefined}
|
||
control={
|
||
<Segmented
|
||
label={tr('displays')}
|
||
value={form.displays ?? 1}
|
||
onChange={(displays) => set({ displays })}
|
||
options={[1, 2, 3, 4].map((n) => ({ value: n, label: String(n) }))}
|
||
/>
|
||
}
|
||
/>
|
||
</SetGroup>
|
||
</>
|
||
)
|
||
|
||
const diskControllerDesc = detail.has_installer
|
||
? tr('diskControllerInstallHint')
|
||
: form.disk_controller === 'virtio'
|
||
? tr('diskControllerVirtioHint')
|
||
: form.disk_controller === 'nvme'
|
||
? tr('diskControllerNvmeReadyHint')
|
||
: tr('diskControllerNvmeHint')
|
||
|
||
const storage = (
|
||
<>
|
||
<SetGroup title={tr('catStorage')}>
|
||
<SetValue title={tr('fieldDisk')} value={detail.disk} mono />
|
||
{stats && stats.disk_virtual_bytes > 0 && (
|
||
<SetValue
|
||
title={tr('factDisk')}
|
||
value={tr('diskUsageSummary', {
|
||
actual: formatBytes(stats.disk_actual_bytes, locale),
|
||
virtual: formatBytes(stats.disk_virtual_bytes, locale),
|
||
})}
|
||
/>
|
||
)}
|
||
{stats && ((stats.disk_backing_depth ?? 0) >= 2 || stats.disk_backing_broken) && (
|
||
<SetValue
|
||
title={tr('factBackingChain')}
|
||
value={
|
||
stats.disk_backing_broken
|
||
? tr('diagBackingChainBroken', { depth: stats.disk_backing_depth ?? 1 })
|
||
: tr('diagBackingChainWarn', { depth: stats.disk_backing_depth ?? 2 })
|
||
}
|
||
/>
|
||
)}
|
||
<SetRow
|
||
{...rowProps('disk_controller')}
|
||
title={tr('diskController')}
|
||
desc={diskControllerDesc}
|
||
disabled={detail.has_installer}
|
||
reason={tr('diskControllerWarn')}
|
||
control={
|
||
<Segmented
|
||
label={tr('diskController')}
|
||
value={form.disk_controller}
|
||
onChange={(disk_controller) => set({ disk_controller })}
|
||
options={[
|
||
{ value: 'ahci', label: 'SATA' },
|
||
{ value: 'nvme', label: 'NVMe' },
|
||
{ value: 'virtio', label: 'VirtIO' },
|
||
]}
|
||
/>
|
||
}
|
||
/>
|
||
<DiskCacheRow
|
||
locale={locale}
|
||
value={(form.disk_cache as DiskCache) || 'default'}
|
||
dirty={dirty('disk_cache')}
|
||
supported={diskCacheSupported}
|
||
reason={tr('diskCacheRequiresRuntime')}
|
||
onReset={reset('disk_cache')}
|
||
resetLabel={tr('resetField')}
|
||
error={issueOf('disk_cache')}
|
||
onChange={(disk_cache) => set({ disk_cache })}
|
||
/>
|
||
<DiskMaintenanceRows locale={locale} running={running} state={disk} onCopy={onCopy} />
|
||
{host.defender_realtime_active && <DefenderExclusionRow locale={locale} dataRoot={host.data_root} onCopy={onCopy} onError={setErr} />}
|
||
</SetGroup>
|
||
<DriveShareSection locale={locale} detail={detail} state={drives} toolsVersion={toolsVersion} />
|
||
<SharedFolderSection locale={locale} detail={detail} state={folders} toolsVersion={toolsVersion} />
|
||
<VMNetworkSettings name={detail.name} locale={locale} running={running} disabled={busy} stagedDirty={changed.length > 0} onBusy={setBusy} onSaved={onSaved} />
|
||
<SetGroup>
|
||
<SetRow
|
||
{...rowProps('ssh_port')}
|
||
title={tr('sshForward')}
|
||
desc={sshOn ? <code className="inline-code">{sshCommand(form.ssh_port ?? 0)}</code> : tr('sshOffDesc')}
|
||
disabled={!form.network}
|
||
reason={tr(detail.network_mode === 'bridge' ? 'sshNeedsNAT' : 'sshNeedsNetwork')}
|
||
control={
|
||
<div className="hstack">
|
||
{sshOn && (
|
||
<NumberField label={tr('sshPort')} value={form.ssh_port ?? 0} min={1} max={65535} onChange={(ssh_port) => set({ ssh_port })} />
|
||
)}
|
||
<Switch
|
||
label={tr('sshForward')}
|
||
checked={sshOn}
|
||
onChange={(on) => set({ ssh_port: on ? (base.ssh_port || 2222) : 0 })}
|
||
/>
|
||
</div>
|
||
}
|
||
/>
|
||
</SetGroup>
|
||
</>
|
||
)
|
||
|
||
const hostAudio = host.audio
|
||
const audioOutSummary = hostAudio
|
||
? hostAudio.output_count > 0
|
||
? `${hostAudio.output_count}${hostAudio.output_devices?.length ? ` · ${hostAudio.output_devices.slice(0, 2).join(', ')}` : ''}`
|
||
: tr('hostAudioMissingOut')
|
||
: '—'
|
||
const audioInSummary = hostAudio
|
||
? hostAudio.input_count > 0
|
||
? `${hostAudio.input_count}${hostAudio.input_devices?.length ? ` · ${hostAudio.input_devices.slice(0, 2).join(', ')}` : ''}`
|
||
: tr('hostAudioMissingIn')
|
||
: '—'
|
||
|
||
const input = (
|
||
<>
|
||
{detail.capture_supported && (
|
||
<SetGroup title={tr('catInput')}>
|
||
<SetRow
|
||
{...rowProps('capture')}
|
||
title={tr('captureInput')}
|
||
desc={tr('captureInputHint')}
|
||
control={<Switch label={tr('captureInput')} checked={!!form.capture} onChange={(capture) => set({ capture })} />}
|
||
/>
|
||
</SetGroup>
|
||
)}
|
||
<KeymapSection locale={locale} vm={detail.name} state={keymap} captureSupported={detail.capture_supported} />
|
||
<VMPluginGroup locale={locale} group="keyboard" state={plugins} />
|
||
<SetGroup title={tr('catAudio')} note={tr('audioTroubleshootNote')}>
|
||
<SetRow
|
||
{...rowProps('audio')}
|
||
title={tr('enableAudio')}
|
||
desc={tr('audioDesc')}
|
||
control={<Switch label={tr('enableAudio')} checked={!!form.audio} onChange={(audio) => set({ audio })} />}
|
||
/>
|
||
<SetRow
|
||
{...rowProps('audio_backend')}
|
||
title={tr('audioBackendTitle')}
|
||
desc={tr('audioBackendDesc')}
|
||
disabled={!form.audio}
|
||
reason={tr('audioDisabledReason')}
|
||
control={
|
||
<Segmented
|
||
label={tr('audioBackendTitle')}
|
||
value={form.audio_backend || 'auto'}
|
||
onChange={(audio_backend) => set({ audio_backend })}
|
||
options={[
|
||
{ value: 'auto', label: tr('audioBackendAuto') },
|
||
{ value: 'dsound', label: tr('audioBackendDsound') },
|
||
{ value: 'none', label: tr('audioBackendNone') },
|
||
// A backend set elsewhere (`reims-ctl set --audio-backend wav`) still shows as chosen.
|
||
...(['auto', 'dsound', 'none'].includes(form.audio_backend || 'auto') ? [] : [{ value: form.audio_backend as string, label: form.audio_backend as string }]),
|
||
]}
|
||
/>
|
||
}
|
||
/>
|
||
{hostAudio && (
|
||
<>
|
||
<SetValue title={tr('hostAudioOutput')} value={audioOutSummary} />
|
||
<SetValue title={tr('hostAudioInput')} value={audioInSummary} />
|
||
</>
|
||
)}
|
||
</SetGroup>
|
||
</>
|
||
)
|
||
|
||
const advanced = (
|
||
<>
|
||
<SetGroup title={tr('catLogs')}>
|
||
<SetRow
|
||
{...rowProps('logs')}
|
||
title={tr('enableLogs')}
|
||
control={<Switch label={tr('enableLogs')} checked={!!form.logs} onChange={(logs) => set({ logs })} />}
|
||
/>
|
||
<SetRow
|
||
{...rowProps('log_level')}
|
||
title={tr('logLevel')}
|
||
desc={tr('logLevelDesc')}
|
||
block={
|
||
<div className="stack-2">
|
||
<Segmented
|
||
label={tr('logLevel')}
|
||
value={customLog ? CUSTOM : (form.log_level || 'info')}
|
||
onChange={(v) => {
|
||
if (v === CUSTOM) { setCustomLog(true); return }
|
||
setCustomLog(false)
|
||
set({ log_level: v })
|
||
}}
|
||
options={[...LOG_LEVELS.map((l) => ({ value: l as string, label: l })), { value: CUSTOM, label: tr('logLevelCustom') }]}
|
||
/>
|
||
{customLog && (
|
||
<input
|
||
className="input rg-p-input mono"
|
||
aria-label={tr('logLevel')}
|
||
placeholder="info,reims=debug"
|
||
value={form.log_level ?? ''}
|
||
onChange={(e) => set({ log_level: e.target.value })}
|
||
/>
|
||
)}
|
||
</div>
|
||
}
|
||
/>
|
||
</SetGroup>
|
||
<SetGroup title={tr('groupQemu')}>
|
||
<SetRow
|
||
{...rowProps('stop_timeout')}
|
||
title={tr('stopTimeout')}
|
||
desc={tr('stopTimeoutHint')}
|
||
control={<NumberField label={tr('stopTimeout')} value={form.stop_timeout ?? 90} min={0} max={3600} unit={tr('secondsUnit')} onChange={(stop_timeout) => set({ stop_timeout })} />}
|
||
/>
|
||
<SetRow
|
||
{...rowProps('extra_args')}
|
||
title={tr('extraArgs')}
|
||
desc={tr('extraArgsDesc')}
|
||
block={<input className="input rg-p-input mono" aria-label={tr('extraArgs')} value={form.extra_args ?? ''} onChange={(e) => set({ extra_args: e.target.value })} />}
|
||
/>
|
||
</SetGroup>
|
||
</>
|
||
)
|
||
|
||
const pages: Record<Cat, React.ReactNode> = { general, compute, display: displayPage, storage, input, advanced }
|
||
|
||
return (
|
||
<>
|
||
<Modal
|
||
className="settings-dialog"
|
||
title={tr('settingsTitle', { name: detail.name })}
|
||
subtitle={`${tr(running ? 'state_running' : 'state_stopped')} · ${tr('appliesNextStart')}`}
|
||
closeLabel={tr('close')}
|
||
dismissable={!busy && !displayBusy && !tzBusy && !folders.confirmRWFolder}
|
||
onClose={onClose}
|
||
>
|
||
<div className="settings-split" onKeyDown={onKeyDown}>
|
||
<nav className="settings-nav" aria-label={tr('settings')}>
|
||
{CATS.map((c) => {
|
||
const n = changedIn(c.id)
|
||
const bad = issueIn(c.id)
|
||
const Icon = c.icon
|
||
return (
|
||
<button
|
||
key={c.id}
|
||
type="button"
|
||
className="nav-item rg-p-nav-item"
|
||
aria-current={cat === c.id ? 'page' : undefined}
|
||
onClick={() => setCat(c.id)}
|
||
>
|
||
<span className={`nav-icon-badge nav-icon-cat-${c.id}`} aria-hidden="true"><Icon size={14} /></span>
|
||
<span className="nav-label">{tr(c.label)}</span>
|
||
{bad
|
||
? <CircleAlert size={14} className="nav-issue" aria-label={tr('navHasIssue')} />
|
||
: n > 0 && <span className="nav-count" aria-label={tr('pendingChanges', { n })}>{n}</span>}
|
||
</button>
|
||
)
|
||
})}
|
||
</nav>
|
||
|
||
<div className="settings-pane" ref={pane}>
|
||
<h2 className="settings-pane-title">{tr(CATS.find((c) => c.id === cat)!.label)}</h2>
|
||
{err && <div className="notice notice-error">{err}</div>}
|
||
{strayIssues.length > 0 && (
|
||
<div className="notice notice-error">
|
||
<ul>{strayIssues.map((i) => <li key={i.field + i.code}>{i.message}</li>)}</ul>
|
||
</div>
|
||
)}
|
||
<div key={cat} className="pane-anim">{pages[cat]}</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="dialog-foot">
|
||
<span className="foot-status" aria-live="polite">
|
||
{changedCount > 0
|
||
? <><span className="dirty-dot" aria-hidden="true" />{tr('pendingChanges', { n: changedCount })}</>
|
||
: <span className="muted">{tr('noChanges')}</span>}
|
||
{changedCount > 0 && (
|
||
<button type="button" className="link-btn" disabled={busy} onClick={resetAll}>{tr('resetAll')}</button>
|
||
)}
|
||
</span>
|
||
<span className="hstack">
|
||
<Button variant="ghost" disabled={busy || displayBusy || tzBusy} onClick={onClose}>{tr('cancel')}</Button>
|
||
<Button variant="primary" busy={busy} disabled={displayBusy || tzBusy || changed.length === 0 || localBlock} onClick={handleSave} title="Ctrl+S">
|
||
{tr('save')}
|
||
</Button>
|
||
</span>
|
||
</div>
|
||
{smbios.smbiosOpen && <SMBIOSDialog locale={locale} state={smbios} onCopy={onCopy} />}
|
||
</Modal>
|
||
<WritableFolderDialog locale={locale} state={folders} />
|
||
</>
|
||
)
|
||
}
|