* feat(plugin,host,ui): add agent session takeover, protected-phase confirmation, and autoinstall host foundation * feat(macos,ui,cli): add offline REIMSPROV first-boot provisioning to skip Setup Assistant (#129) Builds a per-VM read-only REIMSPROV disk image containing a pure-Go XAR Distribution flat package (provision.pkg) and an offline Recovery fallback script (provision-offline.sh). Passwords are hashed in memory to Apple SALTED-SHA512-PBKDF2 bplist00 ShadowHashData (never persisted in plaintext, no auto-login or NOPASSWD sudo). Uses native OpenDirectory.framework (JXA NSData) + dseditgroup under SIP-enabled live bootinstalld and dslocal plist + PlistBuddy under offline Recovery, skips Setup Assistant and Keyboard Setup Assistant, pre-stages Guest Tools, integrates with CreateWizard / VMPage / vm provision CLI / StartAutoInstall, and zero-wipes on finish_install, normal cold start, or DeleteVM. * feat(autoinstall,host,ui): add input-locked session shield, recovery-only mode, and restart grace cap Adds the real-machine end-to-end verified baseline for automatic macOS installation: (1) takeover_policy 'lock' with transparent Win32 VM client-area input shield, low-level key/mouse lock preserving host escape shortcuts (Alt+Tab/Alt+Esc/Win), HUD & UI Pause/Resume controls, and write guards while paused; (2) decoupled recovery_only vs full (REIMSPROV) modes in StartAutoInstall, CreateWizard, and VMAutoInstallPanel; (3) graceful_timeout_sec cap (default 10s) on automated built-in macOS host/vm.restart so Setup Assistant/Login Window restarts do not stall 90s on ACPI; (4) additional modifier aliases in console manager and agent-session/telemetry cleanup on VM deletion. * feat(autoinstall,overlay,plugin): add built-in macOS auto-install plugin, dynamic island overlay, and review fixes * fix(app,host,macos,ui): address PR #134 automated review findings - Frontend & i18n: - Fix UTF-8/GBK mojibake in VMPage.tsx. - Emit reims:confirm-resolved on timeout/cancel/resolve so frontend modals auto-close and surface errors cleanly; stop submitCreate from continuing after PrepareVMProvision failure. - Gate AutoInstallPanel RapidOCR download button on preflight can_download_ocr when pinned default assets are unavailable. - App / Sessions / Confirm / Lifecycle: - Add 30s denial cooldown for protected-phase confirmation prompts and revoke (pluginID, vmKey) grants on non-completed session exits. - Fix sessionOverlay / activeAgentSessions data race, remove duplicate permission-denied invocation, guard against clobbering other sessions or completed overlays, and unify VM key normalization. - Grant protected-phase confirmation and attach lock-mode session + watcher when resuming auto-install without an active session. - Unify FinishInstall and host/vm.finishInstall result handling and persist .reims-go-provision-ready across restarts. - Preserve non-timeout stop errors in restartMacOSVMLocked instead of force-killing. - Host Takeover Hooks: - Require both keyboard and mouse WH_*_LL hooks (rolling back partial installs), initialize thread message queue before ready, reset started state on error/exit for retry, and report hook failures. - macOS Provisioning & Autoinstall Engine: - Track REIMSPROV staged/wipe-pending/ready lifecycle markers, exclude "restore" recovery marker from re-attaching REIMSPROV, fail explicitly on offline admin plist creation failure, and report wipe failures. - Serialize per-VM Start/Stop/Resume with stop generation tokens, guard ROI fast-path against maxDim overflow, switch hostclient early-event buffer to FIFO eviction, fix untyped nil Engine return, tighten negation & high-risk fuzzy matching, preserve ackedQemuErrors across RebootWindow resets, and re-orient/expire stale inherited running checkpoints. - Document verified Windows SDK IDL vtable slots for WinOCR (live-tested on Windows) and add regression tests across app, host, macosdriver, startprep, installer, and autoinstall packages. * fix(app,cli,host,macos,ui): address PR #134 second automated review findings - CLI & Desktop Control Channel: - Add __reims_host__ / autoinstall desktop control channel with data_root verification so CLI status, resume, and stop talk directly to the live desktop runner instead of splitting checkpoint state or launching doomed short-lived CLI runners. - Merge live runners with on-disk checkpoints when listing status without a VM argument. - App Sessions, Confirmations, Downloads & Telemetry: - Scope single-VM not_authorized errors to the target VM in handleSessionBegin and resolveComputerUseVM so active sessions on other VMs are not aborted. - Exclude stopped and suspended VMs from hasUnboundAgentSession fast-polling. - Revoke protected-phase grants when a VM disappears from poll results. - Require manifest Secret:true validation before storing auto-install passwords and remove the unsafe default account_password fallback. - Reject userinfo URLs in allow_custom_mirror, gate custom-mirror exemption strictly on plugin.ErrNetOriginNotDeclared, and keep redirect SSRF checks enabled on loopback custom mirrors. - Preserve VM telemetry milestones across suspend-resume and Win10 cold-reboot restarts while still resetting on fresh cold boots. - Log a warning when Guest Tools bridge is unavailable while preparing REIMSPROV. - Clarify CallHostAPI authorization/audit contract and add regression test proving built-in plugins enforce catalog permissions and audit logging. - Host Takeover & Guest Tools: - Track locked mouse button presses via a 5-button bitmask so ButtonUp events from drags started outside the VM window are never swallowed. - Align active-window-reporter.js permissions to 0o100755 across ToolsDiskFiles, ToolsProvisionFiles, and postinstall. - macOS Provisioning & Autoinstall Engine (OCR / Vision / Rules / Runner): - Never delete an unwiped REIMSPROV image on OpenFile/Write/Sync failure; persist wipe-pending marker and return error for retry. - Harden live postinstall preference writes with chmod 600, plutil -lint, chown, and cfprefsd flush. - Rewrite Windows RapidOCR C ABI structs and result extraction to match RapidAI/RapidOcrOnnx@675e73fe4c include/OcrLiteCApi.h:27-70 and src/OcrLiteCApi.cpp:12-160 (5-arg OcrInit verified). - Inspect PE32/PE32+ IMAGE_DIRECTORY_ENTRY_IMPORT directly to require onnxruntime.dll only for dynamically linked RapidOcrOnnx.dll builds. - Validate cfg.VM and use collision-free SHA-256-suffixed checkpoint paths with read fallback; redact PII/paths/UUIDs/MACs/IPs/tokens in diagnostic summaries; snapshot checkpoints before releasing r.mu for serialized disk I/O. - Add contrast/border/focus-ring ok return to DetectInputFieldNearLabel, enforce mask-dots verification in fillAccountForm and login screens, refuse blind password typing on clock-only lock screens, confirm shell readiness before typing install.sh, and prefer isolated button lines over modal prose in FindHit. - Frontend: - Require explicit Apple SLA confirmation in both recovery_only and full modes across AutoInstallPanel and CreateWizard, with unit tests in frontend/scripts/test-autoinstall.mjs. * fix(app,cli,host,macos,ui): address PR #134 third automated review findings Addresses all confirmed findings from Review #6204465334 (commit d516350) with targeted regression tests and hardens verified COM vtable bindings: - App & Session Lifecycle: - Track hostPaused separately in agentSession so plugin host/session.update (paused_for_user=false) cannot clear physical user takeover or explicit PauseAgentSession holds; only host ResumeAgentSession or timed takeover expiry clears them. - Give each auto-install session watcher a monotonic watchGen + cancelable child context so restarting/resuming auto-install on the same VM cancels any superseded watcher and prevents stale timeout or secret cleanup. - Bound fast 500ms unbound-PID discovery for running VMs to sessionDiscoverGraceWindow via unboundSince (refreshed on restart/rebind). - Keep non-blocking buffered confirm resolution send inside confirmMu for clear mutual exclusion with cancelPendingConfirmations. - Clear cold-reboot telemetry preserveNextBoot via defer on all early-return and StartVM-failure paths in watchColdReboot. - Rebuild REIMSPROV with current StartAutoInstall credentials (preserving install_guest_tools) whenever VM is stopped instead of reusing stale images. - CLI & macOS Provisioning / StartPrep: - Refuse `vm provision --clear` and overwriting existing REIMSPROV while the VM is running or paused. - Guard live "/" root in postinstall against macOS Recovery/Installer (/System/Installation/CDIS), forbid "/" in provision-offline.sh, and scope chmod 644 strictly to com.apple.keyboardtype.plist. - Reject unknown -* options in REIMSHELP/install.sh (including after --erase). - Defer clearing the one-shot REIMSPROV staged marker until after setExtraArgs (startprep) and StartWithCompat (macosdriver) succeed. - Preserve pending RestartFrom guards in AdvancePostInstallHandoff when checkpoint is already at StepDesktop. - Host Input & Session Overlay: - Filter injected keyboard events (LLKHF_INJECTED / LLKHF_LOWER_IL_INJECTED) in locked-input mode consistently with the mouse hook. - Clean up exited overlay entries in entry.run() and recreate dead entries on Manager.Upsert when CreateWindowExW fails or exits early. - Cache the static island base surface (shell + icons + DirectWrite text) and measured text metrics across breathing frames, raising timerBreathMs to 100ms. - Replace magic Direct2D/DirectWrite vtable indices with named d2d1.h / dwrite.h constants, check EndDraw HRESULT, and add a live Windows DirectWrite rendering smoke test. - Autoinstall OCR, Rules, Watchdog & Runner: - Persist and verify a per-file SHA-256 manifest.json in <dataDir>/ocr/ before loading RapidOcrOnnx.dll / onnxruntime.dll; reject duplicate whitelisted basenames in offline zip imports. - Signal WinOCREngine.Close() before acquiring e.mu and add bounded wait + channel wakeup in Recognize so Close() immediately cancels in-flight OCR. - Fall back to installed RapidOCR when WinOCR initialization fails in Open(), and distinguish needs_rapidocr_import from needs_rapidocr_download in Probe. - Pause instead of pressing Return when post-TypeSecret login screenshot fails. - Re-baseline ColdRebootCount in Watchdog.ResetRebootWindow / ResetAfterResume. - Tighten recovery.main specificity (drop bare "Disk Utility"), guard 4-5 char pure-ASCII needles from sliding-window fuzzy collisions, use Unicode word boundaries for short names (<4 runes) in RedactDiagnosticText, and honor rule verify.wait_change_ms with early exit on visual frame diff. * fix(autoinstall): handle CJK short-name redaction, sh-3.2 prompt bound, and OCR re-import pruning
483 lines
14 KiB
Go
483 lines
14 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/Nwflower/reims-go/internal/driver"
|
|
"github.com/Nwflower/reims-go/internal/i18n"
|
|
"github.com/Nwflower/reims-go/internal/macos/guest"
|
|
"github.com/Nwflower/reims-go/internal/macos/installguide"
|
|
"github.com/Nwflower/reims-go/internal/macos/reims"
|
|
"github.com/Nwflower/reims-go/internal/macos/startprep"
|
|
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
|
)
|
|
|
|
// getInstallGuideManager returns the active VM-window install guide manager
|
|
// provided by builtin.guest.macos, or nil when disabled.
|
|
func (a *App) getInstallGuideManager() *installguide.Manager {
|
|
a.mu.Lock()
|
|
mgr := a.pluginMgr
|
|
a.mu.Unlock()
|
|
if mgr == nil {
|
|
return nil
|
|
}
|
|
raw, ok := mgr.Registry().LookupService(guest.ServiceInstallGuide)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
gm, _ := raw.(*installguide.Manager)
|
|
return gm
|
|
}
|
|
|
|
// installGuideEnabled reports whether the VM-window installation guide service is active.
|
|
func (a *App) installGuideEnabled() bool {
|
|
return a.getInstallGuideManager() != nil
|
|
}
|
|
|
|
func (a *App) guidePreferences() (i18n.Locale, installguide.Theme) {
|
|
a.mu.Lock()
|
|
rawLoc := a.cfg.Locale
|
|
th := a.themeMode
|
|
a.mu.Unlock()
|
|
return i18n.EffectiveLocale(rawLoc), installguide.Theme(th)
|
|
}
|
|
|
|
func (a *App) bindGuideEvents(ctx context.Context) {
|
|
wailsRuntime.EventsOn(ctx, "reims:theme", func(data ...any) {
|
|
if len(data) != 1 {
|
|
return
|
|
}
|
|
raw, _ := data[0].(string)
|
|
theme := installguide.Theme(raw)
|
|
if theme == installguide.ThemeLight || theme == installguide.ThemeDark {
|
|
a.mu.Lock()
|
|
a.themeMode = string(theme)
|
|
a.mu.Unlock()
|
|
}
|
|
})
|
|
}
|
|
|
|
func (a *App) unfoldInstallGuide(name string, pid int) {
|
|
if gm := a.getInstallGuideManager(); gm != nil {
|
|
gm.Unfold(name, pid)
|
|
}
|
|
}
|
|
|
|
// A queued recovery picker ("want") applies at the next boot. The guide
|
|
// describes the running boot, including one already running when the app opens.
|
|
func installGuideKind(d reims.VMDetail) (installguide.Kind, bool) {
|
|
if d.HasInstaller {
|
|
if reims.IsOfflineInstallerPath(d.InstallerPath) {
|
|
return installguide.Offline, true
|
|
}
|
|
return installguide.Online, true
|
|
}
|
|
return installguide.BuiltIn, startprep.ReadRecoveryMarker(d.Directory) == "on"
|
|
}
|
|
|
|
func (a *App) suppressInstallGuideForVM(name string) bool {
|
|
if gm := a.getInstallGuideManager(); gm != nil && name != "" {
|
|
return gm.Cancel(name)
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (a *App) markInstallGuideRecheck(name string) {
|
|
name = strings.TrimSpace(name)
|
|
if name == "" {
|
|
return
|
|
}
|
|
a.mu.Lock()
|
|
if a.guideRecheckVMs == nil {
|
|
a.guideRecheckVMs = map[string]bool{}
|
|
}
|
|
a.guideRecheckVMs[name] = true
|
|
a.mu.Unlock()
|
|
}
|
|
|
|
func (a *App) consumeInstallGuideRecheck(name string) bool {
|
|
if name == "" {
|
|
return false
|
|
}
|
|
a.mu.Lock()
|
|
ok := a.guideRecheckVMs[name]
|
|
if ok {
|
|
delete(a.guideRecheckVMs, name)
|
|
}
|
|
a.mu.Unlock()
|
|
return ok
|
|
}
|
|
|
|
func (a *App) setPendingInstallGuideHandoff(name, step string) {
|
|
name = strings.TrimSpace(name)
|
|
if name == "" || step == "" {
|
|
return
|
|
}
|
|
a.mu.Lock()
|
|
if a.pendingGuideHandoffs == nil {
|
|
a.pendingGuideHandoffs = map[string]string{}
|
|
}
|
|
// Preserve a pending desktop handoff if already scheduled.
|
|
if cur := a.pendingGuideHandoffs[name]; cur != string(installguide.StepDesktop) || step == string(installguide.StepDesktop) {
|
|
a.pendingGuideHandoffs[name] = step
|
|
}
|
|
a.mu.Unlock()
|
|
}
|
|
|
|
func (a *App) hasPendingInstallGuideHandoff(name string) bool {
|
|
if name == "" {
|
|
return false
|
|
}
|
|
a.mu.Lock()
|
|
_, ok := a.pendingGuideHandoffs[name]
|
|
a.mu.Unlock()
|
|
return ok
|
|
}
|
|
|
|
func (a *App) applyPendingInstallGuideHandoff(name, dir string) {
|
|
if name == "" || dir == "" {
|
|
return
|
|
}
|
|
a.mu.Lock()
|
|
step, ok := a.pendingGuideHandoffs[name]
|
|
if ok {
|
|
delete(a.pendingGuideHandoffs, name)
|
|
}
|
|
a.mu.Unlock()
|
|
if ok && step != "" {
|
|
_ = installguide.AdvancePostInstallHandoff(dir, name, installguide.Offline, installguide.PostInstallStep(step))
|
|
}
|
|
}
|
|
|
|
func isMacOSDriverID(driverID string) bool {
|
|
id := driver.CanonicalDriverID(strings.TrimSpace(driverID))
|
|
return id == "" || id == driver.BuiltinReimsMacOSDriverID
|
|
}
|
|
|
|
func (a *App) cachedVMDir(driverID, name string) string {
|
|
driverID = driver.CanonicalDriverID(driverID)
|
|
if driverID == "" {
|
|
driverID = driver.BuiltinReimsMacOSDriverID
|
|
}
|
|
a.mu.Lock()
|
|
defer a.mu.Unlock()
|
|
for _, vm := range a.lastVMs {
|
|
if vm.Name == name && driver.CanonicalDriverID(vm.DriverID) == driverID && strings.TrimSpace(vm.Dir) != "" {
|
|
return strings.TrimSpace(vm.Dir)
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (a *App) cachedRunningVMPID(driverID, name string) int {
|
|
driverID = driver.CanonicalDriverID(driverID)
|
|
if driverID == "" {
|
|
driverID = driver.BuiltinReimsMacOSDriverID
|
|
}
|
|
a.mu.Lock()
|
|
defer a.mu.Unlock()
|
|
for _, vm := range a.lastVMs {
|
|
if vm.Name == name && driver.CanonicalDriverID(vm.DriverID) == driverID && vm.State == "running" && vm.PID != nil && *vm.PID > 0 {
|
|
return *vm.PID
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// restoreManualInstallGuideFallback ensures the original manual installation
|
|
// guide is re-evaluated (or unfolded if already active in compact form) when a
|
|
// plugin cannot run — for example after the user denies protected-phase or
|
|
// plugin execution permission.
|
|
func (a *App) restoreManualInstallGuideFallback(driverID, vmName string) bool {
|
|
vmName = strings.TrimSpace(vmName)
|
|
if vmName == "" || !isMacOSDriverID(driverID) {
|
|
return false
|
|
}
|
|
vmKey := vmKeyForDriver(driverID, vmName)
|
|
a.dismissCompletedOverlay(vmKey)
|
|
a.markInstallGuideRecheck(vmName)
|
|
if gm := a.getInstallGuideManager(); gm != nil {
|
|
if pid := a.cachedRunningVMPID(driverID, vmName); pid > 0 && gm.HasActive(vmName, pid) {
|
|
gm.Unfold(vmName, pid)
|
|
}
|
|
}
|
|
a.wakePoll()
|
|
a.emitStateChanged()
|
|
return a.installGuideEnabled()
|
|
}
|
|
|
|
// prepareInstallGuideFinishHandoff snapshots a macOS VM's recovery state BEFORE
|
|
// `finish_install` modifies disk/recovery markers, returning a commit callback
|
|
// that persists the matching post-install manual guide checkpoint once
|
|
// `finish_install` succeeds.
|
|
func (a *App) prepareInstallGuideFinishHandoff(vm driver.VMInfo) func(running bool, pid int) bool {
|
|
if driver.CanonicalDriverID(vm.DriverID) != driver.BuiltinReimsMacOSDriverID {
|
|
return func(bool, int) bool { return false }
|
|
}
|
|
if vm.Directory == "" {
|
|
vm.Directory = a.cachedVMDir(vm.DriverID, vm.Name)
|
|
}
|
|
d, err := macOSDetailFromVMInfo(vm)
|
|
if err != nil || d.Directory == "" {
|
|
return func(bool, int) bool { return false }
|
|
}
|
|
kind, recovery := installGuideKind(d)
|
|
if !recovery {
|
|
return func(bool, int) bool { return false }
|
|
}
|
|
step := installguide.StepSetup
|
|
if kind == installguide.BuiltIn {
|
|
step = installguide.StepRestored
|
|
}
|
|
vmName, vmDir, media := vm.Name, d.Directory, d.InstallerPath
|
|
return func(running bool, pid int) bool {
|
|
var restartFrom uint32
|
|
if running && pid > 0 {
|
|
restartFrom = uint32(pid)
|
|
}
|
|
return installguide.SavePostInstallHandoff(vmDir, vmName, kind, media, step, restartFrom) == nil
|
|
}
|
|
}
|
|
|
|
// prepareInstallGuideRestoreAfterSession ensures the original manual install
|
|
// guide will reappear on the VM window after an auto-install or Agent session
|
|
// exits (whether stopped manually by the user, failed, plugin-disabled, or
|
|
// completed). It returns true when the native VM-window install guide is
|
|
// enabled and will take over the VM window so any colliding completed session
|
|
// island is dismissed cleanly.
|
|
func (a *App) prepareInstallGuideRestoreAfterSession(sess *agentSession, completed bool) bool {
|
|
if sess == nil || sess.vmName == "" {
|
|
return false
|
|
}
|
|
if !isMacOSDriverID(sess.driverID) {
|
|
return false
|
|
}
|
|
vmDir := strings.TrimSpace(sess.vmDir)
|
|
if vmDir == "" {
|
|
vmDir = a.cachedVMDir(sess.driverID, sess.vmName)
|
|
}
|
|
|
|
var targetStep installguide.PostInstallStep
|
|
if sess.isAutoInstall {
|
|
switch {
|
|
case completed && (strings.EqualFold(sess.autoInstallMode, "full") || (sess.autoInstallMode == "" && sess.sawSetupAssistant)):
|
|
targetStep = installguide.StepDesktop
|
|
case completed:
|
|
targetStep = installguide.StepSetup
|
|
case sess.stage == "stage6_desktop_ready":
|
|
targetStep = installguide.StepDesktop
|
|
case sess.finishInstallDone || sess.stage == "stage5_setup_assistant" || sess.stage == "stage5_wait_reboot":
|
|
targetStep = installguide.StepSetup
|
|
}
|
|
}
|
|
if targetStep != "" {
|
|
if vmDir != "" {
|
|
_ = installguide.AdvancePostInstallHandoff(vmDir, sess.vmName, installguide.Offline, targetStep)
|
|
} else {
|
|
a.setPendingInstallGuideHandoff(sess.vmName, string(targetStep))
|
|
}
|
|
}
|
|
|
|
a.markInstallGuideRecheck(sess.vmName)
|
|
|
|
if !a.installGuideEnabled() {
|
|
return false
|
|
}
|
|
if sess.isAutoInstall || sess.finishInstallDone || sess.suppressedInstallGuide {
|
|
return true
|
|
}
|
|
if vmDir != "" && installguide.HasPostInstallCheckpoint(vmDir, sess.vmName) {
|
|
return true
|
|
}
|
|
return a.hasPendingInstallGuideHandoff(sess.vmName)
|
|
}
|
|
|
|
// guideTracker follows the install guides of running VMs for the poll loop.
|
|
type guideTracker struct {
|
|
a *App
|
|
mgr *installguide.Manager // nil while the guide service is disabled
|
|
checked map[int]bool // PIDs already offered a guide by mgr
|
|
}
|
|
|
|
func (a *App) newGuideTracker() *guideTracker {
|
|
return &guideTracker{a: a, mgr: a.getInstallGuideManager(), checked: make(map[int]bool)}
|
|
}
|
|
|
|
// cancelStopped closes the guides of VMs that stopped and reports whether any
|
|
// did. A restarted guide service checks every running VM again.
|
|
func (t *guideTracker) cancelStopped(vms []driver.VMListItem) bool {
|
|
prunePinnedPIDs(t.checked, vms)
|
|
if mgr := t.a.getInstallGuideManager(); mgr != t.mgr {
|
|
clear(t.checked)
|
|
t.mgr = mgr
|
|
}
|
|
return t.mgr != nil && t.mgr.CancelStopped(runningPIDs(vms))
|
|
}
|
|
|
|
// startMissing opens the guide of running VMs that need one and reports
|
|
// whether any opened. details holds VM details already looked up, by VM key.
|
|
func (t *guideTracker) startMissing(ctx context.Context, vms []driver.VMListItem, details map[string]driver.VMInfo, loc i18n.Locale) bool {
|
|
if t.mgr == nil {
|
|
return false
|
|
}
|
|
started := false
|
|
for _, vm := range vms {
|
|
// The install guide belongs to the macOS installer flow.
|
|
if !driver.SupportsCapability(vm.Capabilities, driver.CapOpenCore) {
|
|
continue
|
|
}
|
|
pid := vm.RunningPID()
|
|
if pid == 0 {
|
|
// Old PIDs were already pruned by prunePinnedPIDs; clear any stale recheck flag.
|
|
t.a.consumeInstallGuideRecheck(vm.Name)
|
|
continue
|
|
}
|
|
vmKey := vmKeyForDriver(vm.DriverID, vm.Name)
|
|
if t.a.hasActiveAgentSession(vmKey) {
|
|
// While an Agent/auto-install session owns the VM, never cache pid as
|
|
// checked so the original manual guide is re-evaluated as soon as it ends.
|
|
delete(t.checked, pid)
|
|
continue
|
|
}
|
|
if t.a.consumeInstallGuideRecheck(vm.Name) {
|
|
delete(t.checked, pid)
|
|
if t.mgr.HasActive(vm.Name, pid) {
|
|
t.mgr.Unfold(vm.Name, pid)
|
|
}
|
|
}
|
|
if t.checked[pid] {
|
|
continue
|
|
}
|
|
det, ok := details[vmKey]
|
|
if !ok {
|
|
var err error
|
|
if det, err = t.a.resolveVMInfo(vm.DriverID, vm.Name); err != nil {
|
|
continue
|
|
}
|
|
if det.Directory == "" {
|
|
det.Directory = vm.Dir
|
|
}
|
|
}
|
|
t.a.applyPendingInstallGuideHandoff(vm.Name, det.Directory)
|
|
if t.a.hasActiveAgentSession(vmKey) {
|
|
delete(t.checked, pid)
|
|
continue
|
|
}
|
|
t.checked[pid] = true
|
|
if t.a.maybeStartInstallGuide(ctx, t.mgr, vm.Name, pid, det, loc) {
|
|
started = true
|
|
} else if t.a.hasActiveAgentSession(vmKey) {
|
|
delete(t.checked, pid)
|
|
}
|
|
}
|
|
return started
|
|
}
|
|
|
|
func (a *App) maybeStartInstallGuide(ctx context.Context, gm *installguide.Manager, name string, pid int, vm driver.VMInfo, loc i18n.Locale) bool {
|
|
if gm == nil || pid <= 0 || gm.HasActive(name, pid) {
|
|
return false
|
|
}
|
|
vmKey := vm.Ref().Key()
|
|
if a.hasActiveAgentSession(vmKey) {
|
|
return false
|
|
}
|
|
d, err := macOSDetailFromVMInfo(vm)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
kind, recovery := installGuideKind(d)
|
|
g := installguide.Guide{
|
|
Name: name,
|
|
PID: uint32(pid),
|
|
Locale: loc,
|
|
GuestLang: d.GuestLang,
|
|
Kind: kind,
|
|
ToolsAttached: reims.HasGuestToolsArgs(d.ExtraArgs),
|
|
}
|
|
if !g.Resume(d.Directory, d.InstallerPath, recovery) {
|
|
return false
|
|
}
|
|
if !gm.Start(ctx, a.buildInstallGuide(ctx, g, d)) {
|
|
return false
|
|
}
|
|
if a.hasActiveAgentSession(vmKey) {
|
|
gm.Cancel(name)
|
|
return false
|
|
}
|
|
a.dismissCompletedOverlay(vmKey)
|
|
return true
|
|
}
|
|
|
|
func (a *App) buildInstallGuide(ctx context.Context, g installguide.Guide, d reims.VMDetail) installguide.Guide {
|
|
name, pid := g.Name, int(g.PID)
|
|
g.CurrentPreferences = a.guidePreferences
|
|
if d.Graphics == "vmware-svga" {
|
|
g.ReleaseKeys = "Ctrl+Alt+G"
|
|
} else if d.Capture {
|
|
g.ReleaseKeys = "Ctrl+Alt+Win"
|
|
}
|
|
// The panel may have been open across a shutdown. Re-list instead of
|
|
// using the poll cache before acting on a VM addressed by name.
|
|
checkBoot := func() error {
|
|
vms, err := a.listVMsInternal(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, vm := range vms {
|
|
if vm.Name == name && vm.RunningPID() == pid {
|
|
return ctx.Err()
|
|
}
|
|
}
|
|
loc, _ := a.guidePreferences()
|
|
return i18n.NewCodedError(loc, "E_GUIDE_INSTANCE_CHANGED", "guide.err.instance_changed", i18n.Vars{"name": name}, nil)
|
|
}
|
|
g.TypeText = func(text string) error {
|
|
if err := checkBoot(); err != nil {
|
|
return err
|
|
}
|
|
_, err := a.TypeText("", name, text)
|
|
return err
|
|
}
|
|
g.FinishRecovery = func() error {
|
|
if err := checkBoot(); err != nil {
|
|
return err
|
|
}
|
|
return a.FinishInstall(name)
|
|
}
|
|
g.AttachImage = func(path string) error {
|
|
if err := checkBoot(); err != nil {
|
|
return err
|
|
}
|
|
_, err := a.AttachInstaller(name, path)
|
|
return err
|
|
}
|
|
g.LogError = func(err error) { a.emitVMLog(name, "Installation guide: "+err.Error()) }
|
|
g.AttachTools = func() error {
|
|
if err := checkBoot(); err != nil {
|
|
return err
|
|
}
|
|
return a.AttachGuestTools(name)
|
|
}
|
|
g.Restart = func() error {
|
|
if err := checkBoot(); err != nil {
|
|
return err
|
|
}
|
|
stopped, err := a.restartMacOSVM(a.baseCtx(), name)
|
|
if stopped && err != nil {
|
|
// The guest window has closed, so report start failures via the tray.
|
|
loc, _ := a.guidePreferences()
|
|
title := i18n.M(loc, "guide.err.restart_failed", i18n.Vars{"name": name})
|
|
a.emitVMLog(name, title+": "+err.Error())
|
|
a.mu.Lock()
|
|
tm := a.trayMgr
|
|
a.mu.Unlock()
|
|
if tm != nil {
|
|
tm.Notify(title, err.Error(), true)
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
return g
|
|
}
|