Files
Reims-Go/opencore_flow.go
T
Nwflower b2f7f036d8 feat(m5): add macOS prev-lang preset, disk resize/compact, audio diagnostics, and VM thumbnails
- M5.5: add pure-Go internal/opencore reader/in-place patcher for OpenCore NVRAM prev-lang:kbd with sidecar persistence, automatic replay after update-opencore/graphics changes/CoW clones, wizard/settings/CLI (--guest-lang) support
- M5.6: add stopped VM disk resize (qemu-img resize + dynamic macOS APFS expand command) and standalone qcow2 compaction (backing-file guard, free-space check, qemu-img check, atomic swap) in GUI Settings and CLI (vm resize/compact)
- M5.9: add Win32 winmm audio output/input device probing, fix reims-ctl show audio_backend parsing, expose audio backend selector (auto/dsound/none) and latency/mic diagnostics in Settings & CLI
- UI & thumbnails: add QMP screendump VM thumbnails (internal/thumb, thumbnail_flow.go), VMPage/CreateWizard layout polish, and docs/ui-audit.md
- Update docs/roadmap.md for M5.5, M5.6, and M5.9
2026-11-28 10:17:54 -07:00

97 lines
3.0 KiB
Go

package main
import (
"context"
"fmt"
"strings"
"github.com/Nwflower/reims-go/internal/driver/reims"
"github.com/Nwflower/reims-go/internal/opencore"
rt "github.com/Nwflower/reims-go/internal/runtime"
)
// populateGuestLangDetail fills VMDetail.GuestLang from the VM's persisted
// sidecar preference, falling back to reading prev-lang:kbd directly from its
// OpenCore image so existing VMs accurately reflect their boot/recovery locale.
func (a *App) populateGuestLangDetail(d *reims.VMDetail) {
if d == nil || d.Directory == "" {
return
}
if saved := opencore.ReadSavedGuestLang(d.Directory); saved != "" {
d.GuestLang = saved
return
}
if ocPath := opencore.ResolveOpenCorePath(d.Directory); ocPath != "" {
if lang, err := opencore.ReadImagePrevLang(ocPath); err == nil && lang != "" {
d.GuestLang = lang
}
}
}
func (a *App) activeQemuImgAndEnv() (string, []string) {
a.mu.Lock()
cfgCopy := *a.cfg
a.mu.Unlock()
active, err := rt.ResolveActive(&cfgCopy)
if err != nil || active == nil {
return "", nil
}
return active.QemuImgPath(), rt.BuildChildEnv(&cfgCopy, *active)
}
// patchVMOpenCoreLang updates prev-lang:kbd inside the VM's OpenCore image.
// Must only be called while the VM is stopped.
func (a *App) patchVMOpenCoreLang(ctx context.Context, name, vmDir, lang string) error {
norm, err := opencore.NormalizeGuestLang(lang)
if err != nil || norm == "" {
return err
}
ocPath := opencore.ResolveOpenCorePath(vmDir)
if ocPath == "" {
return nil
}
qemuImg, env := a.activeQemuImgAndEnv()
changed, err := opencore.PatchImagePrevLang(ctx, ocPath, norm, qemuImg, env)
if err != nil {
return err
}
if changed {
a.emitLog(name, fmt.Sprintf("Applied macOS boot/recovery language (%s) to OpenCore NVRAM", norm))
}
return nil
}
// applyGuestLang persists the VM's macOS prev-lang:kbd preference and, when
// stopped, immediately patches opencore.qcow2. When running, the saved sidecar
// is replayed on the next StartVM before QEMU launches.
func (a *App) applyGuestLang(ctx context.Context, name, vmDir, lang string, running bool) error {
norm, err := opencore.NormalizeGuestLang(lang)
if err != nil {
return err
}
if norm == "" {
return nil
}
if err := opencore.WriteSavedGuestLang(vmDir, norm); err != nil {
return err
}
if running {
a.emitLog(name, fmt.Sprintf("Scheduled macOS boot/recovery language (%s) for next start", norm))
return nil
}
return a.patchVMOpenCoreLang(ctx, name, vmDir, norm)
}
// replaySavedGuestLang ensures the VM's persisted prev-lang:kbd preference is
// present in opencore.qcow2 after any OpenCore rebuild (e.g. update-opencore,
// graphics switch, or kext upgrade) and before starting the VM.
func (a *App) replaySavedGuestLang(ctx context.Context, name, vmDir string) {
saved := opencore.ReadSavedGuestLang(vmDir)
if saved == "" {
return
}
if err := a.patchVMOpenCoreLang(ctx, name, vmDir, saved); err != nil {
a.emitLog(name, fmt.Sprintf("Warning: could not apply macOS language (%s) to OpenCore: %v", strings.TrimSpace(saved), err))
}
}