Merge upstream main 2d2f3b5: borderless resolution fallback

This commit is contained in:
root committed 2026-12-02 23:53:30 +08:00
commit 9bc7684e77
3 files changed
+69 -1

No files matched your search

@@ -0,0 +1,7 @@
{
"group": "fixes",
"order": 0,
"authors": ["YinLiaoCo"],
"zh": "开启无边框模式时若 `reims-ctl show` 未输出分辨率,改为从 `vm.toml` 回读已配置的 `[display].resolution`,避免界面误显示默认 `1920x1080`。",
"en": "Read `[display].resolution` from `vm.toml` when `reims-ctl show` omits the resolution in borderless mode so the UI no longer falls back to `1920x1080`."
}
@@ -0,0 +1,29 @@
package reims
import (
"os"
"path/filepath"
"testing"
)
func TestBorderlessResolutionFallback(t *testing.T) {
for _, tc := range []struct{ name, display, config, want string }{
{"configured", "borderless", "resolution = '5120x2880'", "5120x2880"},
{"missing", "borderless", "", "1920x1080"},
{"explicit", "one, opening at 2560x1440", "resolution = '5120x2880'", "2560x1440"},
} {
t.Run(tc.name, func(t *testing.T) {
dir := t.TempDir()
if tc.config != "" {
if err := os.WriteFile(filepath.Join(dir, "vm.toml"), []byte("[display]\n"+tc.config+"\n"), 0600); err != nil {
t.Fatal(err)
}
}
d := ParseShow("vm", "directory "+dir+"\ndisplay "+tc.display)
applyBorderlessResolutionFallback(&d)
if d.Resolution != tc.want {
t.Fatalf("resolution = %q, want %q", d.Resolution, tc.want)
}
})
}
}
+33 -1
View File
@@ -19,6 +19,7 @@ import (
"github.com/Nwflower/reims-go/internal/i18n"
"github.com/Nwflower/reims-go/internal/macos/opencore"
rt "github.com/Nwflower/reims-go/internal/runtime"
"github.com/pelletier/go-toml/v2"
)
// Client wraps reims-ctl invocations using an isolated portable runtime.
@@ -763,7 +764,38 @@ func (c *Client) Show(ctx context.Context, name string) (VMDetail, error) {
if err := c.run(ctx, &out, &errBuf, "show", name); err != nil {
return VMDetail{}, fmt.Errorf("reims-ctl show %s: %w (%s)", name, err, strings.TrimSpace(errBuf.String()))
}
return ParseShow(name, out.String()), nil
d := ParseShow(name, out.String())
applyBorderlessResolutionFallback(&d)
return d, nil
}
func applyBorderlessResolutionFallback(d *VMDetail) {
if !d.Borderless || d.Directory == "" || reResIn.FindString(d.Display) != "" {
return
}
if res := readVMDisplayResolution(d.Directory); res != "" {
d.Resolution = res
}
}
func readVMDisplayResolution(vmDir string) string {
data, err := os.ReadFile(filepath.Join(vmDir, "vm.toml"))
if err != nil {
return ""
}
var cfg struct {
Display struct {
Resolution string
}
}
if err := toml.Unmarshal(data, &cfg); err != nil {
return ""
}
res := strings.TrimSpace(cfg.Display.Resolution)
if !reRes.MatchString(res) {
return ""
}
return res
}
func (c *Client) ReadLogs(ctx context.Context, name string, serial bool) (string, error) {