Route generic App and CLI code through lifecycle and driver models. Move native macOS detail, create, settings and legacy flows into explicit files, share progress and redaction through host, and enforce the boundary with a file-scoped architecture ratchet.
87 lines
3.0 KiB
Go
87 lines
3.0 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"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/macos/reims"
|
|
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
|
)
|
|
|
|
// ToggleVMFullscreen switches the running VM's display between full screen and windowed mode.
|
|
func (a *App) toggleVMFullscreenLegacy(name string) (bool, error) {
|
|
a.mu.Lock()
|
|
preference := a.cfg.Locale
|
|
a.mu.Unlock()
|
|
loc := i18n.EffectiveLocale(preference)
|
|
c, err := a.client()
|
|
if err != nil {
|
|
return false, i18n.NewCodedError(loc, "E_FULLSCREEN_FAILED", "err.fullscreen_failed", i18n.Vars{"name": name}, err)
|
|
}
|
|
fullscreen, err := toggleVMFullscreen(context.Background(), name, loc, c, host.ToggleProcessWindowFullscreen)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
a.emitVMLog(name, fmt.Sprintf("VM window full screen: %t", fullscreen))
|
|
if a.ctx != nil {
|
|
wailsRuntime.EventsEmit(a.ctx, "reims:state-changed", true)
|
|
}
|
|
return fullscreen, nil
|
|
}
|
|
|
|
type fullscreenVMClient interface {
|
|
Show(context.Context, string) (reims.VMDetail, error)
|
|
List(context.Context) ([]driver.VMListItem, error)
|
|
}
|
|
|
|
func findRunningVMPID(vms []driver.VMListItem, name string) (uint32, bool) {
|
|
for _, vm := range vms {
|
|
if vm.Name == name && vm.State == "running" && vm.PID != nil && *vm.PID > 0 {
|
|
return uint32(*vm.PID), true
|
|
}
|
|
}
|
|
return 0, false
|
|
}
|
|
|
|
func toggleVMFullscreen(ctx context.Context, name string, loc i18n.Locale, c fullscreenVMClient, toggleWindow func(uint32) (bool, error)) (bool, error) {
|
|
vars := i18n.Vars{"name": name}
|
|
beforeVMs, err := c.List(ctx)
|
|
if err != nil {
|
|
return false, i18n.NewCodedError(loc, "E_FULLSCREEN_FAILED", "err.fullscreen_failed", vars, err)
|
|
}
|
|
pidBefore, ok := findRunningVMPID(beforeVMs, name)
|
|
if !ok {
|
|
return false, i18n.NewCodedError(loc, "E_VM_NOT_RUNNING", "err.vm_not_running", vars, nil)
|
|
}
|
|
detail, err := c.Show(ctx, name)
|
|
if err != nil {
|
|
return false, i18n.NewCodedError(loc, "E_FULLSCREEN_FAILED", "err.fullscreen_failed", vars, err)
|
|
}
|
|
if detail.State != "running" {
|
|
return false, i18n.NewCodedError(loc, "E_VM_NOT_RUNNING", "err.vm_not_running", vars, nil)
|
|
}
|
|
if detail.Graphics == "vmware-svga" {
|
|
return false, i18n.NewCodedError(loc, "E_FULLSCREEN_VMWARE_SVGA", "err.fullscreen_vmware_svga", vars, nil)
|
|
}
|
|
afterVMs, err := c.List(ctx)
|
|
if err != nil {
|
|
return false, i18n.NewCodedError(loc, "E_FULLSCREEN_FAILED", "err.fullscreen_failed", vars, err)
|
|
}
|
|
pidAfter, ok := findRunningVMPID(afterVMs, name)
|
|
if !ok || pidAfter != pidBefore {
|
|
return false, i18n.NewCodedError(loc, "E_VM_NOT_RUNNING", "err.vm_not_running", vars, nil)
|
|
}
|
|
fullscreen, err := toggleWindow(pidAfter)
|
|
if errors.Is(err, host.ErrDisplayWindowNotFound) {
|
|
return false, i18n.NewCodedError(loc, "E_VM_WINDOW_NOT_FOUND", "err.vm_window_not_found", vars, err)
|
|
}
|
|
if err != nil {
|
|
return false, i18n.NewCodedError(loc, "E_FULLSCREEN_FAILED", "err.fullscreen_failed", vars, err)
|
|
}
|
|
return fullscreen, nil
|
|
}
|