Files
magpie/internal/settings/lightweight_test.go
T
forever f109b270c0 gui: the main window opens as it was last left — maximised again if it was, at its last size otherwise (#995)
On a MacBook the window had last been zoomed. magpie skipped a maximised
window when it saved the size, so it reopened at an older, nearly full
size: 1712×1083 at (8,34) on a 1728×1084 work area, neither full nor the
size it was given nor the default.

settings.WindowMaximised (this computer's own, KeepOwn) now records
whether the window was maximised when it settled; Window stays the size
it restores to (settle). A window not shown yet, let go, full screen or
minimised, or on Linux hidden, records nothing.

Reopened maximised: on the Mac and Windows placeMain maximises the made
window just before its first Show (on Windows once its page has come);
Wails' StartState is undone by the Mac's centring and shows a Windows
window before its page. The least size Maximise drops is put back. On
Linux makeMain sets StartState, since GTK can't be asked about a window
not mapped yet.

A size kept on a larger screen: Windows fits the window to the work area
and centres it, title bar in reach, and keeps the larger size for the
larger screen (fitted); the Mac fits and zooms it itself, and magpie
doesn't zoom it again, so it can still be restored.

TestSettle fails with upstream's rule (5 of 9 cases); TestOpenSize,
TestFitRoom, TestWindowMaximisedKeptAndOwn; the Mac's real build under a
sandbox HOME, 11 cases.
2026-10-06 16:09:58 +08:00

73 lines
2.1 KiB
Go

package settings
import "testing"
// Lightweight mode (#580) is saved and read back, off by default, and is
// this computer's own: a sync or a restored backup keeps it as it is here.
func TestLightweightKeptAndOwn(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if Load().Lightweight {
t.Fatal("on by default")
}
s := Load()
s.Lightweight = true
if err := Save(s); err != nil {
t.Fatal(err)
}
if !Load().Lightweight {
t.Fatal("not kept")
}
from := Settings{Theme: "dark"}
from.KeepOwn(Load())
if !from.Lightweight || from.Theme != "dark" {
t.Fatalf("KeepOwn: %+v", from)
}
from = Settings{Lightweight: true}
from.KeepOwn(Settings{})
if from.Lightweight {
t.Fatal("another computer's turned on here")
}
}
// Keep awake (xiao_wang24004 on X) is off by default, saved, and this
// computer's own.
func TestKeepAwakeKeptAndOwn(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if Load().KeepAwake {
t.Fatal("on by default")
}
s := Load()
s.KeepAwake, s.KeepAwakeDisplay = true, true
if err := Save(s); err != nil {
t.Fatal(err)
}
if l := Load(); !l.KeepAwake || !l.KeepAwakeDisplay {
t.Fatal("not kept")
}
from := Settings{}
from.KeepOwn(Load())
if !from.KeepAwake || !from.KeepAwakeDisplay {
t.Fatal("KeepOwn dropped it")
}
from = Settings{KeepAwake: true, KeepAwakeDisplay: true}
from.KeepOwn(Settings{})
if from.KeepAwake || from.KeepAwakeDisplay {
t.Fatal("another computer's turned on here")
}
}
// Whether the main window was maximised is this computer's, like its size:
// a synced or restored bundle doesn't bring another's.
func TestWindowMaximisedKeptAndOwn(t *testing.T) {
from := Settings{}
from.KeepOwn(Settings{Window: []int{900, 700}, WindowMaximised: true})
if !from.WindowMaximised || len(from.Window) != 2 {
t.Fatalf("KeepOwn dropped it: %v %v", from.Window, from.WindowMaximised)
}
from = Settings{Window: []int{1200, 800}, WindowMaximised: true}
from.KeepOwn(Settings{})
if from.WindowMaximised || from.Window != nil {
t.Fatalf("another computer's window here: %v %v", from.Window, from.WindowMaximised)
}
}