Files
Reims-Go/internal/app/vm_close_windows.go
NwflowerandClaude Opus 5.5 0ed522656d fix(app): log every VM line under the VM's key
Some lines used the bare VM name as their source, so the log lines reported
with a failed command-line start left them out. Disk tasks also kept the
VM name in their step text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:27:52 -07:00

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.emitVMLog(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.DriverID, 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 := runningPIDByName(vms, ref.Name); current == 0 || current != pid {
return
}
if choice == host.VMCloseSuspend {
a.trayVMAction(ref.DriverID, ref.Name, tray.ActSuspend)
} else {
a.trayVMAction(ref.DriverID, ref.Name, tray.ActStop)
}
}