Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05cc34cbaa | ||
|
|
3f8cf11d3d | ||
|
|
404090d8ed |
No files matched your search
@@ -302,7 +302,17 @@ func (a *App) ValidateCreate(opts reims.CreateOpts) []reims.ValidationIssue {
|
||||
a.mu.Lock()
|
||||
root := a.cfg.DataRoot
|
||||
a.mu.Unlock()
|
||||
return reims.ValidateCreate(opts, host.Inspect(root))
|
||||
issues := reims.ValidateCreate(opts, host.Inspect(root))
|
||||
// reims-ctl refuses a name already registered; say so before the create runs.
|
||||
if vms, err := a.listVMsInternal(context.Background()); err == nil {
|
||||
for _, vm := range vms {
|
||||
if strings.EqualFold(vm.Name, strings.TrimSpace(opts.Name)) {
|
||||
issues = append(issues, reims.ValidationIssue{Field: "name", Code: "name_taken", Message: "A VM named " + vm.Name + " already exists"})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return issues
|
||||
}
|
||||
|
||||
func (a *App) PreviewCreate(opts reims.CreateOpts) (string, error) {
|
||||
@@ -485,6 +495,10 @@ func (a *App) StartVM(name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.checkStartMemory(c, name); err != nil {
|
||||
a.emitLog(name, "Start refused: "+err.Error())
|
||||
return err
|
||||
}
|
||||
a.cancelRebootWatcher(name)
|
||||
|
||||
var qmpAddr string
|
||||
|
||||
+5
-1
@@ -66,8 +66,12 @@ flowchart LR
|
||||
|
||||
- [ ] **M2.1**:**首次启动向导(中英双语实时切换)** — 自动识别系统语言(支持顶部一键切换 `中文 / English`);展示环境体检卡片(WHPX、**提交内存与推荐 RAM**、显卡、磁盘);WHPX 未开时提供「一键提权启用并重启」按钮;引导选择非 C 盘数据目录并一键安装/导入便携运行时。
|
||||
- 2026-11-28 已完成一部分。首次启动先选数据目录:推荐有空间的非系统盘,USB 外置盘排在最后并标出风险,也可以手填路径;选好后进入运行时在线安装,这一步可以跳过。已有安装会被直接沿用,不再询问。选择结果记在 `%APPDATA%\reims-go\location.json`(只有这一个小文件放在数据目录之外)。环境体检卡片和一键启用 WHPX 还没并进这个流程。
|
||||
- [ ] **M2.2**:**离线安装包下载管理器(核心体验)** — 调用 `reims-util --json` 展示可选 macOS Tahoe 精确版本,在 GUI 内直接触发宿主机直连下载、实时显示进度条 / 速率 / 已下体积 / 自动重试状态、支持「暂停/取消」与「断点续传」,并可视化管理 `<DataRoot>\data\reims-ctl\installers` 缓存。
|
||||
- 2026-11-28(v0.2):选好目录后的那一步加了环境检查,包括 WHPX(未启用时可以一键启用,会弹 UAC)、Vulkan 显卡、内存(按 Windows 可分配内存推荐大小),之后再在线安装运行时。
|
||||
- [x] **M2.2**:**离线安装包下载管理器(核心体验)** — 调用 `reims-util --json` 展示可选 macOS Tahoe 精确版本,在 GUI 内直接触发宿主机直连下载、实时显示进度条 / 速率 / 已下体积 / 自动重试状态、支持「暂停/取消」与「断点续传」,并可视化管理 `<DataRoot>\data\reims-ctl\installers` 缓存。
|
||||
- 2026-11-28(v0.2):侧边栏新增「安装包」页。上半部分是已下载的安装包:可以继续未下载完的、删除(两步确认,删除走 `reims-ctl downloads delete`)。下半部分是 Apple 提供的版本:下载、进度、暂停。下载前检查剩余空间(按安装包大小加 10% 计,因为一开始就会占满整个镜像的空间)。速率显示在进度的悬停提示里。暂停后再次下载会接着下。
|
||||
- [ ] **M2.3**:**VM 主面板与创建/装机引导(贴合简体中文 / 英文 macOS 界面术语)** — 实例列表、实时状态、一键启停与串口/图形日志抽屉;新建默认推荐复用本地离线包(附 `--network false`,启动前校验提交内存),装机侧边栏展示离线安装 3 步引导(抹盘 APFS → `sh /Volumes/Installer/install-macos.sh` → 一键 **弹出安装盘并恢复网络**)。
|
||||
- 2026-11-28(v0.2):新建助手默认改为「离线安装包(推荐)」,执行 `reims-ctl create --macos <版本> --offline --network false`。版本列表来自 Apple,已下载的会标出来。这样建的 VM,装机引导改为三步:抹盘、在终端运行 `sh /Volumes/Installer/install-macos.sh`(命令可以一键复制)、点「完成安装」(弹出安装盘并打开网络,下次启动生效)。
|
||||
- 可分配内存检查:体检会读取 Windows 的可分配内存(commit)上限和当前剩余。新建和修改设置时超过上限的会被拦下;启动前如果「内存 + 1 GB」超过当前剩余,就拒绝启动,并说明原因和推荐的大小。新建助手、设置面板、首次启动页都会显示推荐值。M1.1 和 M2.5 里要求的提交内存检查也是这一项。
|
||||
- [ ] **M2.4**:打包为单文件 `reims-go.exe`(验证体积与冷启动速度)。
|
||||
- 2026-11-28:`wails build -trimpath` 产出 12.7 MB 的单文件,命令行版 7.7 MB,作为 [v0.1.0](https://github.com/Nwflower/reims-go/releases/tag/v0.1.0) 发布。没有代码签名,首次运行会被 SmartScreen 拦截一次。冷启动时间还没测。
|
||||
- [ ] **M2.5**:**设置面板(对齐 macOS)** — 按 [`shell-design.md`](shell-design.md) 第 3 节的类别分页(平台、引导、CPU、内存、存储、网络、图形与显示器、音频、键盘与指针、串口与日志、高级);VM 运行中也能打开、能改,每个字段标出生效时机;保存前先在 Go 里校验(含提交内存与 ICD 检查),再调用 `reims-ctl set` 写入;平台类字段只读且脱敏。
|
||||
|
||||
+40
-10
@@ -1,17 +1,18 @@
|
||||
import { Minus, Moon, Square, Sun, X } from 'lucide-react'
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { CreateWizard } from './components/CreateWizard'
|
||||
import { CreateWizard, WizardDraft } from './components/CreateWizard'
|
||||
import { DeleteDialog } from './components/DeleteDialog'
|
||||
import { HostView } from './components/HostView'
|
||||
import { LogPanel, LogTab } from './components/LogPanel'
|
||||
import { SettingsModal } from './components/SettingsModal'
|
||||
import { Setup } from './components/Setup'
|
||||
import { HOST_ID, Sidebar } from './components/Sidebar'
|
||||
import { HOST_ID, INSTALLERS_ID, Sidebar } from './components/Sidebar'
|
||||
import { InstallersPage } from './components/InstallersPage'
|
||||
import { VMAction, VMPage } from './components/VMPage'
|
||||
import { I18nKey, t } from './i18n'
|
||||
import { LogLine, appendLog } from './lib/logs'
|
||||
import { currentTask, upsertTask } from './lib/tasks'
|
||||
import { AppState, Locale, Task, VMDetail } from './types'
|
||||
import { AppState, CreateOpts, Locale, Task, VMDetail } from './types'
|
||||
import { TooltipProvider } from './ui/controls'
|
||||
import { Toaster, useToasts } from './ui/toast'
|
||||
import { backend } from './wails'
|
||||
@@ -24,6 +25,7 @@ const failKey: Record<VMAction, I18nKey> = {
|
||||
forceStop: 'failStop',
|
||||
restart: 'failRestart',
|
||||
eject: 'failEject',
|
||||
finishInstall: 'failFinishInstall',
|
||||
delete: 'failDelete',
|
||||
openFolder: 'failOpenFolder',
|
||||
}
|
||||
@@ -33,6 +35,7 @@ export const App: React.FC = () => {
|
||||
const [selected, setSelected] = useState<string>(HOST_ID)
|
||||
const [detail, setDetail] = useState<VMDetail | null>(null)
|
||||
const [showWizard, setShowWizard] = useState(false)
|
||||
const [wizardDraft, setWizardDraft] = useState<WizardDraft | null>(null)
|
||||
const [showSettings, setShowSettings] = useState(false)
|
||||
const [deleteTarget, setDeleteTarget] = useState<string | null>(null)
|
||||
const [busy, setBusy] = useState<Record<string, VMAction>>({})
|
||||
@@ -66,7 +69,7 @@ export const App: React.FC = () => {
|
||||
setState(s)
|
||||
setLoadError('')
|
||||
setSelected((cur) => {
|
||||
if (cur === HOST_ID) return cur
|
||||
if (cur === HOST_ID || cur === INSTALLERS_ID) return cur
|
||||
if ((s.vms ?? []).some((v) => v.name === cur)) return cur
|
||||
return s.vms && s.vms.length > 0 ? s.vms[0].name : HOST_ID
|
||||
})
|
||||
@@ -201,6 +204,7 @@ export const App: React.FC = () => {
|
||||
case 'forceStop': return runVMAction(name, action, () => backend.stopVM(name, true), tr('toastStopped', { name }))
|
||||
case 'restart': return runVMAction(name, action, () => backend.restartVM(name))
|
||||
case 'eject': return runVMAction(name, action, () => backend.ejectInstaller(name), tr('toastEjected'))
|
||||
case 'finishInstall': return runVMAction(name, action, () => backend.finishInstall(name), tr('toastInstallFinished'))
|
||||
case 'openFolder':
|
||||
return backend.openVMFolder(name).catch((e) => fail(tr('failOpenFolder'), e))
|
||||
case 'delete': return setDeleteTarget(name)
|
||||
@@ -222,6 +226,26 @@ export const App: React.FC = () => {
|
||||
setShowWizard(true)
|
||||
}
|
||||
|
||||
// The wizard closes as soon as the create starts; progress lives in the status bar
|
||||
// (vm-create task). On failure the toast reopens the wizard with the same answers.
|
||||
const submitCreate = (payload: CreateOpts, draft: WizardDraft) => {
|
||||
setShowWizard(false)
|
||||
setWizardDraft(null)
|
||||
const name = payload.name
|
||||
backend.createVM(payload)
|
||||
.then(() => {
|
||||
toasts.push({ kind: 'ok', title: tr('toastCreated', { name }) })
|
||||
setSelected(name)
|
||||
return refresh()
|
||||
})
|
||||
.catch((e) => toasts.push({
|
||||
kind: 'error',
|
||||
title: tr('failCreate', { name }),
|
||||
description: errText(e),
|
||||
action: { label: tr('backToEdit'), onClick: () => { setWizardDraft(draft); setShowWizard(true) } },
|
||||
}))
|
||||
}
|
||||
|
||||
const copy = async (text: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
@@ -303,6 +327,7 @@ export const App: React.FC = () => {
|
||||
hostReady={hostReady}
|
||||
onSelect={setSelected}
|
||||
onNew={openWizard}
|
||||
downloading={Object.values(taskMap).some((x) => x.kind === 'installer-download' && x.status === 'running')}
|
||||
/>
|
||||
|
||||
<main className="main">
|
||||
@@ -311,6 +336,14 @@ export const App: React.FC = () => {
|
||||
<div className="page">
|
||||
{loadError ? <div className="notice notice-error">{loadError}</div> : <span className="muted">…</span>}
|
||||
</div>
|
||||
) : selected === INSTALLERS_ID ? (
|
||||
<InstallersPage
|
||||
locale={locale}
|
||||
host={state.host}
|
||||
tasks={Object.values(taskMap)}
|
||||
onError={fail}
|
||||
onToast={(title) => toasts.push({ kind: 'ok', title })}
|
||||
/>
|
||||
) : selectedVM ? (
|
||||
<VMPage
|
||||
locale={locale}
|
||||
@@ -365,12 +398,9 @@ export const App: React.FC = () => {
|
||||
<CreateWizard
|
||||
locale={locale}
|
||||
host={state.host}
|
||||
onClose={() => setShowWizard(false)}
|
||||
onCreated={(name) => {
|
||||
setShowWizard(false)
|
||||
setSelected(name)
|
||||
refresh()
|
||||
}}
|
||||
draft={wizardDraft}
|
||||
onClose={() => { setShowWizard(false); setWizardDraft(null) }}
|
||||
onSubmit={submitCreate}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -1,35 +1,59 @@
|
||||
import { Check } from 'lucide-react'
|
||||
import { ChevronRight, CircleAlert, CircleCheck, Check, Copy } from 'lucide-react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { I18nKey, t } from '../i18n'
|
||||
import { shortGPUName } from '../lib/format'
|
||||
import { CreateOpts, HostReport, Locale, ValidationIssue } from '../types'
|
||||
import { Button } from '../ui/controls'
|
||||
import { formatMemory, gpuLabel, recommendedMemoryGB, shortGPUName } from '../lib/format'
|
||||
import { CachedInstaller, CreateOpts, HostReport, Locale, Release, ValidationIssue } from '../types'
|
||||
import { Button, IconButton } from '../ui/controls'
|
||||
import { Modal } from '../ui/dialog'
|
||||
import { backend } from '../wails'
|
||||
|
||||
/** 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
|
||||
draft?: WizardDraft | null
|
||||
onClose: () => void
|
||||
onCreated: (name: string) => void
|
||||
/** Called with the cleaned payload; the caller runs the create in the background. */
|
||||
onSubmit: (payload: CreateOpts, draft: WizardDraft) => void
|
||||
}
|
||||
|
||||
export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated }) => {
|
||||
const REVIEW_STEP = 5
|
||||
|
||||
// Which wizard step owns each ValidationIssue.field (internal/driver/reims/reims.go ValidateCreate).
|
||||
const STEP_OF_FIELD: Record<string, number> = {
|
||||
name: 1, installer: 1, disk: 1, macos: 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
|
||||
|
||||
export const CreateWizard: React.FC<Props> = ({ locale, host, draft, onClose, onSubmit }) => {
|
||||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||||
const [step, setStep] = useState(1)
|
||||
const [busy, setBusy] = useState(false)
|
||||
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 [opts, setOpts] = useState<CreateOpts>({
|
||||
const [opts, setOpts] = useState<CreateOpts>(draft?.opts ?? {
|
||||
name: 'macos-tahoe',
|
||||
dir: '',
|
||||
source_mode: 'apple',
|
||||
macos: 'tahoe',
|
||||
// Offline by default: one exact release that installs with no network
|
||||
// (roadmap M2.3; `reims-ctl create --help`, upstream 3731afd).
|
||||
source_mode: 'offline',
|
||||
macos: '',
|
||||
offline: true,
|
||||
installer: '',
|
||||
cpus: host.logical_cpus >= 12 ? 8 : 4,
|
||||
memory: host.total_ram_gb >= 24 ? '16G' : '8G',
|
||||
memory: `${recommendedMemoryGB(host)}G`,
|
||||
disk_size: '128G',
|
||||
disk: '',
|
||||
disk_mode: 'copy',
|
||||
@@ -39,7 +63,7 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated
|
||||
displays: 1,
|
||||
borderless: false,
|
||||
audio: true,
|
||||
network: true,
|
||||
network: false,
|
||||
ssh_port: 0,
|
||||
logs: true,
|
||||
start: true,
|
||||
@@ -47,8 +71,12 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated
|
||||
const set = (patch: Partial<CreateOpts>) => setOpts((o) => ({ ...o, ...patch }))
|
||||
|
||||
const buildPayload = (): CreateOpts => {
|
||||
const p: CreateOpts = { ...opts }
|
||||
if (p.source_mode === 'apple') {
|
||||
const p: CreateOpts = { ...opts, offline: opts.source_mode === 'offline' }
|
||||
if (p.source_mode === 'offline') {
|
||||
p.installer = ''
|
||||
p.disk = ''
|
||||
p.network = false
|
||||
} else if (p.source_mode === 'apple') {
|
||||
p.installer = ''
|
||||
p.disk = ''
|
||||
} else if (p.source_mode === 'installer') {
|
||||
@@ -63,15 +91,49 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (step !== 5) return
|
||||
const payload = buildPayload()
|
||||
Promise.all([backend.validateCreate(payload), backend.previewCreate(payload)])
|
||||
.then(([iss, cmd]) => {
|
||||
setIssues(iss ?? [])
|
||||
setCmdPreview(cmd)
|
||||
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
|
||||
backend.listInstallers().then((l) => { if (live) setCached(l ?? []) }).catch(() => {})
|
||||
backend.listOfflineReleases()
|
||||
.then((list) => {
|
||||
if (!live) return
|
||||
setReleases(list ?? [])
|
||||
if (!opts.macos && list && list.length > 0) set({ macos: list[0].version })
|
||||
})
|
||||
.catch((e) => setErr(String(e)))
|
||||
}, [step, opts])
|
||||
.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 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) ? 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([backend.validateCreate(payload), backend.previewCreate(payload)])
|
||||
.then(([iss, cmd]) => {
|
||||
if (!live) return
|
||||
setIssues(iss ?? [])
|
||||
setCmdPreview(cmd)
|
||||
setErr('')
|
||||
})
|
||||
.catch((e) => { if (live) setErr(String(e).replace(/^Error:\s*/, '')) })
|
||||
.finally(() => { if (live) setChecking(false) })
|
||||
}, 200)
|
||||
return () => { live = false; clearTimeout(timer) }
|
||||
}, [step, reviewed, opts])
|
||||
|
||||
const pickDir = async () => {
|
||||
const dir = await backend.pickDirectory(tr('vmDir'))
|
||||
@@ -83,19 +145,8 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated
|
||||
if (f) set({ [field]: f })
|
||||
}
|
||||
|
||||
const handleCreate = async () => {
|
||||
setErr('')
|
||||
setBusy(true)
|
||||
try {
|
||||
const payload = buildPayload()
|
||||
await backend.createVM(payload)
|
||||
onCreated(payload.name)
|
||||
} catch (e) {
|
||||
setErr(String(e).replace(/^Error:\s*/, ''))
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
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 steps: I18nKey[] = ['step1', 'step2', 'step3', 'step4', 'step5']
|
||||
@@ -111,20 +162,21 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated
|
||||
)
|
||||
|
||||
return (
|
||||
<Modal title={tr('wizardTitle')} closeLabel={tr('close')} dismissable={!busy} onClose={onClose}>
|
||||
<Modal 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${step > n ? ' done' : ''}`}
|
||||
className={`wizard-step${done ? ' done' : ''}${bad ? ' has-issue' : ''}`}
|
||||
aria-current={step === n ? 'step' : undefined}
|
||||
disabled={busy}
|
||||
onClick={() => setStep(n)}
|
||||
>
|
||||
{step > n && <Check size={12} />}
|
||||
{bad ? <CircleAlert size={12} /> : done && <Check size={12} />}
|
||||
{tr(key)}
|
||||
</button>
|
||||
)
|
||||
@@ -152,15 +204,19 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated
|
||||
|
||||
<fieldset className="field choices fieldset">
|
||||
<legend className="field-label">{tr('step1')}</legend>
|
||||
{(['apple', 'installer', 'disk'] as const).map((mode) => (
|
||||
{(['offline', 'apple', 'installer', 'disk'] as const).map((mode) => (
|
||||
<label key={mode} className="choice">
|
||||
<input
|
||||
type="radio"
|
||||
name="source"
|
||||
checked={opts.source_mode === mode}
|
||||
onChange={() => set({ source_mode: mode, ...(mode === 'apple' ? { macos: opts.macos || 'tahoe' } : {}) })}
|
||||
onChange={() => set({
|
||||
source_mode: mode,
|
||||
...(mode === 'apple' ? { macos: 'tahoe', network: true } : {}),
|
||||
...(mode === 'offline' ? { macos: releases?.[0]?.version ?? '', network: false } : {}),
|
||||
})}
|
||||
/>
|
||||
{tr(mode === 'apple' ? 'sourceApple' : mode === 'installer' ? 'sourceInstaller' : 'sourceDisk')}
|
||||
{tr(mode === 'offline' ? 'sourceOffline' : mode === 'apple' ? 'sourceApple' : mode === 'installer' ? 'sourceInstaller' : 'sourceDisk')}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
@@ -174,7 +230,30 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated
|
||||
</div>
|
||||
)}
|
||||
|
||||
{opts.source_mode !== 'apple' && (
|
||||
{opts.source_mode === 'offline' && (
|
||||
<div className="field">
|
||||
<label className="field-label" htmlFor="vm-release">{tr('macosVersion')}</label>
|
||||
{releasesErr ? (
|
||||
<div className="notice notice-error">{tr('offlineListFailed')}:{releasesErr}</div>
|
||||
) : !releases ? (
|
||||
<span className="hint">{tr('offlineLoading')}</span>
|
||||
) : (
|
||||
<select id="vm-release" className="select" value={opts.macos} onChange={(e) => set({ macos: e.target.value })}>
|
||||
{releases.map((r) => (
|
||||
<option key={r.product} value={r.version}>
|
||||
{r.title} {r.version} ({r.build}) · {(r.size / 1e9).toFixed(1)} GB{isCached(r.version) ? ` · ${tr('offlineCached')}` : ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
<span className="hint">{tr('offlineHint')}</span>
|
||||
{needGB > 0 && host.free_disk_gb > 0 && host.free_disk_gb < needGB + 10 && (
|
||||
<span className="hint warn">{tr('offlineSpaceWarn', { free: host.free_disk_gb.toFixed(0), need: needGB })}</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(opts.source_mode === 'installer' || opts.source_mode === 'disk') && (
|
||||
<div className="field">
|
||||
<label className="field-label" htmlFor="vm-src">
|
||||
{tr(opts.source_mode === 'installer' ? 'sourceInstaller' : 'sourceDisk')}
|
||||
@@ -216,7 +295,11 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated
|
||||
<label className="field-label" htmlFor="vm-mem">{tr('factMemory')} · {tr('hostMemory', { n: host.total_ram_gb.toFixed(0) })}</label>
|
||||
{presets(['4G', '8G', '12G', '16G', '24G'], opts.memory, (m) => m, (memory) => set({ memory }))}
|
||||
<input id="vm-mem" className="input" value={opts.memory} onChange={(e) => set({ memory: e.target.value })} />
|
||||
<span className="hint">{tr('memHint')}</span>
|
||||
<span className="hint">
|
||||
{host.commit_avail_gb > 0
|
||||
? tr('memCommitHint', { avail: host.commit_avail_gb.toFixed(1), rec: recommendedMemoryGB(host) })
|
||||
: tr('memHint')}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
@@ -314,40 +397,196 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, onClose, onCreated
|
||||
['start', 'startAfterCreate'],
|
||||
] as const).map(([key, label]) => (
|
||||
<label key={key} className="choice">
|
||||
<input type="checkbox" checked={!!opts[key]} onChange={(e) => set({ [key]: e.target.checked })} />
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!!opts[key]}
|
||||
disabled={key === 'network' && opts.source_mode === 'offline'}
|
||||
onChange={(e) => set({ [key]: e.target.checked })}
|
||||
/>
|
||||
{tr(label)}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
{opts.source_mode === 'offline' && <span className="hint">{tr('networkOfflineHint')}</span>}
|
||||
</>
|
||||
)}
|
||||
|
||||
{step === 5 && (
|
||||
<>
|
||||
{issues.length > 0 ? (
|
||||
<div className="notice notice-error">
|
||||
<ul>{issues.map((i) => <li key={i.field + i.code}>{i.message}</li>)}</ul>
|
||||
</div>
|
||||
) : (
|
||||
<span className="hint">{tr('validationPassed')}</span>
|
||||
)}
|
||||
<div className="field">
|
||||
<span className="field-label">{tr('commandPreview')}</span>
|
||||
<div className="code">{cmdPreview}</div>
|
||||
</div>
|
||||
{busy && <span className="hint">{tr('creating')}</span>}
|
||||
</>
|
||||
<Review
|
||||
locale={locale}
|
||||
host={host}
|
||||
opts={opts}
|
||||
issues={issues}
|
||||
checking={checking}
|
||||
command={cmdPreview}
|
||||
onEdit={setStep}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="dialog-foot">
|
||||
<Button variant="ghost" disabled={step === 1 || busy} onClick={() => setStep(step - 1)}>{tr('back')}</Button>
|
||||
{step < 5 ? (
|
||||
<Button variant="ghost" disabled={step === 1} onClick={() => setStep(step - 1)}>{tr('back')}</Button>
|
||||
{step < REVIEW_STEP ? (
|
||||
<Button variant="primary" onClick={() => setStep(step + 1)}>{tr('next')}</Button>
|
||||
) : (
|
||||
<Button variant="primary" busy={busy} disabled={issues.length > 0} onClick={handleCreate}>{tr('createNow')}</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
|
||||
}
|
||||
|
||||
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 }) => {
|
||||
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('vmName'), value: opts.name },
|
||||
{ label: tr('summarySource'), value: source },
|
||||
{ label: tr('vmDir'), value: opts.dir || tr('summaryDefaultDir'), mono: !!opts.dir },
|
||||
],
|
||||
},
|
||||
{
|
||||
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') }],
|
||||
},
|
||||
{
|
||||
step: 4,
|
||||
title: 'step4',
|
||||
rows: [
|
||||
...graphicsRows,
|
||||
{ label: tr('fieldAudio'), value: onOff(opts.audio) },
|
||||
{ label: tr('fieldNetwork'), value: onOff(opts.network) },
|
||||
{ label: tr('summarySSH'), value: opts.ssh_port ? tr('summarySSHPort', { n: opts.ssh_port }) : tr('off') },
|
||||
{ label: tr('summaryLogs'), value: onOff(opts.logs) },
|
||||
{ label: tr('summaryStartAfter'), value: onOff(opts.start) },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const general = issues.filter((i) => stepOfIssue(i) === REVIEW_STEP)
|
||||
|
||||
const copy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(command)
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 1500)
|
||||
} catch { /* clipboard unavailable; the text stays selectable */ }
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{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>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -78,14 +78,15 @@ export const HostView: React.FC<Props> = ({ state, locale, onRefresh, onError, o
|
||||
<div className="tile">
|
||||
<div className="tile-head"><ShieldCheck size={14} /> {tr('whpxTitle')}</div>
|
||||
<div className={`tile-value ${whpx.tone}`}>{whpx.short}</div>
|
||||
<div className="tile-sub">{host.os}/{host.arch}</div>
|
||||
{host.whpx === 'missing' ? (
|
||||
<Button variant="primary" className="tile-action" busy={enabling} onClick={enableWHPX}>{tr('enableWHPX')}</Button>
|
||||
) : whpx.hint ? (
|
||||
<div className="tile-sub" title={whpx.hint}>{whpx.hint}</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="tile">
|
||||
<div className="tile-head"><Cpu size={14} /> {tr('hostCPU')}</div>
|
||||
<div className="tile-value">{tr('hostCoresThreads', { c: host.physical_cores, t: host.logical_cpus })}</div>
|
||||
<div className="tile-sub">
|
||||
{host.has_hybrid_cores ? tr('hostHybrid', { p: host.p_core_count, e: host.e_core_count }) : tr('hostSymmetric')}
|
||||
</div>
|
||||
</div>
|
||||
<div className="tile">
|
||||
<div className="tile-head"><MemoryStick size={14} /> {tr('hostRAM')}</div>
|
||||
@@ -95,7 +96,6 @@ export const HostView: React.FC<Props> = ({ state, locale, onRefresh, onError, o
|
||||
<div className="tile">
|
||||
<div className="tile-head"><HardDrive size={14} /> {tr('hostDisk')}</div>
|
||||
<div className="tile-value">{host.free_disk_gb.toFixed(0)} GB</div>
|
||||
<div className="tile-sub mono">{config.data_root}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -116,48 +116,23 @@ export const HostView: React.FC<Props> = ({ state, locale, onRefresh, onError, o
|
||||
onInstall={onInstallRuntime}
|
||||
onCancel={onCancelTask}
|
||||
/>
|
||||
</div>
|
||||
<div className="list">
|
||||
{!runtimes || runtimes.length === 0 ? (
|
||||
<div className="row"><span className="row-sub">{tr('noRuntime')}</span></div>
|
||||
) : (
|
||||
runtimes.map((rt) => (
|
||||
<div className="row" key={rt.commit}>
|
||||
<div className="row-main">
|
||||
<div className="row-title">
|
||||
<span className="mono">{rt.commit}</span>
|
||||
<span className="muted">{rt.manifest.qemu_version}</span>
|
||||
{rt.active && <span className="badge badge-ok">{tr('activeBadge')}</span>}
|
||||
</div>
|
||||
<div className="row-sub mono">{rt.dir}</div>
|
||||
</div>
|
||||
{!rt.active && (
|
||||
<div className="row-right">
|
||||
<Button onClick={guard(() => backend.useRuntime(rt.commit))}>{tr('activate')}</Button>
|
||||
</div>
|
||||
)}
|
||||
{(runtimes ?? []).filter((rt) => !rt.active).map((rt) => (
|
||||
<div className="row" key={rt.commit}>
|
||||
<div className="row-main">
|
||||
<div className="row-title"><span className="mono">{rt.commit}</span></div>
|
||||
<div className="row-sub">{rt.manifest.qemu_version.replace(/^QEMU emulator version\s*/i, 'QEMU ')}</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
<div className="row-right">
|
||||
<Button onClick={guard(() => backend.useRuntime(rt.commit))}>{tr('activate')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="section">
|
||||
<div className="section-title">{tr('hostSystem')}</div>
|
||||
<div className="section-title">{tr('settings')}</div>
|
||||
<div className="list">
|
||||
<div className="row">
|
||||
<div className="row-main">
|
||||
<div className="row-title">{tr('hostWHPX')}</div>
|
||||
{whpx.hint && <div className="row-sub">{whpx.hint}</div>}
|
||||
</div>
|
||||
<div className="row-right">
|
||||
{host.whpx === 'missing' ? (
|
||||
<Button variant="primary" busy={enabling} onClick={enableWHPX}>{tr('enableWHPX')}</Button>
|
||||
) : (
|
||||
<span className={`badge ${whpx.tone === 'ok' ? 'badge-ok' : 'badge-warn'}`}>{whpx.short}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="row">
|
||||
<div className="row-main">
|
||||
<div className="row-title">{tr('hostDataRoot')}</div>
|
||||
@@ -169,7 +144,6 @@ export const HostView: React.FC<Props> = ({ state, locale, onRefresh, onError, o
|
||||
<div className="row">
|
||||
<div className="row-main">
|
||||
<div className="row-title">{tr('autoPinPCores')}</div>
|
||||
<div className="row-sub mono">{host.p_core_mask_hex}</div>
|
||||
</div>
|
||||
<div className="row-right">
|
||||
<label className="switch">
|
||||
@@ -184,6 +158,15 @@ export const HostView: React.FC<Props> = ({ state, locale, onRefresh, onError, o
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="row">
|
||||
<div className="row-main"><div className="row-title">{tr('language')}</div></div>
|
||||
<div className="row-right">
|
||||
<div className="segmented" role="group" aria-label={tr('language')}>
|
||||
<button type="button" aria-pressed={locale === 'zh-CN'} onClick={() => onSetLocale('zh-CN')}>中文</button>
|
||||
<button type="button" aria-pressed={locale === 'en-US'} onClick={() => onSetLocale('en-US')}>English</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -196,33 +179,17 @@ export const HostView: React.FC<Props> = ({ state, locale, onRefresh, onError, o
|
||||
realGPUs.map((g) => (
|
||||
<div className="row" key={g.vulkan_icd}>
|
||||
<div className="row-main">
|
||||
<div className="row-title">
|
||||
<div className="row-title" title={g.vulkan_icd}>
|
||||
{g.name}
|
||||
<span className={`badge ${g.kind === 'discrete' ? 'badge-accent' : ''}`}>{gpuKind(g.kind)}</span>
|
||||
{host.recommended_gpu?.vulkan_icd === g.vulkan_icd && <span className="badge badge-ok">{tr('gpuRecommended')}</span>}
|
||||
</div>
|
||||
<div className="row-sub mono">{g.vulkan_icd}</div>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="section">
|
||||
<div className="section-title">{tr('hostPrefs')}</div>
|
||||
<div className="list">
|
||||
<div className="row">
|
||||
<div className="row-main"><div className="row-title">{tr('language')}</div></div>
|
||||
<div className="row-right">
|
||||
<div className="segmented" role="group" aria-label={tr('language')}>
|
||||
<button type="button" aria-pressed={locale === 'zh-CN'} onClick={() => onSetLocale('zh-CN')}>中文</button>
|
||||
<button type="button" aria-pressed={locale === 'en-US'} onClick={() => onSetLocale('en-US')}>English</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
import { Download, LoaderCircle, Pause, RefreshCw, Trash } from 'lucide-react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { I18nKey, t } from '../i18n'
|
||||
import { taskDetail } from '../lib/tasks'
|
||||
import { CachedInstaller, HostReport, Locale, Release, Task } from '../types'
|
||||
import { Button, IconButton } from '../ui/controls'
|
||||
import { backend } from '../wails'
|
||||
|
||||
interface Props {
|
||||
locale: Locale
|
||||
host: HostReport
|
||||
tasks: Task[]
|
||||
onError: (title: string, e: unknown) => void
|
||||
onToast: (title: string) => void
|
||||
}
|
||||
|
||||
const gb = (b: number) => (b >= 1e9 ? `${(b / 1e9).toFixed(1)} GB` : `${Math.max(1, Math.ceil(b / 1e6))} MB`)
|
||||
|
||||
// reims-util creates the whole image as soon as a download starts (19.7 GB for an
|
||||
// 18.4 GB release, measured 2026-11-28): reserve 10% over the release size.
|
||||
const needBytes = (r: Release) => r.size * 1.1
|
||||
|
||||
/** Offline installers (roadmap M2.2): what is downloaded, and Apple's releases to download. */
|
||||
export const InstallersPage: React.FC<Props> = ({ locale, host, tasks, onError, onToast }) => {
|
||||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||||
const [cached, setCached] = useState<CachedInstaller[] | null>(null)
|
||||
const [releases, setReleases] = useState<Release[] | null>(null)
|
||||
const [releasesErr, setReleasesErr] = useState('')
|
||||
const [confirmDelete, setConfirmDelete] = useState('')
|
||||
|
||||
const downloads = tasks.filter((x) => x.kind === 'installer-download')
|
||||
const running = (version: string) => downloads.find((x) => x.status === 'running' && x.subject === version)
|
||||
const finishedCount = downloads.filter((x) => x.status !== 'running').length
|
||||
|
||||
const loadCached = () => backend.listInstallers().then((l) => setCached(l ?? [])).catch((e) => onError(tr('failGeneric'), e))
|
||||
const loadReleases = () => {
|
||||
setReleases(null)
|
||||
setReleasesErr('')
|
||||
backend.listOfflineReleases()
|
||||
.then((l) => setReleases(l ?? []))
|
||||
.catch((e) => setReleasesErr(String(e).replace(/^Error:\s*/, '')))
|
||||
}
|
||||
useEffect(() => { loadReleases() }, [])
|
||||
// Refresh the downloaded list whenever a download starts or ends.
|
||||
useEffect(() => { loadCached() }, [finishedCount, downloads.length])
|
||||
|
||||
const isDownloaded = (v: string) => (cached ?? []).some((c) => c.kind === 'offline' && !c.partial && c.version === v)
|
||||
|
||||
const download = (version: string) => {
|
||||
backend.downloadInstaller(version).catch((e) => onError(tr('failDownload'), e))
|
||||
}
|
||||
|
||||
const remove = async (name: string) => {
|
||||
if (confirmDelete !== name) { setConfirmDelete(name); return }
|
||||
setConfirmDelete('')
|
||||
try {
|
||||
await backend.deleteInstaller(name)
|
||||
onToast(tr('toastDeleted', { name }))
|
||||
loadCached()
|
||||
} catch (e) {
|
||||
onError(tr('failDelete'), e)
|
||||
}
|
||||
}
|
||||
|
||||
const progress = (task: Task) => (
|
||||
<span className="task-inline row-sub">
|
||||
<LoaderCircle size={14} className="spin" />
|
||||
{task.percent >= 0 && <span className="progress"><div style={{ width: `${task.percent}%` }} /></span>}
|
||||
<span>{task.percent >= 0 ? `${Math.floor(task.percent)}%` : ''} {taskDetail(task)}</span>
|
||||
</span>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="page">
|
||||
<header className="page-head">
|
||||
<div className="page-title"><h1>{tr('installersTitle')}</h1></div>
|
||||
<div className="actions">
|
||||
<IconButton label={tr('refresh')} icon={<RefreshCw size={16} />} onClick={() => { loadCached(); loadReleases() }} />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section className="section">
|
||||
<div className="section-title">{tr('installersDownloaded')}</div>
|
||||
<div className="list">
|
||||
{cached === null ? (
|
||||
<div className="row"><span className="row-sub">…</span></div>
|
||||
) : cached.length === 0 ? (
|
||||
<div className="row"><span className="row-sub">{tr('installersEmpty')}</span></div>
|
||||
) : cached.map((c) => {
|
||||
const task = c.version ? running(c.version) : undefined
|
||||
return (
|
||||
<div className="row" key={c.name}>
|
||||
<div className="row-main">
|
||||
<div className="row-title">
|
||||
{c.title ?? c.name} {c.version}
|
||||
{c.build && <span className="muted">({c.build})</span>}
|
||||
{c.partial && !task && <span className="badge badge-warn">{tr('installersPartial')}</span>}
|
||||
</div>
|
||||
{task ? progress(task) : <div className="row-sub mono">{c.name} · {gb(c.bytes)}</div>}
|
||||
</div>
|
||||
<div className="row-right">
|
||||
{task ? (
|
||||
<IconButton label={tr('pauseDownload')} icon={<Pause size={16} />} onClick={() => backend.cancelTask(task.id)} />
|
||||
) : (
|
||||
<>
|
||||
{c.partial && c.kind === 'offline' && c.version && (
|
||||
<Button icon={<Download size={14} />} onClick={() => download(c.version!)}>{tr('installersResume')}</Button>
|
||||
)}
|
||||
{confirmDelete === c.name ? (
|
||||
<Button variant="danger" onClick={() => remove(c.name)}>{tr('installersDeleteConfirm')}</Button>
|
||||
) : (
|
||||
<IconButton label={tr('installersDelete')} icon={<Trash size={15} />} onClick={() => remove(c.name)} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="section">
|
||||
<div className="section-title">{tr('installersAvailable')}</div>
|
||||
<div className="list">
|
||||
{releasesErr ? (
|
||||
<div className="row"><span className="row-sub">{tr('offlineListFailed')}:{releasesErr}</span></div>
|
||||
) : releases === null ? (
|
||||
<div className="row"><span className="row-sub">{tr('offlineLoading')}</span></div>
|
||||
) : releases.map((r) => {
|
||||
const task = running(r.version)
|
||||
const done = isDownloaded(r.version)
|
||||
const short = !done && !task && host.free_disk_gb > 0 && host.free_disk_gb * 1e9 < needBytes(r)
|
||||
return (
|
||||
<div className="row" key={r.product}>
|
||||
<div className="row-main">
|
||||
<div className="row-title">
|
||||
{r.title} {r.version}
|
||||
<span className="muted">({r.build})</span>
|
||||
</div>
|
||||
{task ? progress(task) : (
|
||||
<div className="row-sub">
|
||||
{r.posted} · {gb(r.size)}
|
||||
{short && <span className="warn-text"> · {tr('installersNoSpace', { need: Math.ceil(needBytes(r) / 1e9), free: host.free_disk_gb.toFixed(0) })}</span>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="row-right">
|
||||
{task ? (
|
||||
<IconButton label={tr('pauseDownload')} icon={<Pause size={16} />} onClick={() => backend.cancelTask(task.id)} />
|
||||
) : done ? (
|
||||
<span className="badge badge-ok">{tr('offlineCached')}</span>
|
||||
) : (
|
||||
<Button icon={<Download size={14} />} disabled={short} onClick={() => download(r.version)}>{tr('installersDownload')}</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<span className="hint">{tr('installersHint')}</span>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -18,7 +18,13 @@ interface Props {
|
||||
|
||||
const gb = (b: number) => (b >= 1e9 ? `${(b / 1e9).toFixed(1)} GB` : `${Math.ceil(b / 1e6)} MB`)
|
||||
|
||||
/** Online runtime install: newest release on the channel, its install button or progress. */
|
||||
/** "QEMU emulator version 11.1.90" → "QEMU 11.1.90". */
|
||||
const shortQemu = (v: string) => v.replace(/^QEMU emulator version\s*/i, 'QEMU ')
|
||||
|
||||
/**
|
||||
* The runtime rows: the active runtime and whether it is current (or, with
|
||||
* none installed, the newest release to install), then the candidate switch.
|
||||
*/
|
||||
export const RuntimeOnline: React.FC<Props> = ({ locale, channel, installed, task, onChannel, onInstall, onCancel }) => {
|
||||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||||
const [remote, setRemote] = useState<RemoteRuntime[] | null>(null)
|
||||
@@ -34,32 +40,34 @@ export const RuntimeOnline: React.FC<Props> = ({ locale, channel, installed, tas
|
||||
return () => { live = false }
|
||||
}, [channel, task?.status === 'done'])
|
||||
|
||||
const active = installed.find((i) => i.active) ?? installed[0]
|
||||
const latest = remote?.[0]
|
||||
const isInstalled = (c: string) => installed.some((i) => i.commit.startsWith(c) || c.startsWith(i.commit))
|
||||
const running = task?.status === 'running'
|
||||
const updatable = !!latest && !isInstalled(latest.commit)
|
||||
|
||||
let body: React.ReactNode
|
||||
let sub: React.ReactNode
|
||||
if (running && task) {
|
||||
body = (
|
||||
sub = (
|
||||
<div className="row-sub task-inline">
|
||||
<LoaderCircle size={14} className="spin" />
|
||||
{task.percent >= 0 && <span className="progress"><div style={{ width: `${task.percent}%` }} /></span>}
|
||||
<span>{task.percent >= 0 ? `${Math.floor(task.percent)}%` : ''} {taskDetail(task)}</span>
|
||||
</div>
|
||||
)
|
||||
} else if (active && !updatable) {
|
||||
sub = <div className="row-sub">{shortQemu(active.manifest.qemu_version)}</div>
|
||||
} else if (error) {
|
||||
body = <div className="row-sub" title={error}>{tr('runtimeLookupFailed')}</div>
|
||||
sub = <div className="row-sub" title={error}>{tr('runtimeLookupFailed')}</div>
|
||||
} else if (!remote) {
|
||||
body = <div className="row-sub">…</div>
|
||||
sub = <div className="row-sub">…</div>
|
||||
} else if (!latest) {
|
||||
body = <div className="row-sub">{tr('runtimeNoneOnChannel')}</div>
|
||||
sub = <div className="row-sub">{tr('runtimeNoneOnChannel')}</div>
|
||||
} else {
|
||||
body = (
|
||||
sub = (
|
||||
<div className="row-sub">
|
||||
<span className="mono">{tr('runtimeLatest', { v: latest.commit })}</span>
|
||||
{' · '}{tr(`runtimeChannel_${latest.channel}` as I18nKey)}
|
||||
{' · '}{gb(latest.archive_size)}
|
||||
{' · '}{latest.published_at.slice(0, 10)}
|
||||
{active ? tr('runtimeNewer', { v: latest.commit }) : tr('runtimeLatest', { v: latest.commit })}
|
||||
{' · '}{tr(`runtimeChannel_${latest.channel}` as I18nKey)} · {gb(latest.archive_size)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -68,16 +76,21 @@ export const RuntimeOnline: React.FC<Props> = ({ locale, channel, installed, tas
|
||||
<>
|
||||
<div className="row">
|
||||
<div className="row-main">
|
||||
<div className="row-title">{tr('runtimeOnline')}</div>
|
||||
{body}
|
||||
<div className="row-title">
|
||||
{active ? <>{tr('runtimeCurrent')} <span className="mono">{active.commit}</span></> : tr('runtimeOnline')}
|
||||
</div>
|
||||
{sub}
|
||||
</div>
|
||||
<div className="row-right">
|
||||
{running && task?.cancelable && (
|
||||
{running && task?.cancelable ? (
|
||||
<IconButton label={tr('pauseDownload')} icon={<Pause size={16} />} onClick={() => onCancel(task.id)} />
|
||||
)}
|
||||
{!running && latest && (isInstalled(latest.commit)
|
||||
? <span className="badge badge-ok">{tr('runtimeUpToDate')}</span>
|
||||
: <Button variant="primary" icon={<Download size={14} />} onClick={() => onInstall(latest.commit)}>{tr('runtimeInstall')}</Button>)}
|
||||
) : !running && updatable ? (
|
||||
<Button variant="primary" icon={<Download size={14} />} onClick={() => onInstall(latest!.commit)}>
|
||||
{tr(active ? 'runtimeUpdate' : 'runtimeInstall')}
|
||||
</Button>
|
||||
) : !running && active && remote ? (
|
||||
<span className="badge badge-ok">{tr('runtimeUpToDate')}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div className="row">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useState } from 'react'
|
||||
import { I18nKey, t } from '../i18n'
|
||||
import { shortGPUName } from '../lib/format'
|
||||
import { recommendedMemoryGB, shortGPUName } from '../lib/format'
|
||||
import { HostReport, Locale, SetOpts, ValidationIssue, VMDetail } from '../types'
|
||||
import { Button } from '../ui/controls'
|
||||
import { Modal } from '../ui/dialog'
|
||||
@@ -176,7 +176,11 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, host, running,
|
||||
<label className="field-label" htmlFor="set-mem">{tr('factMemory')} · {tr('hostMemory', { n: host.total_ram_gb.toFixed(0) })}</label>
|
||||
{presets(['4G', '8G', '12G', '16G', '24G'], form.memory, (m) => m, (memory) => set({ memory }))}
|
||||
<input id="set-mem" className="input" value={form.memory ?? ''} onChange={(e) => set({ memory: e.target.value })} />
|
||||
<span className="hint">{tr('memHint')}</span>
|
||||
<span className="hint">
|
||||
{host.commit_avail_gb > 0
|
||||
? tr('memCommitHint', { avail: host.commit_avail_gb.toFixed(1), rec: recommendedMemoryGB(host) })
|
||||
: tr('memHint')}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react'
|
||||
import { I18nKey, t } from '../i18n'
|
||||
import { AppState, DataRootCheck, DataRootChoice, Locale, Task } from '../types'
|
||||
import { Button } from '../ui/controls'
|
||||
import { recommendedMemoryGB, shortGPUName } from '../lib/format'
|
||||
import { backend } from '../wails'
|
||||
import { RuntimeOnline } from './RuntimeOnline'
|
||||
|
||||
@@ -147,14 +148,69 @@ const FolderStep: React.FC<StepProps> = ({ locale, tr, onLocale, onFolderDone, o
|
||||
)
|
||||
}
|
||||
|
||||
const RuntimeStep: React.FC<StepProps> = ({ locale, tr, state, runtimeTask, onChannel, onInstallRuntime, onCancelTask, onImportRuntime, onFinish }) => {
|
||||
const RuntimeStep: React.FC<StepProps> = ({ locale, tr, state, runtimeTask, onChannel, 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 backend.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}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Cpu, Monitor, Plus } from 'lucide-react'
|
||||
import { Cpu, Download, Monitor, Plus } from 'lucide-react'
|
||||
import React, { useRef } from 'react'
|
||||
import { I18nKey, t } from '../i18n'
|
||||
import { Locale, VMListItem } from '../types'
|
||||
import { IconButton, StatusShape, Tip, statusKind } from '../ui/controls'
|
||||
|
||||
export const HOST_ID = '__host__'
|
||||
export const INSTALLERS_ID = '__installers__'
|
||||
|
||||
interface Props {
|
||||
locale: Locale
|
||||
@@ -14,11 +15,13 @@ interface Props {
|
||||
hostReady: boolean
|
||||
onSelect: (id: string) => void
|
||||
onNew: () => void
|
||||
/** An installer download is running (busy dot on the Installers entry). */
|
||||
downloading?: boolean
|
||||
}
|
||||
|
||||
export const Sidebar: React.FC<Props> = ({ locale, vms, transitions, selected, hostReady, onSelect, onNew }) => {
|
||||
export const Sidebar: React.FC<Props> = ({ locale, vms, transitions, selected, hostReady, onSelect, onNew, downloading }) => {
|
||||
const listRef = useRef<HTMLDivElement>(null)
|
||||
const ids = [...vms.map((v) => v.name), HOST_ID]
|
||||
const ids = [...vms.map((v) => v.name), INSTALLERS_ID, HOST_ID]
|
||||
|
||||
// Listbox keyboard model: ↑/↓/Home/End move selection and focus together.
|
||||
const onKeyDown = (e: React.KeyboardEvent) => {
|
||||
@@ -40,7 +43,7 @@ export const Sidebar: React.FC<Props> = ({ locale, vms, transitions, selected, h
|
||||
icon: React.ReactNode,
|
||||
badgeClass: string,
|
||||
stateLabel: string,
|
||||
kind: ReturnType<typeof statusKind>,
|
||||
kind: ReturnType<typeof statusKind> | null,
|
||||
) => (
|
||||
<button
|
||||
key={id}
|
||||
@@ -49,15 +52,17 @@ export const Sidebar: React.FC<Props> = ({ locale, vms, transitions, selected, h
|
||||
data-id={id}
|
||||
className="nav-item"
|
||||
aria-selected={selected === id}
|
||||
aria-label={`${label},${stateLabel}`}
|
||||
aria-label={stateLabel ? `${label},${stateLabel}` : label}
|
||||
tabIndex={selected === id ? 0 : -1}
|
||||
onClick={() => onSelect(id)}
|
||||
>
|
||||
<span className={`nav-icon-badge ${badgeClass}`} aria-hidden="true">{icon}</span>
|
||||
<span className="nav-label">{label}</span>
|
||||
<Tip label={stateLabel} side="right">
|
||||
<span className="hstack"><StatusShape kind={kind} /></span>
|
||||
</Tip>
|
||||
{kind && (
|
||||
<Tip label={stateLabel} side="right">
|
||||
<span className="hstack"><StatusShape kind={kind} /></span>
|
||||
</Tip>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
|
||||
@@ -75,6 +80,14 @@ export const Sidebar: React.FC<Props> = ({ locale, vms, transitions, selected, h
|
||||
return item(vm.name, vm.name, <Monitor size={13} />, 'nav-icon-vm', t(locale, `state_${st}` as I18nKey), statusKind(st))
|
||||
})}
|
||||
<div className="sidebar-sep" role="presentation" />
|
||||
{item(
|
||||
INSTALLERS_ID,
|
||||
t(locale, 'sidebarInstallers'),
|
||||
<Download size={13} />,
|
||||
'nav-icon-installers',
|
||||
downloading ? t(locale, 'state_starting') : '',
|
||||
downloading ? 'busy' : null,
|
||||
)}
|
||||
{item(
|
||||
HOST_ID,
|
||||
t(locale, 'sidebarHost'),
|
||||
|
||||
@@ -18,7 +18,10 @@ import { controllerLabel, formatMemory, graphicsLabel, sshCommand } from '../lib
|
||||
import { HostReport, Locale, PendingChange, VMDetail } from '../types'
|
||||
import { Button, IconButton, StatusShape, Tip, statusKind } from '../ui/controls'
|
||||
|
||||
export type VMAction = 'start' | 'stop' | 'forceStop' | 'restart' | 'eject' | 'delete' | 'openFolder'
|
||||
export type VMAction = 'start' | 'stop' | 'forceStop' | 'restart' | 'eject' | 'finishInstall' | 'delete' | 'openFolder'
|
||||
|
||||
// What an offline installer's Recovery runs to install (`reims-util offline-installer --help`).
|
||||
const OFFLINE_INSTALL_CMD = 'sh /Volumes/Installer/install-macos.sh'
|
||||
|
||||
interface Props {
|
||||
locale: Locale
|
||||
@@ -134,21 +137,49 @@ export const VMPage: React.FC<Props> = ({
|
||||
{detail?.has_installer && (
|
||||
<section className="card" aria-labelledby="guide-title">
|
||||
<h2 className="card-title" id="guide-title">{tr('guideTitle')}</h2>
|
||||
<ol className="steps">
|
||||
<li>{tr('guideStep1')}</li>
|
||||
<li>{tr('guideStep2')}</li>
|
||||
<li>{tr('guideStep3')}</li>
|
||||
</ol>
|
||||
<div className="card-foot">
|
||||
<Button
|
||||
variant={running ? 'primary' : 'secondary'}
|
||||
busy={busyAction === 'eject'}
|
||||
disabled={busy}
|
||||
onClick={() => onAction('eject')}
|
||||
>
|
||||
{tr('eject')}
|
||||
</Button>
|
||||
</div>
|
||||
{/offline-installer/i.test(detail.installer_path ?? '') ? (
|
||||
<>
|
||||
<ol className="steps">
|
||||
<li>{tr('guideOffline1')}</li>
|
||||
<li>
|
||||
{tr('guideOffline2')}
|
||||
<div className="cmd-line guide-cmd">
|
||||
<code>{OFFLINE_INSTALL_CMD}</code>
|
||||
<IconButton small label={tr('copy')} icon={<Copy size={14} />} onClick={() => onCopy(OFFLINE_INSTALL_CMD)} />
|
||||
</div>
|
||||
</li>
|
||||
<li>{tr('guideOffline3')}</li>
|
||||
</ol>
|
||||
<div className="card-foot">
|
||||
<Button
|
||||
variant={running ? 'primary' : 'secondary'}
|
||||
busy={busyAction === 'finishInstall'}
|
||||
disabled={busy}
|
||||
onClick={() => onAction('finishInstall')}
|
||||
>
|
||||
{tr('finishInstall')}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ol className="steps">
|
||||
<li>{tr('guideStep1')}</li>
|
||||
<li>{tr('guideStep2')}</li>
|
||||
<li>{tr('guideStep3')}</li>
|
||||
</ol>
|
||||
<div className="card-foot">
|
||||
<Button
|
||||
variant={running ? 'primary' : 'secondary'}
|
||||
busy={busyAction === 'eject'}
|
||||
disabled={busy}
|
||||
onClick={() => onAction('eject')}
|
||||
>
|
||||
{tr('eject')}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
|
||||
|
||||
+112
-8
@@ -7,6 +7,18 @@ const dict = {
|
||||
// Shell
|
||||
sidebarVMs: '虚拟机',
|
||||
sidebarHost: '宿主与运行时',
|
||||
sidebarInstallers: '安装包',
|
||||
installersTitle: '安装包',
|
||||
installersDownloaded: '已下载',
|
||||
installersAvailable: 'Apple 提供的版本',
|
||||
installersEmpty: '还没有下载任何安装包',
|
||||
installersPartial: '未下载完',
|
||||
installersResume: '继续下载',
|
||||
installersDownload: '下载',
|
||||
installersDelete: '删除',
|
||||
installersDeleteConfirm: '确认删除',
|
||||
installersNoSpace: '空间不足:需要约 {need} GB,可用 {free} GB',
|
||||
installersHint: '离线安装包可以重复用来新建虚拟机;正在使用或正在下载的不能删除',
|
||||
emptyVMs: '还没有虚拟机',
|
||||
hostReady: '就绪',
|
||||
hostNeedsAction: '需要处理',
|
||||
@@ -54,6 +66,10 @@ const dict = {
|
||||
guideStep1: '在「磁盘工具」中抹掉「QEMU HARDDISK Media」,格式选 APFS',
|
||||
guideStep2: '退出磁盘工具,选择「重新安装 macOS」',
|
||||
guideStep3: '进入桌面后,弹出安装盘',
|
||||
guideOffline1: '在「磁盘工具」中抹掉「QEMU HARDDISK Media」,格式选 APFS',
|
||||
guideOffline2: '退出磁盘工具,打开「实用工具 › 终端」,运行:',
|
||||
guideOffline3: '进入桌面后,点「完成安装」',
|
||||
finishInstall: '完成安装',
|
||||
brokenHint: '这台虚拟机的配置无法读取',
|
||||
techInfo: '技术信息',
|
||||
factCPU: '处理器',
|
||||
@@ -105,7 +121,11 @@ const dict = {
|
||||
setupWarnSpace: '可用空间不足 60 GB:一个离线安装包约 20 GB,虚拟磁盘会随使用增长',
|
||||
setupReuse: '这里已有 reims-go 数据,会直接沿用',
|
||||
setupContinue: '继续',
|
||||
setupRuntimeTitle: '安装运行时',
|
||||
setupRuntimeTitle: '检查环境并安装运行时',
|
||||
setupCheck: '环境',
|
||||
setupGPU: '显卡(Vulkan)',
|
||||
setupNoGPU: '没有检测到 Vulkan 显卡,只能用软件渲染',
|
||||
setupRecMem: '推荐 {n} GB',
|
||||
setupRuntimeDesc: '运行虚拟机所需的 QEMU 与 reims-ctl,从 GitHub 下载并校验',
|
||||
setupLater: '稍后',
|
||||
setupDone: '完成',
|
||||
@@ -116,6 +136,9 @@ const dict = {
|
||||
runtimeLatest: '最新:{v}',
|
||||
runtimeNoneOnChannel: '这个通道还没有发布运行时',
|
||||
runtimeUpToDate: '已是最新',
|
||||
runtimeCurrent: '当前运行时',
|
||||
runtimeUpdate: '更新',
|
||||
runtimeNewer: '有新版本:{v}',
|
||||
runtimeInstall: '安装',
|
||||
runtimeCandidate: '接收候选版',
|
||||
runtimeCandidateHint: '候选版未经真实宿主冒烟测试',
|
||||
@@ -126,6 +149,7 @@ const dict = {
|
||||
// Toasts & dialogs
|
||||
toastStopped: '{name} 已关机',
|
||||
toastEjected: '已弹出安装盘',
|
||||
toastInstallFinished: '已弹出安装盘并打开网络,下次启动生效',
|
||||
toastDeleted: '已删除 {name}',
|
||||
toastSaved: '已保存',
|
||||
toastSavedNextStart: '已保存,下次启动生效',
|
||||
@@ -134,6 +158,7 @@ const dict = {
|
||||
failStop: '关机失败',
|
||||
failRestart: '重启失败',
|
||||
failEject: '弹出安装盘失败',
|
||||
failFinishInstall: '完成安装失败',
|
||||
failDelete: '删除失败',
|
||||
failOpenFolder: '无法打开文件夹',
|
||||
failGeneric: '操作失败',
|
||||
@@ -193,6 +218,14 @@ const dict = {
|
||||
sourceApple: '从 Apple 下载恢复镜像',
|
||||
sourceInstaller: '本地安装器镜像(.img / .dmg)',
|
||||
sourceDisk: '已有虚拟磁盘(.qcow2)',
|
||||
sourceOffline: '离线安装包(推荐)',
|
||||
offlineLoading: '正在读取 Apple 的版本列表…',
|
||||
offlineListFailed: '无法读取 Apple 的版本列表',
|
||||
offlineCached: '已下载',
|
||||
offlineHint: '约 20 GB,安装时不联网;装完点「完成安装」会恢复网络',
|
||||
offlineSpaceWarn: '可用空间 {free} GB,下载这个版本需要约 {need} GB',
|
||||
networkOfflineHint: '离线安装期间保持关闭,完成安装后打开',
|
||||
summaryOfflineSource: '离线安装包 · macOS {v}',
|
||||
macosVersion: 'macOS 版本',
|
||||
macosTahoe: 'macOS 26 Tahoe(硬件加速需要 26.4 及以上)',
|
||||
diskSize: '磁盘上限',
|
||||
@@ -204,6 +237,7 @@ const dict = {
|
||||
hostMemory: '宿主 {n} GB',
|
||||
cpuHint: '推荐 4 或 8 核',
|
||||
memHint: '建议不超过宿主内存的 75%',
|
||||
memCommitHint: 'Windows 现在还能分配 {avail} GB,推荐 {rec} GB',
|
||||
graphicsBackend: '图形后端',
|
||||
graphicsReims: 'reims-vgpu(硬件加速,推荐)',
|
||||
graphicsSvga: 'vmware-svga(无加速,用于排障)',
|
||||
@@ -218,10 +252,28 @@ const dict = {
|
||||
sshPortHint: '0 表示关闭',
|
||||
enableLogs: '记录图形与串口日志',
|
||||
startAfterCreate: '创建后立即启动',
|
||||
commandPreview: '将执行的命令',
|
||||
validationPassed: '检查通过',
|
||||
validationPassed: '检查通过,可以创建',
|
||||
validationChecking: '正在检查…',
|
||||
issuesCount: '有 {n} 项需要修改',
|
||||
summaryEdit: '修改',
|
||||
summarySource: '来源',
|
||||
summaryDefaultDir: '数据目录(默认)',
|
||||
summaryAppleSource: '从 Apple 下载 · {v}',
|
||||
summaryInstallerSource: '本地安装器 · {file}',
|
||||
summaryDiskSource: '已有磁盘 · {file}',
|
||||
summaryOn: '开',
|
||||
summaryStartAfter: '创建后启动',
|
||||
summaryLogs: '图形与串口日志',
|
||||
summarySSH: 'SSH 转发',
|
||||
summarySSHPort: '端口 {n}',
|
||||
summaryDiskGrow: '{size},按实际占用增长',
|
||||
commandToggle: '等效命令',
|
||||
commandToggleHint: '在终端运行下面这条命令效果相同',
|
||||
createNow: '创建',
|
||||
creating: '正在创建,进度见底部状态栏',
|
||||
createStartedHint: '创建后窗口会关闭,进度在底部状态栏',
|
||||
toastCreated: '{name} 已创建',
|
||||
failCreate: '{name} 创建失败',
|
||||
backToEdit: '返回修改',
|
||||
|
||||
// Settings
|
||||
settingsTitle: '{name} 设置',
|
||||
@@ -251,6 +303,18 @@ const dict = {
|
||||
'en-US': {
|
||||
sidebarVMs: 'Virtual machines',
|
||||
sidebarHost: 'Host & runtime',
|
||||
sidebarInstallers: 'Installers',
|
||||
installersTitle: 'Installers',
|
||||
installersDownloaded: 'Downloaded',
|
||||
installersAvailable: 'Releases from Apple',
|
||||
installersEmpty: 'No installers downloaded yet',
|
||||
installersPartial: 'Partly downloaded',
|
||||
installersResume: 'Resume',
|
||||
installersDownload: 'Download',
|
||||
installersDelete: 'Delete',
|
||||
installersDeleteConfirm: 'Confirm delete',
|
||||
installersNoSpace: 'Not enough space: needs about {need} GB, {free} GB free',
|
||||
installersHint: 'An offline installer can be reused for new VMs; one in use or downloading can’t be deleted',
|
||||
emptyVMs: 'No virtual machines',
|
||||
hostReady: 'Ready',
|
||||
hostNeedsAction: 'Needs attention',
|
||||
@@ -295,6 +359,10 @@ const dict = {
|
||||
guideStep1: 'In Disk Utility, erase "QEMU HARDDISK Media" as APFS',
|
||||
guideStep2: 'Quit Disk Utility and choose "Reinstall macOS"',
|
||||
guideStep3: 'Once on the desktop, eject the installer',
|
||||
guideOffline1: 'In Disk Utility, erase "QEMU HARDDISK Media" as APFS',
|
||||
guideOffline2: 'Quit Disk Utility, open Utilities › Terminal and run:',
|
||||
guideOffline3: 'Once on the desktop, click “Finish install”',
|
||||
finishInstall: 'Finish install',
|
||||
brokenHint: 'This VM’s configuration can’t be read',
|
||||
techInfo: 'Technical details',
|
||||
factCPU: 'CPU',
|
||||
@@ -343,7 +411,11 @@ const dict = {
|
||||
setupWarnSpace: 'Under 60 GB free: an offline installer is about 20 GB and virtual disks grow with use',
|
||||
setupReuse: 'This folder already has reims-go data; it will be reused',
|
||||
setupContinue: 'Continue',
|
||||
setupRuntimeTitle: 'Install the runtime',
|
||||
setupRuntimeTitle: 'Check the host and install the runtime',
|
||||
setupCheck: 'Host',
|
||||
setupGPU: 'Graphics (Vulkan)',
|
||||
setupNoGPU: 'No Vulkan GPU found; only software rendering will work',
|
||||
setupRecMem: '{n} GB recommended',
|
||||
setupRuntimeDesc: 'QEMU and reims-ctl, downloaded from GitHub and verified',
|
||||
setupLater: 'Later',
|
||||
setupDone: 'Done',
|
||||
@@ -353,6 +425,9 @@ const dict = {
|
||||
runtimeLatest: 'Latest: {v}',
|
||||
runtimeNoneOnChannel: 'No runtime published on this channel yet',
|
||||
runtimeUpToDate: 'Up to date',
|
||||
runtimeCurrent: 'Current runtime',
|
||||
runtimeUpdate: 'Update',
|
||||
runtimeNewer: 'New version: {v}',
|
||||
runtimeInstall: 'Install',
|
||||
runtimeCandidate: 'Receive candidates',
|
||||
runtimeCandidateHint: 'Candidates have not passed a real-host smoke test',
|
||||
@@ -362,6 +437,7 @@ const dict = {
|
||||
|
||||
toastStopped: '{name} shut down',
|
||||
toastEjected: 'Installer ejected',
|
||||
toastInstallFinished: 'Installer ejected and network on — applies at next start',
|
||||
toastDeleted: '{name} deleted',
|
||||
toastSaved: 'Saved',
|
||||
toastSavedNextStart: 'Saved — applies on next start',
|
||||
@@ -370,6 +446,7 @@ const dict = {
|
||||
failStop: 'Couldn’t shut down',
|
||||
failRestart: 'Couldn’t restart',
|
||||
failEject: 'Couldn’t eject the installer',
|
||||
failFinishInstall: 'Couldn’t finish the install',
|
||||
failDelete: 'Couldn’t delete',
|
||||
failOpenFolder: 'Couldn’t open the folder',
|
||||
failGeneric: 'Something went wrong',
|
||||
@@ -427,6 +504,14 @@ const dict = {
|
||||
sourceApple: 'Download recovery image from Apple',
|
||||
sourceInstaller: 'Local installer image (.img / .dmg)',
|
||||
sourceDisk: 'Existing virtual disk (.qcow2)',
|
||||
sourceOffline: 'Offline installer (recommended)',
|
||||
offlineLoading: 'Reading Apple’s release list…',
|
||||
offlineListFailed: 'Couldn’t read Apple’s release list',
|
||||
offlineCached: 'Downloaded',
|
||||
offlineHint: 'About 20 GB; installs with no network. “Finish install” turns the network back on',
|
||||
offlineSpaceWarn: '{free} GB free; this release needs about {need} GB',
|
||||
networkOfflineHint: 'Off while installing offline; turned on when you finish the install',
|
||||
summaryOfflineSource: 'Offline installer · macOS {v}',
|
||||
macosVersion: 'macOS version',
|
||||
macosTahoe: 'macOS 26 Tahoe (acceleration needs 26.4 or later)',
|
||||
diskSize: 'Disk size',
|
||||
@@ -438,6 +523,7 @@ const dict = {
|
||||
hostMemory: 'Host has {n} GB',
|
||||
cpuHint: '4 or 8 cores recommended',
|
||||
memHint: 'Keep under 75% of host memory',
|
||||
memCommitHint: 'Windows can allocate {avail} GB more right now; {rec} GB recommended',
|
||||
graphicsBackend: 'Graphics backend',
|
||||
graphicsReims: 'reims-vgpu (accelerated, recommended)',
|
||||
graphicsSvga: 'vmware-svga (no acceleration, for troubleshooting)',
|
||||
@@ -452,10 +538,28 @@ const dict = {
|
||||
sshPortHint: '0 turns it off',
|
||||
enableLogs: 'Keep graphics and serial logs',
|
||||
startAfterCreate: 'Start after creating',
|
||||
commandPreview: 'Command to run',
|
||||
validationPassed: 'All checks passed',
|
||||
validationPassed: 'All checks passed — ready to create',
|
||||
validationChecking: 'Checking…',
|
||||
issuesCount: '{n} item(s) need fixing',
|
||||
summaryEdit: 'Edit',
|
||||
summarySource: 'Source',
|
||||
summaryDefaultDir: 'Data folder (default)',
|
||||
summaryAppleSource: 'Download from Apple · {v}',
|
||||
summaryInstallerSource: 'Local installer · {file}',
|
||||
summaryDiskSource: 'Existing disk · {file}',
|
||||
summaryOn: 'On',
|
||||
summaryStartAfter: 'Start after creating',
|
||||
summaryLogs: 'Graphics & serial logs',
|
||||
summarySSH: 'SSH forwarding',
|
||||
summarySSHPort: 'Port {n}',
|
||||
summaryDiskGrow: '{size}, grows with use',
|
||||
commandToggle: 'Equivalent command',
|
||||
commandToggleHint: 'Running this in a terminal does the same thing',
|
||||
createStartedHint: 'The window closes once creation starts; progress shows in the status bar',
|
||||
toastCreated: '{name} created',
|
||||
failCreate: 'Couldn’t create {name}',
|
||||
backToEdit: 'Edit and retry',
|
||||
createNow: 'Create',
|
||||
creating: 'Creating — progress is in the status bar',
|
||||
|
||||
settingsTitle: '{name} settings',
|
||||
appliesNextStart: 'Applies on next start',
|
||||
|
||||
@@ -4,6 +4,19 @@ import { GPUInfo, HostReport, Locale, VMDetail } from '../types'
|
||||
// Human-readable values for the main view (docs/ui-redesign.md §4.3).
|
||||
// Raw values stay available under "Technical details".
|
||||
|
||||
const MEMORY_CHOICES = [4, 6, 8, 12, 16, 24, 32, 48, 64]
|
||||
|
||||
/**
|
||||
* Largest offered memory size that fits in 60% of physical RAM and in the
|
||||
* commit memory free now, minus 1 GB for QEMU and 2 GB for the host. Mirrors
|
||||
* host.RecommendedMemoryGB (internal/host/memory.go).
|
||||
*/
|
||||
export function recommendedMemoryGB(host: HostReport): number {
|
||||
let limit = host.total_ram_gb * 0.6
|
||||
if (host.commit_avail_gb > 0) limit = Math.min(limit, host.commit_avail_gb - 3)
|
||||
return MEMORY_CHOICES.reduce((best, m) => (m <= limit ? m : best), MEMORY_CHOICES[0])
|
||||
}
|
||||
|
||||
/** "16G" / "16384M" / "16GiB" → "16 GB". Unknown shapes pass through. */
|
||||
export function formatMemory(raw: string): string {
|
||||
const m = /^\s*(\d+(?:\.\d+)?)\s*([KMGT])?(?:i?B)?\s*$/i.exec(raw ?? '')
|
||||
@@ -46,15 +59,18 @@ export function resolutionLabel(raw: string): string {
|
||||
return Math.abs(w / h - 16 / 9) < 0.01 ? `${h}p` : `${w}×${h}`
|
||||
}
|
||||
|
||||
/** A `gpu` value ("auto" or a Vulkan ICD path) as the card's short name, e.g. "RTX 4070 Ti". */
|
||||
export function gpuLabel(locale: Locale, icd: string | undefined, host: HostReport): string {
|
||||
if (!icd || icd === 'auto') {
|
||||
return host.recommended_gpu ? shortGPUName(host.recommended_gpu.name) : t(locale, 'gpuAuto')
|
||||
}
|
||||
const found = findGPU(host, icd)
|
||||
return found ? shortGPUName(found.name) : t(locale, 'gpuAuto')
|
||||
}
|
||||
|
||||
export function graphicsLabel(locale: Locale, d: VMDetail, host: HostReport): string {
|
||||
if (d.graphics && d.graphics !== 'reims-vgpu') return t(locale, 'softwareGraphics')
|
||||
let gpu: string
|
||||
if (!d.gpu || d.gpu === 'auto') {
|
||||
gpu = host.recommended_gpu ? shortGPUName(host.recommended_gpu.name) : t(locale, 'gpuAuto')
|
||||
} else {
|
||||
const found = findGPU(host, d.gpu)
|
||||
gpu = found ? shortGPUName(found.name) : t(locale, 'gpuAuto')
|
||||
}
|
||||
const gpu = gpuLabel(locale, d.gpu, host)
|
||||
const res = resolutionLabel(d.resolution)
|
||||
const screens = d.displays > 1 ? `${d.displays} × ${res}` : res
|
||||
return res ? `${gpu} · ${screens}` : gpu
|
||||
|
||||
@@ -125,6 +125,7 @@ h1, h2, h3, p { margin: 0; }
|
||||
}
|
||||
.nav-icon-vm { background: linear-gradient(145deg, #32a0ff 0%, #007aff 100%); }
|
||||
.nav-icon-host { background: linear-gradient(145deg, #8e8e93 0%, #636366 100%); }
|
||||
.nav-icon-installers { background: linear-gradient(145deg, #34c759 0%, #248a3d 100%); }
|
||||
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-13); }
|
||||
|
||||
/* Status shapes */
|
||||
@@ -292,7 +293,8 @@ h1, h2, h3, p { margin: 0; }
|
||||
:root[data-theme="dark"] .badge-warn { color: var(--status-busy); }
|
||||
.badge-error { background: var(--danger); color: #fff; min-width: 18px; height: 18px; padding: 0 var(--sp-1); justify-content: center; border-radius: 999px; }
|
||||
|
||||
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
|
||||
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
|
||||
.tile .tile-action { align-self: flex-start; height: 26px; margin-top: 2px; }
|
||||
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
||||
.tile-head { display: flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--text-3); }
|
||||
.tile-value { font-size: 15px; font-weight: var(--fw-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
|
||||
@@ -426,6 +428,43 @@ h1, h2, h3, p { margin: 0; }
|
||||
.wizard-step[aria-current="step"] { background: var(--accent-soft); color: var(--accent-soft-text); font-weight: var(--fw-strong); }
|
||||
.wizard-step.done { color: var(--text-2); }
|
||||
.wizard-step.done svg { color: var(--status-running); }
|
||||
.wizard-step.has-issue { color: var(--danger-text); }
|
||||
.wizard-step.has-issue[aria-current="step"] { background: var(--danger-soft); color: var(--danger-text); }
|
||||
|
||||
/* Wizard step ⑤: grouped summary */
|
||||
.review-status { display: flex; align-items: center; gap: 6px; font-size: var(--fs-13); color: var(--text-3); }
|
||||
.review-status.ok { color: var(--text-2); }
|
||||
.review-status.ok svg { color: var(--status-running); }
|
||||
.review-status.bad { color: var(--danger-text); font-weight: var(--fw-medium); }
|
||||
.review-groups { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
|
||||
.review-group {
|
||||
min-width: 0; padding: 12px 14px; border-radius: var(--r-lg);
|
||||
border: 1px solid var(--border); background: var(--surface-1);
|
||||
display: flex; flex-direction: column; gap: var(--sp-2);
|
||||
}
|
||||
.review-group:first-child, .review-group:last-child { grid-column: 1 / -1; }
|
||||
.review-group.has-issue { border-color: rgba(255, 59, 48, 0.4); background: var(--danger-soft); }
|
||||
.review-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
|
||||
.review-title { font-size: var(--fs-12); font-weight: var(--fw-strong); color: var(--text-3); }
|
||||
.link-btn { border: none; background: none; padding: 0; font: inherit; font-size: var(--fs-12); color: var(--accent-soft-text); cursor: pointer; }
|
||||
.link-btn:hover { text-decoration: underline; }
|
||||
.review-rows { display: grid; grid-template-columns: max-content 1fr; column-gap: var(--sp-4); row-gap: 6px; margin: 0; font-size: var(--fs-13); }
|
||||
.review-group:last-child .review-rows { grid-template-columns: max-content 1fr max-content 1fr; }
|
||||
.review-rows dt { color: var(--text-3); }
|
||||
.review-rows dd { margin: 0; min-width: 0; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.review-issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-12); color: var(--danger-text); }
|
||||
.review-issues li { display: flex; align-items: flex-start; gap: 6px; }
|
||||
.review-issues svg { flex-shrink: 0; margin-top: 2px; }
|
||||
.review-cmd > summary {
|
||||
list-style: none; display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
|
||||
font-size: var(--fs-13); color: var(--text-2); user-select: none;
|
||||
}
|
||||
.review-cmd > summary::-webkit-details-marker { display: none; }
|
||||
.review-cmd > summary svg { transition: transform var(--dur-fast); }
|
||||
.review-cmd[open] > summary svg { transform: rotate(90deg); }
|
||||
.review-cmd-body { margin-top: var(--sp-2); display: flex; flex-direction: column; gap: 6px; }
|
||||
.review-cmd-box { display: flex; align-items: flex-start; gap: var(--sp-2); }
|
||||
.review-cmd-box .code { flex: 1; min-width: 0; }
|
||||
|
||||
.settings-split { display: flex; height: 460px; min-height: 0; }
|
||||
.settings-nav { width: 186px; flex-shrink: 0; padding: 10px 8px; border-right: 1px solid var(--border); background: var(--surface-1); display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
|
||||
@@ -458,3 +497,6 @@ h1, h2, h3, p { margin: 0; }
|
||||
.choice-card-meta { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-12); color: var(--text-3); }
|
||||
.choice-other { align-self: flex-start; }
|
||||
.task-inline { display: flex; align-items: center; gap: var(--sp-2); }
|
||||
|
||||
.guide-cmd { margin-top: var(--sp-2); }
|
||||
.warn-text { color: var(--status-busy); }
|
||||
@@ -29,6 +29,9 @@ export interface HostReport {
|
||||
e_core_logical_cpus?: number[]
|
||||
total_ram_gb: number
|
||||
avail_ram_gb: number
|
||||
/** Windows commit memory: QEMU commits all guest RAM at start. */
|
||||
commit_avail_gb: number
|
||||
commit_limit_gb: number
|
||||
data_root: string
|
||||
free_disk_gb: number
|
||||
whpx: 'ready' | 'no_hypervisor' | 'missing' | 'unsupported'
|
||||
@@ -119,7 +122,9 @@ export interface ValidationIssue {
|
||||
export interface CreateOpts {
|
||||
name: string
|
||||
dir?: string
|
||||
source_mode?: 'apple' | 'installer' | 'disk'
|
||||
source_mode?: 'offline' | 'apple' | 'installer' | 'disk'
|
||||
/** With macos: an offline installer of that release (reims-ctl create --offline). */
|
||||
offline?: boolean
|
||||
macos?: string
|
||||
installer?: string
|
||||
cpus: number
|
||||
|
||||
@@ -41,6 +41,7 @@ declare global {
|
||||
DeleteVM(name: string, keepFiles: boolean): Promise<void>
|
||||
ReadVMLogs(name: string, serial: boolean): Promise<string>
|
||||
OpenVMFolder(name: string): Promise<void>
|
||||
FinishInstall(name: string): Promise<void>
|
||||
GetTasks(): Promise<Task[]>
|
||||
CancelTask(id: string): Promise<void>
|
||||
DismissTask(id: string): Promise<void>
|
||||
@@ -97,6 +98,7 @@ export const backend = {
|
||||
deleteVM: (name: string, keepFiles: boolean) => app().DeleteVM(name, keepFiles),
|
||||
readVMLogs: (name: string, serial: boolean) => app().ReadVMLogs(name, serial),
|
||||
openVMFolder: (name: string) => app().OpenVMFolder(name),
|
||||
finishInstall: (name: string) => app().FinishInstall(name),
|
||||
getTasks: () => app().GetTasks(),
|
||||
cancelTask: (id: string) => app().CancelTask(id),
|
||||
dismissTask: (id: string) => app().DismissTask(id),
|
||||
|
||||
Vendored
+2
@@ -27,6 +27,8 @@ export function EjectInstaller(arg1:string):Promise<void>;
|
||||
|
||||
export function EnableWHPX():Promise<void>;
|
||||
|
||||
export function FinishInstall(arg1:string):Promise<void>;
|
||||
|
||||
export function GetState():Promise<main.AppState>;
|
||||
|
||||
export function GetTasks():Promise<Array<main.Task>>;
|
||||
|
||||
@@ -46,6 +46,10 @@ export function EnableWHPX() {
|
||||
return window['go']['main']['App']['EnableWHPX']();
|
||||
}
|
||||
|
||||
export function FinishInstall(arg1) {
|
||||
return window['go']['main']['App']['FinishInstall'](arg1);
|
||||
}
|
||||
|
||||
export function GetState() {
|
||||
return window['go']['main']['App']['GetState']();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ export namespace host {
|
||||
e_core_logical_cpus?: number[];
|
||||
total_ram_gb: number;
|
||||
avail_ram_gb: number;
|
||||
commit_avail_gb: number;
|
||||
commit_limit_gb: number;
|
||||
data_root: string;
|
||||
free_disk_gb: number;
|
||||
whpx: string;
|
||||
@@ -83,6 +85,8 @@ export namespace host {
|
||||
this.e_core_logical_cpus = source["e_core_logical_cpus"];
|
||||
this.total_ram_gb = source["total_ram_gb"];
|
||||
this.avail_ram_gb = source["avail_ram_gb"];
|
||||
this.commit_avail_gb = source["commit_avail_gb"];
|
||||
this.commit_limit_gb = source["commit_limit_gb"];
|
||||
this.data_root = source["data_root"];
|
||||
this.free_disk_gb = source["free_disk_gb"];
|
||||
this.whpx = source["whpx"];
|
||||
@@ -319,6 +323,7 @@ export namespace reims {
|
||||
dir?: string;
|
||||
source_mode?: string;
|
||||
macos?: string;
|
||||
offline?: boolean;
|
||||
installer?: string;
|
||||
cpus?: number;
|
||||
memory?: string;
|
||||
@@ -346,6 +351,7 @@ export namespace reims {
|
||||
this.dir = source["dir"];
|
||||
this.source_mode = source["source_mode"];
|
||||
this.macos = source["macos"];
|
||||
this.offline = source["offline"];
|
||||
this.installer = source["installer"];
|
||||
this.cpus = source["cpus"];
|
||||
this.memory = source["memory"];
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
// Finishing an offline install (roadmap M2.3): take the installer out and turn
|
||||
// the network back on, which an offline install keeps off so its installer
|
||||
// downloads no update (`reims-ctl create --help`, upstream 3731afd).
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Nwflower/reims-go/internal/driver/reims"
|
||||
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// FinishInstall ejects the installer and enables the network. Both changes
|
||||
// apply at the VM's next start (a running VM keeps its installer until then:
|
||||
// `reims-ctl eject --help`), so on a running VM they are listed as pending.
|
||||
func (a *App) FinishInstall(name string) error {
|
||||
c, err := a.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d, err := a.GetVMDetail(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := &logWriter{emit: func(line string) { a.emitLog(name, line) }}
|
||||
ctx := context.Background()
|
||||
|
||||
if d.HasInstaller {
|
||||
a.emitLog(name, "Ejecting installer from "+name+"...")
|
||||
if err := c.Eject(ctx, name, w, w); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !d.Network {
|
||||
on := true
|
||||
a.emitLog(name, "Turning the network on for "+name+"...")
|
||||
if err := c.Set(ctx, reims.SetOpts{Name: name, Network: &on}, w, w); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
running := d.State == "running"
|
||||
if !running {
|
||||
if list, err := c.List(ctx); err == nil {
|
||||
for _, vm := range list {
|
||||
if vm.Name == name {
|
||||
running = vm.State == "running"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if running {
|
||||
var diffs []PendingChange
|
||||
if d.HasInstaller {
|
||||
diffs = append(diffs, PendingChange{Field: "installer", From: "attached", To: "ejected"})
|
||||
}
|
||||
if !d.Network {
|
||||
diffs = append(diffs, PendingChange{Field: "network", From: "off", To: "on"})
|
||||
}
|
||||
a.mu.Lock()
|
||||
a.pendingChanges[name] = append(a.pendingChanges[name], diffs...)
|
||||
a.mu.Unlock()
|
||||
}
|
||||
a.emitLog(name, "Install finished: installer out, network on")
|
||||
if a.ctx != nil {
|
||||
wailsRuntime.EventsEmit(a.ctx, "reims:state-changed", true)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -79,6 +79,10 @@ type CreateOpts struct {
|
||||
Dir string `json:"dir,omitempty"`
|
||||
SourceMode string `json:"source_mode,omitempty"` // "apple" | "installer" | "disk"
|
||||
MacOS string `json:"macos,omitempty"`
|
||||
// Offline makes --macos an offline installer of one release (13 to 20 GB)
|
||||
// that installs with no network; upstream advises the VM's network off then
|
||||
// (`reims-ctl create --help`, 3731afd). Network defaults to false with it.
|
||||
Offline bool `json:"offline,omitempty"`
|
||||
Installer string `json:"installer,omitempty"`
|
||||
CPUs int `json:"cpus,omitempty"`
|
||||
Memory string `json:"memory,omitempty"`
|
||||
@@ -158,8 +162,13 @@ func ValidateCreate(o CreateOpts, rep host.Report) []ValidationIssue {
|
||||
issues = append(issues, ValidationIssue{Field: "memory", Code: "invalid_memory", Message: "Memory must be at least 2G (e.g. 8G, 16G)"})
|
||||
} else if rep.TotalRAMGB > 0 && memGB > rep.TotalRAMGB*0.85 {
|
||||
issues = append(issues, ValidationIssue{Field: "memory", Code: "memory_exceeds_host", Message: fmt.Sprintf("Memory %.0fG exceeds safe host limit (host total %.1f GB)", memGB, rep.TotalRAMGB)})
|
||||
} else if rep.CommitLimitGB > 0 && memGB+host.StartMarginGB > rep.CommitLimitGB-2 {
|
||||
issues = append(issues, ValidationIssue{Field: "memory", Code: "memory_exceeds_commit", Message: fmt.Sprintf("Memory %.0fG can't fit in Windows' commit limit (%.1f GB including the page file); choose %.0fG or less", memGB, rep.CommitLimitGB, host.RecommendedMemoryGB(rep))})
|
||||
}
|
||||
}
|
||||
if o.Offline && strings.TrimSpace(o.MacOS) == "" {
|
||||
issues = append(issues, ValidationIssue{Field: "macos", Code: "missing_release", Message: "Choose the macOS release to install offline"})
|
||||
}
|
||||
if o.Disk == "" && o.DiskSize != "" {
|
||||
diskGB, ok := ParseSizeGB(o.DiskSize)
|
||||
if !ok || diskGB < 32 {
|
||||
@@ -208,6 +217,8 @@ func ValidateSet(o SetOpts, current VMDetail, rep host.Report) []ValidationIssue
|
||||
issues = append(issues, ValidationIssue{Field: "memory", Code: "invalid_memory", Message: "Memory must be at least 2G"})
|
||||
} else if rep.TotalRAMGB > 0 && memGB > rep.TotalRAMGB*0.85 {
|
||||
issues = append(issues, ValidationIssue{Field: "memory", Code: "memory_exceeds_host", Message: fmt.Sprintf("Memory %.0fG exceeds safe host limit (%.1f GB total)", memGB, rep.TotalRAMGB)})
|
||||
} else if rep.CommitLimitGB > 0 && memGB+host.StartMarginGB > rep.CommitLimitGB-2 {
|
||||
issues = append(issues, ValidationIssue{Field: "memory", Code: "memory_exceeds_commit", Message: fmt.Sprintf("Memory %.0fG can't fit in Windows' commit limit (%.1f GB including the page file); choose %.0fG or less", memGB, rep.CommitLimitGB, host.RecommendedMemoryGB(rep))})
|
||||
}
|
||||
}
|
||||
if o.Graphics != "" && current.Graphics != "" && o.Graphics != current.Graphics && current.State == "running" {
|
||||
@@ -244,6 +255,9 @@ func BuildCreateArgs(o CreateOpts) ([]string, error) {
|
||||
}
|
||||
if o.MacOS != "" {
|
||||
args = append(args, "--macos", o.MacOS)
|
||||
if o.Offline {
|
||||
args = append(args, "--offline")
|
||||
}
|
||||
}
|
||||
if o.Installer != "" {
|
||||
args = append(args, "--installer", o.Installer)
|
||||
@@ -283,6 +297,8 @@ func BuildCreateArgs(o CreateOpts) ([]string, error) {
|
||||
}
|
||||
if o.Network != nil {
|
||||
args = append(args, "--network", strconv.FormatBool(*o.Network))
|
||||
} else if o.Offline {
|
||||
args = append(args, "--network", "false")
|
||||
}
|
||||
if o.SSHPort > 0 {
|
||||
args = append(args, "--ssh-port", strconv.Itoa(o.SSHPort))
|
||||
@@ -469,6 +485,11 @@ func ParseShow(name, text string) VMDetail {
|
||||
// Redact MAC per docs/shell-design.md §3.
|
||||
d.NetworkSummary = strings.TrimSpace(reMac.ReplaceAllString(v, " (MAC configured)"))
|
||||
d.Network = !strings.EqualFold(v, "off") && !strings.EqualFold(v, "none")
|
||||
if d.SSHPort == 0 {
|
||||
if m := regexp.MustCompile(`ssh on [^:]+:(\d+)`).FindStringSubmatch(v); len(m) == 2 {
|
||||
d.SSHPort, _ = strconv.Atoi(m[1])
|
||||
}
|
||||
}
|
||||
case "ssh":
|
||||
if m := regexp.MustCompile(`(\d+)`).FindString(v); m != "" {
|
||||
d.SSHPort, _ = strconv.Atoi(m)
|
||||
@@ -483,7 +504,8 @@ func ParseShow(name, text string) VMDetail {
|
||||
d.StopTimeout, _ = strconv.Atoi(m)
|
||||
}
|
||||
case "capture":
|
||||
d.Capture = !strings.EqualFold(v, "off") && !strings.EqualFold(v, "false")
|
||||
low := strings.ToLower(strings.TrimSpace(v))
|
||||
d.Capture = !strings.HasPrefix(low, "off") && !strings.HasPrefix(low, "false")
|
||||
case "extra args":
|
||||
d.ExtraArgs = v
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package reims
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -61,3 +62,41 @@ func TestParseShowRedactsMACAndDetectsInstaller(t *testing.T) {
|
||||
t.Fatalf("expected MAC to be redacted, got %q", d.NetworkSummary)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOfflineCreateTurnsNetworkOff(t *testing.T) {
|
||||
args, err := BuildCreateArgs(CreateOpts{Name: "m1", MacOS: "26.7.3", Offline: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := strings.Join(args, " ")
|
||||
if got != "create m1 --macos 26.7.3 --offline --network false" {
|
||||
t.Fatalf("args = %q", got)
|
||||
}
|
||||
on := true
|
||||
args, _ = BuildCreateArgs(CreateOpts{Name: "m1", MacOS: "26.7.3", Offline: true, Network: &on})
|
||||
if got := strings.Join(args, " "); !strings.HasSuffix(got, "--network true") {
|
||||
t.Fatalf("explicit network kept: %q", got)
|
||||
}
|
||||
args, _ = BuildCreateArgs(CreateOpts{Name: "m1", Installer: `D:\i.img`, Offline: true})
|
||||
if got := strings.Join(args, " "); strings.Contains(got, "--offline") {
|
||||
t.Fatalf("--offline only goes with --macos: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseShowCaptureOffAndInlineSSHPort(t *testing.T) {
|
||||
sample := `macos-tahoe
|
||||
state running, pid 1234
|
||||
cpus 8
|
||||
memory 16G
|
||||
disk disk.qcow2 (qcow2, NVMe)
|
||||
display one, in a window opening at 1920x1080, whose size the guest follows
|
||||
capture off: the windows never capture the mouse or the keyboard
|
||||
network user, mac 52:54:00:3c:ce:59, ssh on 127.0.0.1:2222`
|
||||
d := ParseShow("macos-tahoe", sample)
|
||||
if d.Capture {
|
||||
t.Fatalf("expected Capture=false for 'off: ...', got true")
|
||||
}
|
||||
if d.SSHPort != 2222 {
|
||||
t.Fatalf("expected SSHPort=2222, got %d", d.SSHPort)
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,12 @@ type Report struct {
|
||||
ECoreLogicalCPUs []int `json:"e_core_logical_cpus,omitempty"`
|
||||
TotalRAMGB float64 `json:"total_ram_gb"`
|
||||
AvailRAMGB float64 `json:"avail_ram_gb"`
|
||||
// Commit memory: QEMU commits all guest RAM at start (CreateFileMapping), so
|
||||
// a VM needs its memory free in the commit charge, not just in physical RAM.
|
||||
// Measured 2026-11-28: 14.7 GiB commit free with 17.3 GiB physical free, and a
|
||||
// 16G guest failed ("Cannot set up guest memory"). portable-runtime-spec.md §5.1.
|
||||
CommitAvailGB float64 `json:"commit_avail_gb"`
|
||||
CommitLimitGB float64 `json:"commit_limit_gb"`
|
||||
DataRoot string `json:"data_root"`
|
||||
FreeDiskGB float64 `json:"free_disk_gb"`
|
||||
WHPX WHPXState `json:"whpx"`
|
||||
|
||||
@@ -79,6 +79,10 @@ func Inspect(dataRoot string) Report {
|
||||
rep.TotalRAMGB = totalGB
|
||||
rep.AvailRAMGB = availGB
|
||||
}
|
||||
if limitGB, availGB, ok := probeCommitGB(); ok {
|
||||
rep.CommitLimitGB = limitGB
|
||||
rep.CommitAvailGB = availGB
|
||||
}
|
||||
if freeGB, ok := probeFreeDiskGB(dataRoot); ok {
|
||||
rep.FreeDiskGB = freeGB
|
||||
}
|
||||
@@ -220,16 +224,39 @@ func probeHybridTopology() (phys, pCount, eCount int, pMask uint64, pLPs, eLPs [
|
||||
}
|
||||
|
||||
func probeMemoryGB() (totalGB, availGB float64, ok bool) {
|
||||
var ms memoryStatusEx
|
||||
ms.Length = uint32(unsafe.Sizeof(ms))
|
||||
r, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&ms)))
|
||||
if r == 0 {
|
||||
ms, ok := memoryStatus()
|
||||
if !ok {
|
||||
return 0, 0, false
|
||||
}
|
||||
const gb = 1024 * 1024 * 1024
|
||||
return float64(ms.TotalPhys) / gb, float64(ms.AvailPhys) / gb, true
|
||||
}
|
||||
|
||||
// probeCommitGB reads the system commit limit and what is still free in it.
|
||||
// GlobalMemoryStatusEx's "page file" fields are the commit limit and the
|
||||
// available commit for the system (not the page file alone).
|
||||
func probeCommitGB() (limitGB, availGB float64, ok bool) {
|
||||
ms, ok := memoryStatus()
|
||||
if !ok {
|
||||
return 0, 0, false
|
||||
}
|
||||
const gb = 1024 * 1024 * 1024
|
||||
return float64(ms.TotalPageFile) / gb, float64(ms.AvailPageFile) / gb, true
|
||||
}
|
||||
|
||||
func memoryStatus() (memoryStatusEx, bool) {
|
||||
var ms memoryStatusEx
|
||||
ms.Length = uint32(unsafe.Sizeof(ms))
|
||||
r, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&ms)))
|
||||
return ms, r != 0
|
||||
}
|
||||
|
||||
// CommitAvailGB is the commit memory free right now (for start-time checks).
|
||||
func CommitAvailGB() (float64, bool) {
|
||||
_, avail, ok := probeCommitGB()
|
||||
return avail, ok
|
||||
}
|
||||
|
||||
func probeFreeDiskGB(path string) (float64, bool) {
|
||||
vol := filepath.VolumeName(path)
|
||||
if vol != "" {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package host
|
||||
|
||||
// StartMarginGB is the commit memory a VM needs beyond its guest RAM: QEMU's own
|
||||
// allocations and the graphics path. Conservative; refine with measurements.
|
||||
const StartMarginGB = 1.0
|
||||
|
||||
// memoryChoices are the sizes the UI offers (GB).
|
||||
var memoryChoices = []float64{4, 6, 8, 12, 16, 24, 32, 48, 64}
|
||||
|
||||
// RecommendedMemoryGB is the largest offered size that fits both in 60% of
|
||||
// physical RAM and in the commit memory free now (minus StartMarginGB and 2 GB
|
||||
// headroom for the host). At least 4.
|
||||
func RecommendedMemoryGB(rep Report) float64 {
|
||||
limit := rep.TotalRAMGB * 0.6
|
||||
if rep.CommitAvailGB > 0 {
|
||||
if c := rep.CommitAvailGB - StartMarginGB - 2; c < limit {
|
||||
limit = c
|
||||
}
|
||||
}
|
||||
best := memoryChoices[0]
|
||||
for _, m := range memoryChoices {
|
||||
if m <= limit {
|
||||
best = m
|
||||
}
|
||||
}
|
||||
return best
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
//go:build !windows
|
||||
|
||||
package host
|
||||
|
||||
// CommitAvailGB is unknown on dev/preview hosts.
|
||||
func CommitAvailGB() (float64, bool) { return 0, false }
|
||||
@@ -0,0 +1,19 @@
|
||||
package host
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRecommendedMemoryFollowsCommitMemory(t *testing.T) {
|
||||
// The measured case: 32 GB host, 14.7 GiB commit free -> 16G fails, 8G fits.
|
||||
if got := RecommendedMemoryGB(Report{TotalRAMGB: 31.8, CommitAvailGB: 14.7}); got != 8 {
|
||||
t.Fatalf("got %v, want 8", got)
|
||||
}
|
||||
if got := RecommendedMemoryGB(Report{TotalRAMGB: 64, CommitAvailGB: 60}); got != 32 {
|
||||
t.Fatalf("got %v, want 32", got)
|
||||
}
|
||||
if got := RecommendedMemoryGB(Report{TotalRAMGB: 8, CommitAvailGB: 3}); got != 4 {
|
||||
t.Fatalf("got %v, want the 4 GB floor", got)
|
||||
}
|
||||
if got := RecommendedMemoryGB(Report{TotalRAMGB: 32}); got != 16 {
|
||||
t.Fatalf("unknown commit: got %v, want 16", got)
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,7 @@ var catalog = map[Locale]map[string]string{
|
||||
"vm.install_guide.step2": "2. 退出磁盘工具,选择「重新安装 macOS Tahoe」并等待完成。",
|
||||
"vm.install_guide.step3": "3. 进入桌面后,运行 `reims-go vm eject %s`(或在界面点击「弹出安装盘」)。",
|
||||
"err.runtime_not_installed": "未找到已激活的便携运行时,请先执行 `reims-go runtime install <归档路径>`",
|
||||
"err.commit_memory": "内存不够启动:这台虚拟机要 %.0f GB,Windows 现在只能再分配 %.1f GB。关掉一些程序再试,或在设置里把内存改为 %.0f GB",
|
||||
"installer.paused": "已暂停。再次运行 `reims-go installer download %s` 会从中断处继续。",
|
||||
"installer.done": "离线安装包已就绪:macOS %s -> %s",
|
||||
"installer.cached.empty": "还没有下载任何安装包。",
|
||||
@@ -103,6 +104,7 @@ var catalog = map[Locale]map[string]string{
|
||||
"vm.install_guide.step2": "2. Quit Disk Utility, choose 'Reinstall macOS Tahoe', and wait for completion.",
|
||||
"vm.install_guide.step3": "3. Once on the desktop, run `reims-go vm eject %s` (or click 'Eject Installer').",
|
||||
"err.runtime_not_installed": "no active portable runtime found; run `reims-go runtime install <archive>` first",
|
||||
"err.commit_memory": "Not enough memory to start: this VM needs %.0f GB and Windows can commit only %.1f GB more. Close some programs, or set its memory to %.0f GB",
|
||||
"installer.paused": "Paused. Run `reims-go installer download %s` again to continue where it stopped.",
|
||||
"installer.done": "Offline installer ready: macOS %s -> %s",
|
||||
"installer.cached.empty": "No installers downloaded yet.",
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Nwflower/reims-go/internal/driver/reims"
|
||||
"github.com/Nwflower/reims-go/internal/host"
|
||||
"github.com/Nwflower/reims-go/internal/i18n"
|
||||
)
|
||||
|
||||
// checkStartMemory refuses to start a VM whose guest RAM can't be committed
|
||||
// right now. Without it QEMU exits with "Cannot set up guest memory 'ram'"
|
||||
// (measured 2026-11-28, portable-runtime-spec.md §5.1), which says nothing
|
||||
// about what to do.
|
||||
func (a *App) checkStartMemory(c *reims.Client, name string) error {
|
||||
avail, ok := host.CommitAvailGB()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
d, err := a.GetVMDetail(name)
|
||||
if err != nil {
|
||||
return nil // can't tell; let reims-ctl report its own error
|
||||
}
|
||||
memGB, ok := reims.ParseSizeGB(d.Memory)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if memGB+host.StartMarginGB <= avail {
|
||||
return nil
|
||||
}
|
||||
a.mu.Lock()
|
||||
loc := a.cfg.Locale
|
||||
root := a.cfg.DataRoot
|
||||
a.mu.Unlock()
|
||||
rec := host.RecommendedMemoryGB(host.Inspect(root))
|
||||
return fmt.Errorf("%s", i18n.T(loc, "err.commit_memory", memGB, avail, rec))
|
||||
}
|
||||
+34
-1
@@ -9,6 +9,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Nwflower/reims-go/internal/config"
|
||||
"github.com/Nwflower/reims-go/internal/installer"
|
||||
@@ -29,9 +31,39 @@ func (a *App) includeCandidate() bool {
|
||||
return a.cfg.RuntimeChannel == rt.ChannelCandidate
|
||||
}
|
||||
|
||||
// remoteCache keeps the release list for a while: GitHub allows 60
|
||||
// unauthenticated API requests an hour, and the host page, first launch and
|
||||
// the CLI all ask for it.
|
||||
var remoteCache struct {
|
||||
sync.Mutex
|
||||
at time.Time
|
||||
candidate bool
|
||||
list []rt.Remote
|
||||
}
|
||||
|
||||
const remoteCacheTTL = 10 * time.Minute
|
||||
|
||||
// ListRemoteRuntimes lists published runtimes for the configured channel.
|
||||
func (a *App) ListRemoteRuntimes() ([]rt.Remote, error) {
|
||||
return rt.DefaultSource().ListRemote(a.baseCtx(), a.includeCandidate())
|
||||
cand := a.includeCandidate()
|
||||
remoteCache.Lock()
|
||||
defer remoteCache.Unlock()
|
||||
if remoteCache.list != nil && remoteCache.candidate == cand && time.Since(remoteCache.at) < remoteCacheTTL {
|
||||
return remoteCache.list, nil
|
||||
}
|
||||
list, err := rt.DefaultSource().ListRemote(a.baseCtx(), cand)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
remoteCache.at, remoteCache.candidate, remoteCache.list = time.Now(), cand, list
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// forgetRemoteRuntimes drops the cached list (after an install or a channel change).
|
||||
func forgetRemoteRuntimes() {
|
||||
remoteCache.Lock()
|
||||
remoteCache.list = nil
|
||||
remoteCache.Unlock()
|
||||
}
|
||||
|
||||
// SetRuntimeChannel picks "stable" or "candidate" for online installs.
|
||||
@@ -42,6 +74,7 @@ func (a *App) SetRuntimeChannel(channel string) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
a.cfg.RuntimeChannel = channel
|
||||
forgetRemoteRuntimes()
|
||||
return config.Save("", a.cfg)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user