Adapt Intel VM suspend/resume to driver.SuspendDriver and lifecycle.Service, move native VM close confirmation into internal/host, migrate vm-suspend legacy capability detection, drop moved runtime build tooling, and regenerate i18n and Wails bindings.
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
//go:build windows
|
|
|
|
package app
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/Nwflower/reims-go/internal/driver"
|
|
"github.com/Nwflower/reims-go/internal/host"
|
|
"github.com/Nwflower/reims-go/internal/i18n"
|
|
"github.com/Nwflower/reims-go/internal/tray"
|
|
)
|
|
|
|
func (a *App) confirmVMWindowClose(name string) {
|
|
if _, pending := a.vmClosePrompts.LoadOrStore(name, struct{}{}); pending {
|
|
return
|
|
}
|
|
defer a.vmClosePrompts.Delete(name)
|
|
ctx := a.baseCtx()
|
|
pid := a.cachedVMPID(name)
|
|
owner := host.ProcessDisplayWindow(uint32(pid))
|
|
if owner == 0 {
|
|
pid = a.findRunningVMPID(ctx, name)
|
|
owner = host.ProcessDisplayWindow(uint32(pid))
|
|
}
|
|
if owner == 0 {
|
|
a.emitLog(name, "Could not locate the VM display window for close confirmation")
|
|
return
|
|
}
|
|
a.mu.Lock()
|
|
loc := i18n.EffectiveLocale(a.cfg.Locale)
|
|
theme := a.themeMode
|
|
a.mu.Unlock()
|
|
|
|
ref := driver.NewVMRef("", name)
|
|
canSuspend := false
|
|
if vm, err := a.resolveVMInfo("", name); err == nil {
|
|
ref = vm.Ref()
|
|
canSuspend = slices.Contains(vm.Capabilities, driver.CapSuspend)
|
|
}
|
|
label := strings.TrimSpace(a.GetVMNote(ref.Name))
|
|
if label == "" {
|
|
label = ref.Name
|
|
}
|
|
choice, err := host.ConfirmVMClose(ctx, owner, label, loc, theme, canSuspend)
|
|
if err != nil {
|
|
a.emitVMLogForDriver(ref.DriverID, ref.Name, err.Error())
|
|
return
|
|
}
|
|
if choice == host.VMCloseCancel {
|
|
return
|
|
}
|
|
vms, err := a.listVMsInternal(ctx)
|
|
if err != nil {
|
|
a.emitVMLogForDriver(ref.DriverID, ref.Name, err.Error())
|
|
return
|
|
}
|
|
if current, running := findRunningVMPID(vms, ref.Name); !running || current != uint32(pid) {
|
|
return
|
|
}
|
|
if choice == host.VMCloseSuspend {
|
|
a.trayVMAction(ref.DriverID, ref.Name, tray.ActSuspend)
|
|
} else {
|
|
a.trayVMAction(ref.DriverID, ref.Name, tray.ActStop)
|
|
}
|
|
}
|