Offline installers (roadmap M1.3): - internal/installer drives `reims-util --json offline-installer` and parses its JSON event stream (upstream reims-vgpu 3731afd, reims_util.rs:423-509) - downloads hold installers/.lock like reims-ctl, so the two never write the same file; checked against the real reims-ctl (TestLockExcludesReimsCtl) - pause = stop the process, rerun resumes; deletes go through `reims-ctl downloads delete`, which refuses files in use or downloading - CLI: reims-go installer list | download | cached | delete - Wails bindings: ListOfflineReleases, DownloadInstaller, ListInstallers, DeleteInstaller Task events (ui-redesign B1): - tasks.go tracks long-running work and emits "reims:task" (throttled to 200 ms per task); VM creation turns reims-ctl's progress lines into task progress and logs each step once - the status bar shows the current task with a progress bar, details in a tooltip and a pause button; the frontend regex merging is removed Win10 cold reboot workaround: - host probes whether WinHvPlatform.dll lacks WHvResetPartition (Win10 19045) - internal/qmp watches a dedicated QMP channel for guest resets; with -no-reboot the app restarts the VM in a fresh partition - architecture.md documents download routing and the workaround Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
3.0 KiB
Go
111 lines
3.0 KiB
Go
package main
|
|
|
|
// Wails bindings for offline installers (roadmap M1.3). The download manager
|
|
// page (M2.2) builds on these; downloads report through tasks (tasks.go).
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/Nwflower/reims-go/internal/installer"
|
|
rt "github.com/Nwflower/reims-go/internal/runtime"
|
|
)
|
|
|
|
func (a *App) installerClient() (*installer.Client, error) {
|
|
a.mu.Lock()
|
|
cfg := *a.cfg
|
|
a.mu.Unlock()
|
|
active, err := rt.ResolveActive(&cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return installer.NewClient(&cfg, *active), nil
|
|
}
|
|
|
|
// ListOfflineReleases lists the offline installers Apple offers, newest first.
|
|
// It reads Apple's catalog (a few seconds, needs the network).
|
|
func (a *App) ListOfflineReleases() ([]installer.Release, error) {
|
|
c, err := a.installerClient()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
base := a.ctx
|
|
if base == nil {
|
|
base = context.Background()
|
|
}
|
|
return c.ListOffline(base, nil)
|
|
}
|
|
|
|
// DownloadInstaller starts downloading an offline installer in the background
|
|
// and returns its task ID. A download already running for the same release is
|
|
// returned instead of starting another; CancelTask pauses it.
|
|
func (a *App) DownloadInstaller(version string) (string, error) {
|
|
version = strings.TrimSpace(version)
|
|
if version == "" {
|
|
return "", fmt.Errorf("no version given")
|
|
}
|
|
c, err := a.installerClient()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
for _, t := range tasks.list() {
|
|
if t.Kind == "installer-download" && t.Status == TaskRunning && strings.EqualFold(t.Subject, version) {
|
|
return t.ID, nil
|
|
}
|
|
}
|
|
a.ensureTaskEmitter()
|
|
base := a.ctx
|
|
if base == nil {
|
|
base = context.Background()
|
|
}
|
|
ctx, cancel := context.WithCancel(base)
|
|
id := tasks.start("installer-download", version, "", cancel)
|
|
a.emitLog("installer", "Downloading macOS "+version+" offline installer")
|
|
go func() {
|
|
defer cancel()
|
|
res, err := c.DownloadOffline(ctx, version, func(u installer.Update) {
|
|
switch u.Kind {
|
|
case installer.KindStep, installer.KindNote:
|
|
a.emitLog("installer", u.Message)
|
|
}
|
|
tasks.update(id, u)
|
|
})
|
|
switch {
|
|
case err == nil:
|
|
a.emitLog("installer", "Installer ready: "+res.Image)
|
|
tasks.finish(id, res.Image, nil)
|
|
case ctx.Err() != nil:
|
|
a.emitLog("installer", "Download paused; starting it again continues where it stopped")
|
|
tasks.finish(id, "", context.Canceled)
|
|
default:
|
|
a.emitLog("installer", "Download error: "+err.Error())
|
|
tasks.finish(id, "", err)
|
|
}
|
|
}()
|
|
return id, nil
|
|
}
|
|
|
|
// ListInstallers lists the downloaded installers kept for new VMs.
|
|
func (a *App) ListInstallers() ([]installer.Cached, error) {
|
|
c, err := a.installerClient()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return c.ListCached()
|
|
}
|
|
|
|
// DeleteInstaller deletes a downloaded installer through reims-ctl, which
|
|
// refuses one a VM boots from or one being downloaded.
|
|
func (a *App) DeleteInstaller(name string) error {
|
|
c, err := a.installerClient()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := c.DeleteCached(context.Background(), name, nil); err != nil {
|
|
return err
|
|
}
|
|
a.emitLog("installer", "Deleted "+name)
|
|
return nil
|
|
}
|