Align the Wails desktop shell with the macOS Tahoe visual design: - Add bundled open-source Inter Variable (Latin) and multi-weight CJK font mapping tuned for Windows DirectWrite readability - Refine VMPage with compact Studio Display stand, 2x3 icon spec card, inline telemetry meters, single-row Connection list, numbered install guide, and one-click tech summary copy - Move LogPanel to full-width status bar with ambient WHPX status and pointer-captured vertical resize handle - Upgrade HostView tiles, InstallersPage skeletons/empty state, system theme detection, and unified Segmented/Switch primitives - Refine translucent chrome surfaces, GPU scaleX meters/progress, toast swipe/enter motion, and reduced-motion/transparency/contrast support
245 lines
9.4 KiB
TypeScript
245 lines
9.4 KiB
TypeScript
import { FolderOpen, HardDrive } from 'lucide-react'
|
||
import React, { useEffect, useState } from 'react'
|
||
import { I18nKey, t } from '../i18n'
|
||
import { AppState, DataRootCheck, DataRootChoice, Locale, RuntimeSource, Task } from '../types'
|
||
import { Button } from '../ui/controls'
|
||
import { Segmented } from '../ui/settings'
|
||
import { recommendedMemoryGB, shortGPUName } from '../lib/format'
|
||
import { api } from '../wails'
|
||
import { RuntimeOnline } from './RuntimeOnline'
|
||
|
||
interface Props {
|
||
locale: Locale
|
||
state: AppState
|
||
stage: 'folder' | 'runtime'
|
||
runtimeTask: Task | null
|
||
onLocale: (l: Locale) => void
|
||
onFolderDone: () => void
|
||
onFinish: () => void
|
||
onError: (title: string, e: unknown) => void
|
||
onChannel: (alpha: boolean) => void
|
||
onSource: (source: RuntimeSource) => void
|
||
onInstallRuntime: (commit: string) => void
|
||
onCancelTask: (id: string) => void
|
||
onImportRuntime: () => void
|
||
}
|
||
|
||
const LOW_SPACE_GB = 60
|
||
|
||
/** First launch: choose the data folder, then (optionally) install the runtime. */
|
||
export const Setup: React.FC<Props> = (p) => {
|
||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(p.locale, k, v)
|
||
return (
|
||
<div className="setup">
|
||
<div className="setup-card">
|
||
{p.stage === 'folder' ? <FolderStep {...p} tr={tr} /> : <RuntimeStep {...p} tr={tr} />}
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
type StepProps = Props & { tr: (k: I18nKey, v?: Record<string, string | number>) => string }
|
||
|
||
const FolderStep: React.FC<StepProps> = ({ locale, tr, onLocale, onFolderDone, onError }) => {
|
||
const [choices, setChoices] = useState<DataRootChoice[]>([])
|
||
const [custom, setCustom] = useState('')
|
||
const [customMode, setCustomMode] = useState(false)
|
||
const [selected, setSelected] = useState('')
|
||
const [check, setCheck] = useState<DataRootCheck | null>(null)
|
||
const [busy, setBusy] = useState(false)
|
||
|
||
useEffect(() => {
|
||
api.SuggestDataRoots().then((list) => {
|
||
const l = list ?? []
|
||
setChoices(l)
|
||
const rec = l.find((c) => c.recommended) ?? l[0]
|
||
if (rec) setSelected(rec.path)
|
||
}).catch((e) => onError(tr('failGeneric'), e))
|
||
}, [])
|
||
|
||
useEffect(() => {
|
||
if (!selected) { setCheck(null); return }
|
||
let live = true
|
||
api.CheckDataRoot(selected).then((c) => { if (live) setCheck(c) }).catch(() => {})
|
||
return () => { live = false }
|
||
}, [selected])
|
||
|
||
const browse = async () => {
|
||
const dir = await api.PickDirectory(tr('setupTitle')).catch(() => '')
|
||
if (dir) { setCustom(dir); setCustomMode(true); setSelected(dir) }
|
||
}
|
||
|
||
const next = async () => {
|
||
setBusy(true)
|
||
try {
|
||
await api.CompleteSetup(selected)
|
||
onFolderDone()
|
||
} catch (e) {
|
||
onError(tr('failGeneric'), e)
|
||
} finally {
|
||
setBusy(false)
|
||
}
|
||
}
|
||
|
||
const option = (path: string, meta: React.ReactNode) => (
|
||
<label key={path} className="choice-card" data-selected={selected === path}>
|
||
<input type="radio" name="data-root" checked={selected === path} onChange={() => setSelected(path)} />
|
||
<HardDrive size={18} aria-hidden="true" />
|
||
<span className="choice-card-main">
|
||
<span className="mono choice-card-path">{path}</span>
|
||
<span className="choice-card-meta">{meta}</span>
|
||
</span>
|
||
</label>
|
||
)
|
||
|
||
const notices: string[] = []
|
||
if (check?.error) notices.push(check.error)
|
||
else if (check) {
|
||
if (check.system) notices.push(tr('setupWarnSystem'))
|
||
if (check.external) notices.push(tr('setupWarnExternal'))
|
||
if (check.free_gb > 0 && check.free_gb < LOW_SPACE_GB) notices.push(tr('setupWarnSpace'))
|
||
}
|
||
|
||
return (
|
||
<>
|
||
<div className="setup-head">
|
||
<h1>{tr('setupTitle')}</h1>
|
||
<p>{tr('setupDesc')}</p>
|
||
</div>
|
||
<div className="choices-list" role="radiogroup" aria-label={tr('setupTitle')}>
|
||
{choices.map((c) => option(c.path, (
|
||
<>
|
||
{tr('setupFree', { n: c.free_gb.toFixed(0) })}
|
||
{c.recommended && <span className="badge badge-accent">{tr('setupRecommended')}</span>}
|
||
{c.system && <span className="badge">{tr('setupSystem')}</span>}
|
||
{c.external && <span className="badge badge-warn">{tr('setupExternal')}</span>}
|
||
</>
|
||
)))}
|
||
{customMode ? (
|
||
<div className="input-group">
|
||
<input
|
||
className="input mono"
|
||
aria-label={tr('setupOther')}
|
||
value={custom}
|
||
placeholder="D:\VMs\reims-go"
|
||
spellCheck={false}
|
||
autoComplete="off"
|
||
autoFocus
|
||
onFocus={() => custom && setSelected(custom)}
|
||
onChange={(e) => { setCustom(e.target.value); setSelected(e.target.value.trim()) }}
|
||
/>
|
||
<Button icon={<FolderOpen size={14} />} onClick={browse}>{tr('choose')}</Button>
|
||
</div>
|
||
) : (
|
||
<Button variant="ghost" icon={<FolderOpen size={14} />} onClick={() => setCustomMode(true)} className="choice-other">{tr('setupOther')}</Button>
|
||
)}
|
||
</div>
|
||
{notices.length > 0 && (
|
||
<div className={check?.error ? 'notice notice-error' : 'hint warn'}>{notices.join(';')}</div>
|
||
)}
|
||
{!check?.error && check?.has_config && <div className="hint">{tr('setupReuse')}</div>}
|
||
{customMode && check && check.path === custom && !check.error && (
|
||
<div className="hint">{tr('setupFree', { n: check.free_gb.toFixed(0) })}</div>
|
||
)}
|
||
<div className="setup-foot">
|
||
<Segmented
|
||
label={tr('language')}
|
||
value={locale}
|
||
onChange={onLocale}
|
||
options={[
|
||
{ value: 'zh-CN', label: '中文' },
|
||
{ value: 'en-US', label: 'English' },
|
||
]}
|
||
/>
|
||
<Button variant="primary" busy={busy} disabled={!selected || !!check?.error} onClick={next}>{tr('setupContinue')}</Button>
|
||
</div>
|
||
</>
|
||
)
|
||
}
|
||
|
||
const RuntimeStep: React.FC<StepProps> = ({ locale, tr, state, runtimeTask, onChannel, onSource, onInstallRuntime, onCancelTask, onImportRuntime, onFinish, onError }) => {
|
||
const ready = !!state.active_runtime
|
||
const { host } = state
|
||
const [enabling, setEnabling] = useState(false)
|
||
const enableWHPX = async () => {
|
||
setEnabling(true)
|
||
try { await api.EnableWHPX() } catch (e) { onError(tr('failGeneric'), e) } finally { setEnabling(false) }
|
||
}
|
||
const whpxOK = host.whpx === 'ready'
|
||
const gpu = host.recommended_gpu ?? (host.gpus ?? []).find((g) => g.kind !== 'virtual')
|
||
const recMem = recommendedMemoryGB(host)
|
||
return (
|
||
<>
|
||
<div className="setup-head">
|
||
<h1>{tr('setupRuntimeTitle')}</h1>
|
||
<p>{tr('setupRuntimeDesc')}</p>
|
||
</div>
|
||
<section className="section">
|
||
<div className="section-title">{tr('setupCheck')}</div>
|
||
<div className="list">
|
||
<div className="row">
|
||
<div className="row-main">
|
||
<div className="row-title">{tr('hostWHPX')}</div>
|
||
{!whpxOK && (
|
||
<div className="row-sub">
|
||
{tr(host.whpx === 'missing' ? 'whpxMissing' : host.whpx === 'no_hypervisor' ? 'whpxNoHv' : 'whpxUnsupported')}
|
||
</div>
|
||
)}
|
||
</div>
|
||
<div className="row-right">
|
||
{host.whpx === 'missing' ? (
|
||
<Button variant="primary" busy={enabling} onClick={enableWHPX}>{tr('enableWHPX')}</Button>
|
||
) : (
|
||
<span className={`badge ${whpxOK ? 'badge-ok' : 'badge-warn'}`}>
|
||
{tr(whpxOK ? 'whpxReady' : host.whpx === 'no_hypervisor' ? 'whpxNoHvShort' : 'whpxUnsupportedShort')}
|
||
</span>
|
||
)}
|
||
</div>
|
||
</div>
|
||
<div className="row">
|
||
<div className="row-main">
|
||
<div className="row-title">{tr('setupGPU')}</div>
|
||
<div className="row-sub">{gpu ? shortGPUName(gpu.name) : tr('setupNoGPU')}</div>
|
||
</div>
|
||
<div className="row-right">
|
||
<span className={`badge ${gpu ? 'badge-ok' : 'badge-warn'}`}>{tr(gpu ? 'whpxReady' : 'hostNeedsAction')}</span>
|
||
</div>
|
||
</div>
|
||
<div className="row">
|
||
<div className="row-main">
|
||
<div className="row-title">{tr('hostRAM')}</div>
|
||
<div className="row-sub">
|
||
{host.commit_avail_gb > 0
|
||
? tr('memCommitHint', { avail: host.commit_avail_gb.toFixed(1), rec: recMem })
|
||
: tr('hostRAMTotal', { n: host.total_ram_gb.toFixed(1) })}
|
||
</div>
|
||
</div>
|
||
<div className="row-right">
|
||
<span className={`badge ${recMem >= 8 ? 'badge-ok' : 'badge-warn'}`}>{tr('setupRecMem', { n: recMem })}</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<div className="list">
|
||
<RuntimeOnline
|
||
locale={locale}
|
||
channel={state.config.runtime_channel === 'alpha' ? 'alpha' : 'stable'}
|
||
source={state.config.runtime_source === 'github' || state.config.runtime_source === 'gitcode' ? state.config.runtime_source : 'auto'}
|
||
installed={state.runtimes ?? []}
|
||
task={runtimeTask}
|
||
onChannel={onChannel}
|
||
onSource={onSource}
|
||
onInstall={onInstallRuntime}
|
||
onCancel={onCancelTask}
|
||
/>
|
||
</div>
|
||
<div className="setup-foot">
|
||
<Button variant="ghost" onClick={onImportRuntime}>{tr('setupImport')}</Button>
|
||
<Button variant={ready ? 'primary' : 'secondary'} disabled={runtimeTask?.status === 'running'} onClick={onFinish}>
|
||
{tr(ready ? 'setupDone' : 'setupLater')}
|
||
</Button>
|
||
</div>
|
||
</>
|
||
)
|
||
}
|