Files
Reims-Go/internal/app/extras_flow.go
T
NwflowerandClaude Opus 5.5 c0f08be124 feat: per-VM CPU affinity, disk snapshots, SSH helpers and VM window actions
Backend
- Per-VM CPU affinity (vmstart/affinity.go, affinity_flow.go): modes auto /
  all / P-cores / non-LP-E / custom, saved in the VM folder, applied to the
  QEMU process on start (GUI and CLI) and live via SetVMAffinity; copied on
  clone. Start summary logs the resolved mapping. Host report gains CPU
  topology helpers (mask <-> CPU list).
- Offline qcow2 restore points via qemu-img (driver/reims/snapshot.go,
  snapshot_flow.go): list / create / restore / delete.
- SSH helpers (ssh_flow.go): remembered user, open a terminal, write an
  ~/.ssh/config entry, open VS Code Remote-SSH.
- FocusVMWindow brings the QEMU window forward (restoring it if minimized);
  CopyVMScreenshot copies a full-resolution frame to the clipboard.
- DeliverPathsToGuest copies dropped host files into the shared folder;
  main.go enables Wails file drop on elements marked --wails-drop-target.
- VM note (.reims-go-note) and a storage breakdown (extras_flow.go).

Frontend
- VM page: running state's "Show Window" and the screen preview use
  FocusVMWindow; camera button and More-menu item copy a screenshot;
  editable note under the name; SSH row shows the saved user with
  Terminal / config / VS Code actions; restore-point list; install guide
  steps can be ticked off; drop files onto the page to send them.
- Sidebar right-click menu per VM (start, show window, screenshot, stop,
  restart, settings, folders, clone, delete); double-click and Ctrl+Enter
  still run the main action.
- AffinityDialog opened from the VM menu and VM settings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 04:00:48 -07:00

123 lines
3.2 KiB
Go

package app
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"sort"
"strings"
"github.com/Nwflower/reims-go/internal/installer"
)
const vmNoteFileName = ".reims-go-note"
// VMStorageItem is one VM's disk footprint under DataRoot.
type VMStorageItem struct {
Name string `json:"name"`
Bytes int64 `json:"bytes"`
}
// StorageBreakdown summarizes how DataRoot space is distributed across VMs,
// cached macOS installers, and portable runtimes.
type StorageBreakdown struct {
VMsBytes int64 `json:"vms_bytes"`
InstallersBytes int64 `json:"installers_bytes"`
RuntimesBytes int64 `json:"runtimes_bytes"`
TotalBytes int64 `json:"total_bytes"`
VMs []VMStorageItem `json:"vms"`
}
// GetVMNote returns the optional single-line note saved for a VM.
func (a *App) GetVMNote(name string) string {
d, err := a.GetVMDetail(name)
if err != nil || d.Directory == "" {
return ""
}
b, err := os.ReadFile(filepath.Join(d.Directory, vmNoteFileName))
if err != nil {
return ""
}
return strings.TrimSpace(string(b))
}
// SetVMNote stores a short single-line note next to the VM directory.
func (a *App) SetVMNote(name, note string) error {
note = sanitizeVMNote(note)
d, err := a.GetVMDetail(name)
if err != nil {
return err
}
if d.Directory == "" {
return fmt.Errorf("VM directory not found")
}
p := filepath.Join(d.Directory, vmNoteFileName)
if note == "" {
_ = os.Remove(p)
return nil
}
return os.WriteFile(p, []byte(note+"\n"), 0o644)
}
func sanitizeVMNote(note string) string {
note = strings.ReplaceAll(note, "\r", " ")
note = strings.ReplaceAll(note, "\n", " ")
note = strings.TrimSpace(note)
runes := []rune(note)
if len(runes) > 120 {
return string(runes[:120])
}
return note
}
// GetStorageBreakdown computes disk usage across DataRoot subdirectories.
func (a *App) GetStorageBreakdown() StorageBreakdown {
a.mu.Lock()
cfgCopy := *a.cfg
a.mu.Unlock()
vmsDir := filepath.Join(cfgCopy.XDGDataDir(), "reims-vgpu", "vms")
return computeStorageBreakdown(vmsDir, installer.Dir(&cfgCopy), cfgCopy.RuntimesDir(), cfgCopy.ImagesDir())
}
func computeStorageBreakdown(vmsDir, installersDir, runtimesDir, imagesDir string) StorageBreakdown {
var out StorageBreakdown
if entries, err := os.ReadDir(vmsDir); err == nil {
for _, e := range entries {
if !e.IsDir() {
continue
}
sz := dirSizeBytes(filepath.Join(vmsDir, e.Name()))
out.VMs = append(out.VMs, VMStorageItem{Name: e.Name(), Bytes: sz})
out.VMsBytes += sz
}
}
if imgBytes := dirSizeBytes(imagesDir); imgBytes > 0 {
out.VMsBytes += imgBytes
}
sort.Slice(out.VMs, func(i, j int) bool {
return out.VMs[i].Bytes > out.VMs[j].Bytes
})
out.InstallersBytes = dirSizeBytes(installersDir)
out.RuntimesBytes = dirSizeBytes(runtimesDir)
out.TotalBytes = out.VMsBytes + out.InstallersBytes + out.RuntimesBytes
return out
}
func dirSizeBytes(root string) int64 {
if root == "" {
return 0
}
var total int64
_ = filepath.WalkDir(root, func(_ string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
return nil
}
if info, err := d.Info(); err == nil {
total += info.Size()
}
return nil
})
return total
}