// 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 GuestLang string // OpenCore prev-lang:kbd (e.g. "en-US:0", "zh-Hans:0", "ja-JP:0") 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 cancel string disableRight bool } func (g Guide) preferences() (i18n.Locale, Theme) { if g.CurrentPreferences != nil { loc, th := g.CurrentPreferences() return i18n.EffectiveLocale(loc), th } return i18n.EffectiveLocale(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() tr := func(key string) string { return i18n.T(loc, key) } trv := func(key string, vars i18n.Vars) string { return i18n.M(loc, key, vars) } gt := func(termKey string, bracketed bool) string { return i18n.FormatGuestTerm(loc, g.GuestLang, termKey, bracketed) } c := content{fold: tr("guide.btn.fold"), isConfirm: p.confirmsRestart()} stage := func(stageKey string, step, total int, tn tone) { label := tr(stageKey) if step > 0 && total > 0 { c.stage = fmt.Sprintf("%s · %d / %d", label, step, total) } else { c.stage = label } c.stageTone = tn } card := func(titleKey, bodyKey string, vars i18n.Vars) { c.title = trv(titleKey, vars) c.body = trv(bodyKey, vars) } next := func(dst page, btnKey string) { c.next = dst; c.right = tr(btnKey) } extra := func(dst page, btnKey string) { c.alt = dst; c.extra = tr(btnKey) } back := func(dst page) { c.prev = dst; c.left = tr("guide.btn.back") } cancel := func(dst page) { c.prev = dst; c.left = tr("guide.btn.cancel") } finish := func() { next(done, "guide.btn.done") } switch p { case boot: switch g.Kind { case Offline, Online: card("guide.boot.recovery.title", "guide.boot.recovery.body", nil) if g.Kind == Offline { stage("guide.stage.offline", 1, 5, toneAccent) next(terminal, "guide.btn.continue") } else { stage("guide.stage.online", 1, 5, toneAccent) next(selectDisk, "guide.btn.continue") } case BuiltIn: stage("guide.stage.builtin", 1, 2, toneAccent) // OpenCore picker itself shows "Recovery" in Latin text recLabel := "Recovery" if i18n.IsCJKLocale(loc) { recLabel = "「Recovery」" } card("guide.boot.builtin.title", "guide.boot.builtin.body", i18n.Vars{"recovery": recLabel}) next(recoverMenu, "guide.btn.continue") } case terminal: stage("guide.stage.offline", 2, 5, toneAccent) card("guide.terminal.title", "guide.terminal.body", i18n.Vars{ "utilitiesTerminal": gt("macos.utilitiesTerminal", true), "reinstallMacOS": gt("macos.reinstallMacOS", true), }) back(boot) next(command, "guide.btn.continue") case command: stage("guide.stage.offline", 3, 5, toneAccent) card("guide.command.title", "guide.command.body", nil) c.code = OfflineCommand back(terminal) next(typingCommand, "guide.command.btn.type") extra(verifyCommand, "guide.command.btn.typed") case verifyCommand: stage("guide.stage.offline", 4, 5, toneAccent) card("guide.verify.title", "guide.verify.body", nil) back(command) next(waitInstall, "guide.btn.continue") case selectDisk: stage("guide.stage.online", 2, 5, toneAccent) card("guide.select_disk.title", "guide.select_disk.body", i18n.Vars{ "diskUtility": gt("macos.diskUtility", true), "showAllDevices": gt("macos.showAllDevices", true), "volume": gt("macos.volume", false), }) back(boot) next(formatDisk, "guide.select_disk.btn.erase") extra(reinstall, "guide.select_disk.btn.existing") case formatDisk: stage("guide.stage.online", 3, 5, toneAccent) card("guide.format_disk.title", "guide.format_disk.body", i18n.Vars{ "erase": gt("macos.erase", true), "guidMap": gt("macos.guidPartitionMap", false), "diskUtilityPlain": gt("macos.diskUtility", false), }) back(selectDisk) next(reinstall, "guide.btn.continue") case reinstall: if g.Kind == BuiltIn { stage("guide.stage.builtin", 0, 0, toneAccent) back(mediaChoice) } else { stage("guide.stage.online", 4, 5, toneAccent) back(selectDisk) } card("guide.reinstall.title", "guide.reinstall.body", i18n.Vars{ "reinstallMacOS": gt("macos.reinstallMacOS", true), }) next(waitInstall, "guide.btn.continue") case waitInstall: switch g.Kind { case Offline: stage("guide.stage.offline", 5, 5, toneAccent) back(verifyCommand) case Online: stage("guide.stage.online", 5, 5, toneAccent) back(reinstall) default: stage("guide.stage.builtin", 0, 0, toneAccent) back(reinstall) } card("guide.wait_install.title", "guide.wait_install.body", i18n.Vars{ "setupAssistant": gt("macos.setupAssistant", true), }) next(confirm, "guide.btn.exit_recovery") case recoverMenu: stage("guide.stage.builtin", 2, 2, toneAccent) card("guide.recover_menu.title", "guide.recover_menu.body", i18n.Vars{ "diskUtility": gt("macos.diskUtility", true), }) back(boot) next(confirmRepair, "guide.btn.exit_recovery") extra(mediaChoice, "guide.recover_menu.btn.reinstall") case mediaChoice: stage("guide.stage.builtin", 0, 0, toneAccent) card("guide.media_choice.title", "guide.media_choice.body", nil) back(recoverMenu) next(reinstall, "guide.media_choice.btn.online") extra(pickImage, "guide.media_choice.btn.local") case confirmImage: stage("guide.stage.confirm_restart", 0, 0, toneWarn) card("guide.confirm_image.title", "guide.confirm_image.body", nil) c.code = detail cancel(mediaChoice) next(mounting, "guide.btn.attach_restart") case confirm, confirmRepair: stage("guide.stage.confirm_restart", 0, 0, toneWarn) card("guide.confirm_exit.title", "guide.confirm_exit.body", i18n.Vars{"name": g.Name}) if p == confirmRepair { cancel(recoverMenu) } else { cancel(waitInstall) } next(working, "guide.confirm_exit.btn") case restartPending: stage("guide.stage.restart_pending", 0, 0, toneWarn) card("guide.restart_pending.title", "guide.restart_pending.body", nil) next(working, "guide.restart_pending.btn") case setup: stage("guide.stage.setup_assistant", 1, 6, toneAccent) card("guide.setup.region.title", "guide.setup.region.body", i18n.Vars{ "setupAssistantPlain": gt("macos.setupAssistant", false), }) next(network, "guide.btn.continue") extra(desktop, "guide.setup.btn.at_desktop") case network: stage("guide.stage.setup_assistant", 2, 6, toneAccent) card("guide.setup.network.title", "guide.setup.network.body", nil) back(setup) next(account, "guide.btn.continue") case account: stage("guide.stage.setup_assistant", 3, 6, toneAccent) card("guide.setup.account.title", "guide.setup.account.body", i18n.Vars{ "otherSignInLater": gt("macos.otherSignInSetUpLater", true), }) back(network) next(localUser, "guide.btn.continue") case localUser: stage("guide.stage.setup_assistant", 4, 6, toneAccent) card("guide.setup.user.title", "guide.setup.user.body", nil) back(account) next(preferences, "guide.btn.continue") case preferences: stage("guide.stage.setup_assistant", 5, 6, toneAccent) card("guide.setup.prefs.title", "guide.setup.prefs.body", nil) back(localUser) next(desktop, "guide.btn.continue") case desktop: stage("guide.stage.setup_assistant", 6, 6, toneOK) card("guide.setup.desktop.title", "guide.setup.desktop.body", nil) back(preferences) finish() if g.ToolsAttached { extra(toolsTerminal, "guide.setup.btn.install_tools") } else { extra(confirmTools, "guide.setup.btn.attach_tools") } case confirmTools: stage("guide.stage.confirm_restart", 0, 0, toneWarn) card("guide.confirm_tools.title", "guide.confirm_tools.body", nil) cancel(desktop) next(mountTools, "guide.btn.attach_restart") case toolsTerminal: stage("guide.stage.guest_tools", 1, 2, toneAccent) card("guide.tools_terminal.title", "guide.tools_terminal.body", i18n.Vars{ "appsUtilitiesTerminal": gt("macos.appsUtilitiesTerminal", true), }) c.code = ToolsCommand back(desktop) next(typingTools, "guide.command.btn.type") case toolsVerify: stage("guide.stage.guest_tools", 2, 2, toneOK) card("guide.tools_verify.title", "guide.tools_verify.body", nil) back(toolsTerminal) finish() case restored: stage("guide.stage.restored", 0, 0, toneOK) card("guide.restored.title", "guide.restored.body", i18n.Vars{ "setupAssistantPlain": gt("macos.setupAssistant", false), }) extra(setup, "guide.restored.btn.guide") finish() case failed: stage("guide.stage.error", 0, 0, toneDanger) c.title = tr("guide.failed.title") c.body = detail c.left = tr("guide.btn.return") case typingCommand, typingTools, working, mounting, mountTools: stage("guide.stage.working", 0, 0, toneAccent) if p == typingCommand || p == typingTools { card("guide.working.typing.title", "guide.working.typing.body", nil) } else { card("guide.working.restarting.title", "guide.working.restarting.body", nil) } case compact: return content{right: tr("guide.compact.label")} } if (c.next == "" && c.prev == "" && c.alt == "") || c.isConfirm { c.fold = "" } if p == boot && g.ReleaseKeys != "" { c.inputHint = trv("guide.hint.release_input", i18n.Vars{"keys": 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 = trv("guide.jump.setup_assistant", i18n.Vars{ "setupAssistant": gt("macos.setupAssistant", false), }) } return c }