392 lines
16 KiB
Go
392 lines
16 KiB
Go
// Package installguide presents the installation workflow on the guest window.
|
||
package installguide
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"github.com/Nwflower/reims-go/internal/i18n"
|
||
)
|
||
|
||
type Kind int
|
||
|
||
const (
|
||
Online Kind = iota
|
||
Offline
|
||
BuiltIn
|
||
)
|
||
|
||
type Theme string
|
||
|
||
const (
|
||
ThemeLight Theme = "light"
|
||
ThemeDark Theme = "dark"
|
||
)
|
||
|
||
const OfflineCommand = "sh /Volumes/REIMSHELP/install.sh"
|
||
const ToolsCommand = "sh /Volumes/REIMSTOOLS/Install-Reims-Tools.command"
|
||
|
||
type Guide struct {
|
||
Name string
|
||
PID uint32
|
||
Kind Kind
|
||
ReleaseKeys string
|
||
Locale i18n.Locale
|
||
Theme Theme
|
||
ToolsAttached bool
|
||
CurrentPreferences func() (i18n.Locale, Theme)
|
||
Unfold <-chan struct{}
|
||
TypeText func(string) error
|
||
FinishRecovery func() error
|
||
Restart func() error
|
||
AttachImage func(string) error
|
||
AttachTools func() error
|
||
LogError func(error)
|
||
dir, media string
|
||
initial page
|
||
}
|
||
|
||
type page string
|
||
|
||
const (
|
||
boot page = "boot"
|
||
terminal page = "terminal"
|
||
command page = "command"
|
||
verifyCommand page = "verify-command"
|
||
selectDisk page = "select-disk"
|
||
formatDisk page = "format-disk"
|
||
reinstall page = "reinstall"
|
||
waitInstall page = "installing"
|
||
recoverMenu page = "recovery"
|
||
mediaChoice page = "media"
|
||
pickImage page = "pick-image"
|
||
confirmImage page = "confirm-image"
|
||
mounting page = "mounting"
|
||
confirm page = "confirm-install"
|
||
confirmRepair page = "confirm-repair"
|
||
restartPending page = "restart-pending"
|
||
working page = "restarting"
|
||
setup page = "setup"
|
||
network page = "network"
|
||
account page = "account"
|
||
localUser page = "local-user"
|
||
preferences page = "preferences"
|
||
desktop page = "desktop"
|
||
restored page = "restored"
|
||
toolsTerminal page = "tools-terminal"
|
||
confirmTools page = "confirm-tools"
|
||
mountTools page = "mount-tools"
|
||
toolsVerify page = "tools-verify"
|
||
typingCommand page = "typing"
|
||
typingTools page = "typing-tools"
|
||
failed page = "failed"
|
||
compact page = "compact"
|
||
done page = "done"
|
||
)
|
||
|
||
type tone int
|
||
|
||
const (
|
||
toneAccent tone = iota
|
||
toneOK
|
||
toneWarn
|
||
toneDanger
|
||
)
|
||
|
||
type content struct {
|
||
stage string
|
||
stageTone tone
|
||
title string
|
||
body string
|
||
code string
|
||
left string
|
||
right string
|
||
extra string
|
||
jump string
|
||
fold string
|
||
inputHint string
|
||
prev page
|
||
next page
|
||
alt page
|
||
isConfirm bool
|
||
}
|
||
|
||
func (g Guide) preferences() (i18n.Locale, Theme) {
|
||
if g.CurrentPreferences != nil {
|
||
return g.CurrentPreferences()
|
||
}
|
||
return g.Locale, g.Theme
|
||
}
|
||
|
||
func (p page) confirmsRestart() bool {
|
||
switch p {
|
||
case confirm, confirmRepair, confirmImage, confirmTools:
|
||
return true
|
||
}
|
||
return false
|
||
}
|
||
|
||
func (g Guide) content(p page, detail string) content {
|
||
loc, _ := g.preferences()
|
||
t := func(zh, en string) string {
|
||
if loc == i18n.ZhCN {
|
||
return zh
|
||
}
|
||
return en
|
||
}
|
||
c := content{fold: t("收起", "Hide"), isConfirm: p.confirmsRestart()}
|
||
stage := func(zh, en string, step, total int, tn tone) {
|
||
label := t(zh, en)
|
||
if step > 0 && total > 0 {
|
||
c.stage = fmt.Sprintf("%s · %d / %d", label, step, total)
|
||
} else {
|
||
c.stage = label
|
||
}
|
||
c.stageTone = tn
|
||
}
|
||
card := func(zhTitle, enTitle, zhBody, enBody string) {
|
||
c.title = t(zhTitle, enTitle)
|
||
c.body = t(zhBody, enBody)
|
||
}
|
||
next := func(dst page, zh, en string) { c.next = dst; c.right = t(zh, en) }
|
||
extra := func(dst page, zh, en string) { c.alt = dst; c.extra = t(zh, en) }
|
||
back := func(dst page) { c.prev = dst; c.left = t("上一步", "Back") }
|
||
cancel := func(dst page) { c.prev = dst; c.left = t("取消", "Cancel") }
|
||
finish := func() { next(done, "完成", "Done") }
|
||
|
||
switch p {
|
||
case boot:
|
||
switch g.Kind {
|
||
case Offline, Online:
|
||
card("等待进入恢复界面", "Wait for Recovery",
|
||
"等待苹果标志和进度条结束。若出现语言选择,选好后继续;看到恢复工具列表即可下一步。",
|
||
"Wait for the Apple logo and progress bar. Pick a language if asked, then continue when Recovery utilities appear.")
|
||
if g.Kind == Offline {
|
||
stage("离线安装", "Offline install", 1, 5, toneAccent)
|
||
next(terminal, "继续", "Continue")
|
||
} else {
|
||
stage("在线恢复", "Online recovery", 1, 5, toneAccent)
|
||
next(selectDisk, "继续", "Continue")
|
||
}
|
||
case BuiltIn:
|
||
stage("内置恢复", "Built-in recovery", 1, 2, toneAccent)
|
||
card("在引导菜单选 Recovery", "Select Recovery in boot menu",
|
||
"在 OpenCore 启动菜单选「Recovery」按回车,等恢复工具列表出现后继续。",
|
||
"Choose Recovery in the OpenCore boot picker and press Return. Continue when the recovery utilities appear.")
|
||
next(recoverMenu, "继续", "Continue")
|
||
}
|
||
case terminal:
|
||
stage("离线安装", "Offline install", 2, 5, toneAccent)
|
||
card("打开恢复终端", "Open Recovery Terminal",
|
||
"在顶部菜单栏打开「实用工具 › 终端」(Utilities › Terminal),不要点「重新安装 macOS」。",
|
||
"Open Utilities › Terminal from the menu bar. Don’t click Reinstall macOS.")
|
||
back(boot)
|
||
next(command, "继续", "Continue")
|
||
case command:
|
||
stage("离线安装", "Offline install", 3, 5, toneAccent)
|
||
card("键入安装命令", "Type installer command",
|
||
"点「键入命令」自动输入到终端。脚本会抹除空白磁盘为 APFS 并启动安装。",
|
||
"Click Type command to send this to Terminal. It formats a blank disk as APFS and starts installation.")
|
||
c.code = OfflineCommand
|
||
back(terminal)
|
||
next(typingCommand, "键入命令", "Type command")
|
||
extra(verifyCommand, "已手动输入", "Already typed it")
|
||
case verifyCommand:
|
||
stage("离线安装", "Offline install", 4, 5, toneAccent)
|
||
card("在终端按回车运行", "Press Return in Terminal",
|
||
"核对终端命令后按回车;若提示抹盘,确认是目标磁盘再继续。看到安装进度后点下一步。",
|
||
"Check the command in Terminal and press Return. Confirm the target disk if asked, then continue once installation starts.")
|
||
back(command)
|
||
next(waitInstall, "继续", "Continue")
|
||
case selectDisk:
|
||
stage("在线恢复", "Online recovery", 2, 5, toneAccent)
|
||
card("选择目标磁盘", "Select target disk",
|
||
"全新空盘打开「磁盘工具」,选「显示 › 显示所有设备」,按容量找到 QEMU 磁盘;已有 APFS 卷可直接重装。",
|
||
"For a blank disk, open Disk Utility › View › Show All Devices and find the QEMU disk by size, or use an existing APFS volume.")
|
||
back(boot)
|
||
next(formatDisk, "抹掉空盘", "Erase disk")
|
||
extra(reinstall, "使用现有 APFS 卷", "Use existing APFS volume")
|
||
case formatDisk:
|
||
stage("在线恢复", "Online recovery", 3, 5, toneAccent)
|
||
card("抹掉空白系统盘", "Erase blank disk",
|
||
"确认选中目标空盘后点「抹掉」:名称 Macintosh HD,格式 APFS,方案 GUID 分区图。完成后退出磁盘工具。",
|
||
"Click Erase on the blank disk: name Macintosh HD, format APFS, scheme GUID Partition Map. Quit Disk Utility when finished.")
|
||
back(selectDisk)
|
||
next(reinstall, "继续", "Continue")
|
||
case reinstall:
|
||
if g.Kind == BuiltIn {
|
||
stage("内置恢复", "Built-in recovery", 0, 0, toneAccent)
|
||
back(mediaChoice)
|
||
} else {
|
||
stage("在线恢复", "Online recovery", 4, 5, toneAccent)
|
||
back(selectDisk)
|
||
}
|
||
card("开始安装 macOS", "Start macOS install",
|
||
"在恢复工具选「重新安装 macOS」,选择目标系统卷并继续。出现安装进度条后点下一步。",
|
||
"Choose Reinstall macOS in Recovery and select the target system volume. Continue once the progress bar appears.")
|
||
next(waitInstall, "继续", "Continue")
|
||
case waitInstall:
|
||
switch g.Kind {
|
||
case Offline:
|
||
stage("离线安装", "Offline install", 5, 5, toneAccent)
|
||
back(verifyCommand)
|
||
case Online:
|
||
stage("在线恢复", "Online recovery", 5, 5, toneAccent)
|
||
back(reinstall)
|
||
default:
|
||
stage("内置恢复", "Built-in recovery", 0, 0, toneAccent)
|
||
back(reinstall)
|
||
}
|
||
card("等待安装完成", "Wait for installation",
|
||
"进度条可能停留较久,中途会重启几次。看到「设置助理」或 Apple 账户页后,退出恢复模式。",
|
||
"Progress may pause and the VM restarts several times. Exit recovery once Setup Assistant or Apple Account appears.")
|
||
next(confirm, "退出恢复…", "Exit recovery…")
|
||
case recoverMenu:
|
||
stage("内置恢复", "Built-in recovery", 2, 2, toneAccent)
|
||
card("使用恢复工具", "Use recovery utilities",
|
||
"可使用磁盘工具修复或排查问题;重装系统可选在线恢复或挂载本地镜像。",
|
||
"Use Disk Utility or other recovery tools here, or choose to reinstall macOS online or from a local image.")
|
||
back(boot)
|
||
next(confirmRepair, "退出恢复…", "Exit recovery…")
|
||
extra(mediaChoice, "重新安装 macOS", "Reinstall macOS")
|
||
case mediaChoice:
|
||
stage("内置恢复", "Built-in recovery", 0, 0, toneAccent)
|
||
card("选择重装方式", "Choose reinstall source",
|
||
"在线重装直接使用当前恢复环境;本地镜像将在挂载并重启虚拟机后启动。",
|
||
"Online reinstall uses this recovery environment. A local image boots after attaching it and restarting the VM.")
|
||
back(recoverMenu)
|
||
next(reinstall, "在线重装", "Reinstall online")
|
||
extra(pickImage, "选择本地镜像…", "Choose local image…")
|
||
case confirmImage:
|
||
stage("确认重启", "Confirm restart", 0, 0, toneWarn)
|
||
card("挂载镜像并重启?", "Attach image and restart?",
|
||
"确认当前恢复操作已结束。继续会挂载该镜像并重启虚拟机。",
|
||
"Make sure recovery work is done. Continuing attaches this image and restarts the VM.")
|
||
c.code = detail
|
||
cancel(mediaChoice)
|
||
next(mounting, "挂载并重启", "Attach and restart")
|
||
case confirm, confirmRepair:
|
||
stage("确认重启", "Confirm restart", 0, 0, toneWarn)
|
||
card("退出恢复模式并重启?", "Exit recovery and restart?",
|
||
"若仍有安装进度条,返回继续等待。确认后会退出恢复模式、启用网络并重启「"+g.Name+"」。",
|
||
"If installation is still running, go back and wait. Confirm to exit recovery, enable networking and restart “"+g.Name+"”.")
|
||
if p == confirmRepair {
|
||
cancel(recoverMenu)
|
||
} else {
|
||
cancel(waitInstall)
|
||
}
|
||
next(working, "退出并重启", "Exit and restart")
|
||
case restartPending:
|
||
stage("等待重启", "Restart required", 0, 0, toneWarn)
|
||
card("重启虚拟机以生效", "Restart VM to apply",
|
||
"配置已更新,重启这台虚拟机后即可生效。",
|
||
"Settings were updated. Restart this VM to apply the changes.")
|
||
next(working, "重启虚拟机", "Restart VM")
|
||
case setup:
|
||
stage("设置助理", "Setup Assistant", 1, 6, toneAccent)
|
||
card("选择地区与键盘", "Region and keyboard",
|
||
"等待系统盘启动。在设置助理中选好国家或地区、语言和键盘,已完成可直接下一步。",
|
||
"Wait for macOS to boot, then choose your country or region, language and keyboard.")
|
||
next(network, "继续", "Continue")
|
||
extra(desktop, "已进入桌面", "Already at desktop")
|
||
case network:
|
||
stage("设置助理", "Setup Assistant", 2, 6, toneAccent)
|
||
card("连接虚拟以太网", "Connect via Ethernet",
|
||
"网络现已启用。若提示联网,选择虚拟以太网;已自动连接可直接继续。",
|
||
"Networking is enabled. Choose virtual Ethernet if prompted, or continue if already connected.")
|
||
back(setup)
|
||
next(account, "继续", "Continue")
|
||
case account:
|
||
stage("设置助理", "Setup Assistant", 3, 6, toneAccent)
|
||
card("登录 Apple 账户", "Sign in to Apple Account",
|
||
"可直接登录 Apple 账户;若想稍后再登,点「其他登录选项」并选「稍后设置」。",
|
||
"Sign in to your Apple Account, or choose Other Sign-In Options › Set Up Later.")
|
||
back(network)
|
||
next(localUser, "继续", "Continue")
|
||
case localUser:
|
||
stage("设置助理", "Setup Assistant", 4, 6, toneAccent)
|
||
card("创建本地账户", "Create local account",
|
||
"填写 macOS 用户名与登录密码;覆盖重装保留原账户时,直接登录即可。",
|
||
"Enter a local user name and password, or sign in to an existing account after a reinstall.")
|
||
back(account)
|
||
next(preferences, "继续", "Continue")
|
||
case preferences:
|
||
stage("设置助理", "Setup Assistant", 5, 6, toneAccent)
|
||
card("完成其余系统选项", "Finish setup screens",
|
||
"按需完成隐私、定位与外观等页面,看到程序坞与顶部菜单栏即进入桌面。",
|
||
"Finish the remaining privacy, location and appearance screens until the Dock and menu bar appear.")
|
||
back(localUser)
|
||
next(desktop, "继续", "Continue")
|
||
case desktop:
|
||
stage("设置助理", "Setup Assistant", 6, 6, toneOK)
|
||
card("已进入 macOS 桌面", "macOS is ready",
|
||
"现在可以开始使用 macOS。如需双向剪贴板和共享文件夹,可选装 Guest Tools。",
|
||
"macOS is ready to use. Optionally install Guest Tools for shared clipboard and folders.")
|
||
back(preferences)
|
||
finish()
|
||
if g.ToolsAttached {
|
||
extra(toolsTerminal, "安装 Guest Tools", "Install Guest Tools")
|
||
} else {
|
||
extra(confirmTools, "挂载 Guest Tools…", "Attach Guest Tools…")
|
||
}
|
||
case confirmTools:
|
||
stage("确认重启", "Confirm restart", 0, 0, toneWarn)
|
||
card("挂载工具盘并重启?", "Attach Guest Tools and restart?",
|
||
"先保存桌面上的内容。继续会挂载 REIMSTOOLS 工具盘并重启虚拟机。",
|
||
"Save open work first. Continuing attaches the REIMSTOOLS disk and restarts the VM.")
|
||
cancel(desktop)
|
||
next(mountTools, "挂载并重启", "Attach and restart")
|
||
case toolsTerminal:
|
||
stage("Guest Tools", "Guest Tools", 1, 2, toneAccent)
|
||
card("在 macOS 中打开终端", "Open Terminal in macOS",
|
||
"打开「应用程序 › 实用工具 › 终端」,点下方按钮键入安装命令。",
|
||
"Open Applications › Utilities › Terminal, then click below to type the command.")
|
||
c.code = ToolsCommand
|
||
back(desktop)
|
||
next(typingTools, "键入命令", "Type command")
|
||
case toolsVerify:
|
||
stage("Guest Tools", "Guest Tools", 2, 2, toneOK)
|
||
card("完成 Guest Tools 安装", "Finish Guest Tools setup",
|
||
"在终端核对命令后按回车,按提示完成安装即可使用剪贴板与共享文件夹。",
|
||
"Check the command in Terminal, press Return and follow the prompts to finish.")
|
||
back(toolsTerminal)
|
||
finish()
|
||
case restored:
|
||
stage("已回到系统", "Back on macOS", 0, 0, toneOK)
|
||
card("从系统盘继续", "Continue from system disk",
|
||
"可正常登录 macOS。若进入设置助理,可继续查看联网与账户步骤。",
|
||
"Sign in to macOS as usual, or continue with Setup Assistant guidance if it appears.")
|
||
extra(setup, "查看设置助理引导", "Open Setup Assistant guide")
|
||
finish()
|
||
case failed:
|
||
stage("出错", "Error", 0, 0, toneDanger)
|
||
card("操作未完成", "Could not complete step", detail, detail)
|
||
c.left = t("返回", "Back")
|
||
case typingCommand, typingTools, working, mounting, mountTools:
|
||
stage("进行中", "Working", 0, 0, toneAccent)
|
||
if p == typingCommand || p == typingTools {
|
||
card("正在键入命令", "Typing command",
|
||
"等待命令输入到终端…",
|
||
"Waiting for the command to appear in Terminal…")
|
||
} else {
|
||
card("正在重启虚拟机", "Restarting VM",
|
||
"等待虚拟机窗口重新打开…",
|
||
"Waiting for the VM window to reopen…")
|
||
}
|
||
case compact:
|
||
return content{right: t("安装引导", "Install guide")}
|
||
}
|
||
if (c.next == "" && c.prev == "" && c.alt == "") || c.isConfirm {
|
||
c.fold = ""
|
||
}
|
||
if p == boot && g.ReleaseKeys != "" {
|
||
c.inputHint = t("释放键鼠:", "Release input: ") + g.ReleaseKeys
|
||
}
|
||
// The guest may be ahead of the guide when the user follows the installer
|
||
// directly. Keep the setup handoff reachable from earlier install screens.
|
||
switch p {
|
||
case boot, terminal, command, verifyCommand, selectDisk, formatDisk, reinstall:
|
||
c.jump = t("已到设置助理?退出恢复模式", "At Setup Assistant? Exit recovery")
|
||
}
|
||
return c
|
||
}
|