jorbenzhu on Discord: after every update and restart the panel is back in the middle of the screen. It is the main window: after an update magpie starts again with `magpie gui <tab>`, and Wails opens a window centred unless told otherwise. Its size and maximised state were kept; its place never was (gui-shell.md said "The window's position is not kept"), so nothing was lost on upgrade, there was nothing to restore. The tray's panel opens under the tray icon on the Mac and Windows, and where the click was on Linux, so it is not what moved. Now settings.WindowAt keeps the window's top left corner (system coordinates across every screen), per machine like Window (KeepOwn, and the Settings page's save carries it over). keepAt saves it once a move or resize has rested 500ms, unless the window is maximised, full screen, minimised or hidden; settings.Save writes through temp and rename, and an unreadable settings file is left alone. On the first show placeMain puts it back (putBack): openAt picks the screen holding most of the window and moves it fully onto that screen's work area; when no screen holds any of it (a monitor gone) or the screens or the file can't be read, it stays centred. Under Wayland a window can't place itself, so nothing is kept or restored there unless GDK_BACKEND is x11 (keepsPlace). Run: - mote, at 3f8f1d88b (ond99e213f5): go test -timeout 45m -count=1 ./... 80 packages ok; internal/gui red only in its 10 real-window AppKit tests (TestDockJoinLeadsCommandTab, TestPanelCloseHidesIt, TestPanelJoinsFullScreenSpaces, TestPluginPageLoadsItsFilesInTheWindow, TestDockReopenKeepsTheWindowsSpace, TestMainWindowCorners, TestMainWindowRightToLeft, TestHandoverLeavesTheMenuBarIconForTheNextMagpie, TestTrayCellClickReleasedPanel, TestCoveredWindowStaysUp), each killed at its deadline. The same 10 fail the same way on origin/mainfa427216a: mote has no console session (#4125). - mote, after rebasing onto024393fbb(two gateway commits, none of these files): internal/gui (less the 10 above), internal/settings and internal/gateway: ok. - mote: gofmt -l; go vet ./internal/gui ./internal/settings; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...; go build, and GOOS=windows / GOOS=linux -tags nogui builds: clean. - Windows (win-run) and Linux (wsl-run, -tags gtk3): TestOpenAt, TestSettleAt, TestKeepsPlace, TestOpenSize, TestSettle*, TestSettingsSaveKeeps*, TestWindowMaximisedKeptAndOwn: ok. Broken by hand (each red, then restored): - api.go not carrying WindowAt over a Settings save: TestSettingsSaveKeepsWhatItDoesNotSend red ("WindowAt: [] after a save of the Settings page, was [-1440 120]"). - KeepOwn not keeping WindowAt: TestWindowMaximisedKeptAndOwn red. - openAt without the clamp and the gone-screen check: TestOpenAt red in 7 of 12 cases. Real app, Linux X11 (magpie-desktop, Xvfb 1920x1080 + xfwm4, sandbox HOME/XDG dirs, MAGPIE_ADDR 127.0.0.1:3447, gtk3 build of this tree): first start centred (630,240 in X terms); xdotool moved it to 200,150 and settings.json got windowAt; restarted, it opened at 200,150; windowAt [5000,4000] (a gone monitor) opened centred; [1700,900] opened at [1260,480], flush with the bottom right (660x600 + GTK's 26px shadow). Not tried: the real app on macOS (mote has no console session, #4125) and on Windows (a sandbox magpie.exe rewrites HKCU\Software\Classes\magpie, which points at another session's build there). Wayland is not restored by design. Multi-monitor setups with mixed scaling were not tried on real hardware; openAt's cases cover a second screen left of and right of the main one.
105 lines
3.2 KiB
Go
105 lines
3.2 KiB
Go
package settings
|
|
|
|
import "testing"
|
|
|
|
// Lightweight mode (#580) is off for a user who never chose (the owner,
|
|
// 10-21: too slow to have by default), on for one who turned it on, and
|
|
// kept off for one who turned it off; it is saved and read back, 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().LightweightOn() {
|
|
t.Fatal("on for a user who never chose")
|
|
}
|
|
off, on := false, true
|
|
s := Load()
|
|
s.Lightweight = &on
|
|
if err := Save(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !Load().LightweightOn() {
|
|
t.Fatal("turned on, but read back off")
|
|
}
|
|
s.Lightweight = &off
|
|
if err := Save(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if Load().LightweightOn() {
|
|
t.Fatal("turned off, but read back on")
|
|
}
|
|
s.Theme = "dark" // another setting saved keeps it off
|
|
if err := Save(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if Load().LightweightOn() {
|
|
t.Fatal("another setting's save turned it on")
|
|
}
|
|
from := Settings{Theme: "dark", Lightweight: &on}
|
|
from.KeepOwn(Load())
|
|
if from.LightweightOn() || from.Theme != "dark" {
|
|
t.Fatalf("KeepOwn: %+v", from)
|
|
}
|
|
from = Settings{Lightweight: &off}
|
|
from.KeepOwn(Settings{})
|
|
if from.Lightweight != nil {
|
|
t.Fatal("another computer's choice taken 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, WindowAt: []int{40, 60}})
|
|
if !from.WindowMaximised || len(from.Window) != 2 || len(from.WindowAt) != 2 {
|
|
t.Fatalf("KeepOwn dropped it: %v %v %v", from.Window, from.WindowMaximised, from.WindowAt)
|
|
}
|
|
from = Settings{Window: []int{1200, 800}, WindowMaximised: true, WindowAt: []int{2560, 0}}
|
|
from.KeepOwn(Settings{})
|
|
if from.WindowMaximised || from.Window != nil || from.WindowAt != nil {
|
|
t.Fatalf("another computer's window here: %v %v %v", from.Window, from.WindowMaximised, from.WindowAt)
|
|
}
|
|
}
|
|
|
|
// Detect agents in WSL (#1264) is this computer's own: a sync from a Mac or
|
|
// a restored backup leaves it as it is on this Windows box.
|
|
func TestNoWSLAgentsOwn(t *testing.T) {
|
|
from := Settings{Theme: "dark"}
|
|
from.KeepOwn(Settings{NoWSLAgents: true})
|
|
if !from.NoWSLAgents || from.Theme != "dark" {
|
|
t.Fatalf("KeepOwn: %+v", from)
|
|
}
|
|
from = Settings{NoWSLAgents: true}
|
|
from.KeepOwn(Settings{})
|
|
if from.NoWSLAgents {
|
|
t.Fatal("another computer's turned off here")
|
|
}
|
|
}
|