Files
Reims-Go/internal/app/install_guide.go
T
Dnyo666 ceeec602be feat(i18n,plugin): implement end-to-end i18n & L10n v2 architecture and language pack protocol
- Build single-source-of-truth 7-domain locale catalog (`locales/{zh-CN,en-US}/*.json`, 1,100+ keys) and `cmd/i18ngen` generator emitting Go catalogs and eager/lazy-split TypeScript domain modules (`core`/`vm` eager; `wizard`/`settings`/`plugins` lazy)
- Add zero-dependency ICU MessageFormat subset (`{var}`, `{n, number}`, CLDR `plural`, `select`), 8-hop cycle-free regional fallback (`zh-HK/zh-MO -> zh-Hant -> zh-TW -> zh-CN`), `auto` OS display-language preference, and `en-XA` pseudo-localization across Go and TypeScript
- Introduce `CodedError` supportability with `[E_CODE]` badges, collapsible `[detail]` diagnostics, and automatic SMC OSK / SMBIOS serial / MAC / token redaction
- Add Host × Guest macOS dual-terminology annotation (`FormatGuestTerm`) across 6 official Apple guest UI locales and localize Win32 system tray, file pickers, and DPI-adaptive `installguide` overlays with CJK font fallback probing
- Upgrade L1–L4 plugin localization to dual-track v2: Track A full language packs (`files`, WOFF2 `fonts`, cross-plugin `pluginOverrides`), Track B plugin-scoped `l10n` bundles (`HasUIMessages` isolation), live `plugin/localeChanged` notifications, `< 2ms` static CLI pack loading, and `reims-go plugin locale init|check` translator toolchain with `zh-TW` and `ja-JP` reference packs
- Harden security, WCAG 2.1 AA token contrast, `< 768px` responsive drawer & form layouts, and RTL logical properties; add backend security/locale regression tests and frontend `node --test` static/runtime guard suite in CI

# Conflicts:
#	frontend/src/i18n.ts
#	internal/cli/cli.go
#	internal/i18n/i18n.go
2026-11-30 14:56:19 +08:00

168 lines
4.6 KiB
Go

package app
import (
"context"
"github.com/Nwflower/reims-go/internal/driver/reims"
"github.com/Nwflower/reims-go/internal/i18n"
"github.com/Nwflower/reims-go/internal/installguide"
"github.com/Nwflower/reims-go/internal/plugin/builtin"
"github.com/Nwflower/reims-go/internal/vmstart"
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
)
// getInstallGuideManager returns the active builtin.install-guide manager when
// the plugin is enabled, or nil when disabled or unavailable.
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(builtin.ServiceInstallGuide)
if !ok {
return nil
}
gm, _ := raw.(*installguide.Manager)
return gm
}
// installGuideEnabled reports whether the VM-window installation guide builtin
// plugin is currently 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), 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 = 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, vmstart.ReadRecoveryMarker(d.Directory) == "on"
}
func (a *App) maybeStartInstallGuide(ctx context.Context, gm *installguide.Manager, name string, pid int, d reims.VMDetail, loc i18n.Locale) bool {
if gm == nil || pid <= 0 || gm.HasActive(name, pid) {
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
}
return gm.Start(ctx, a.buildInstallGuide(ctx, g, d))
}
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.State == "running" && vm.PID != nil && *vm.PID == 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.emitLog(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.restartVM(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.emitLog(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
}