Files
magpie/internal/settings/lightweight_test.go
T
yetone 28bec1507c settings: lightweight mode is on for a user who never chose it, and off for one who turned it off
The owner: 改成默认开,只对没设过的用户. A webview kept for good holds what
its page drew while hidden, which grew ~20 MB a minute on Windows under
steady requests (#2515); lightweight mode lets it go.

- settings.Lightweight is a *bool: nil (never chosen) is on, false is
  off, true is on. LightweightOn() says which; gui/lightweight.go reads
  it. KeepOwn still keeps this computer's value on a sync or a restore.
- app.js shows On unless lightweight is false, and the prefs save sends
  s.lightweight as it is: unchosen stays out of the JSON, so saving
  another setting doesn't choose it.

Caveat: until now Off was a bool with omitempty, so it was never stored.
A user who chose Off before this can't be told from one who never chose,
and gets On. Only choices made from this release on are kept.

Tests:
- settings TestLightweightKeptAndOwn: on when unset, Off saved reads back
  off, another save keeps it off, KeepOwn keeps this computer's Off over
  the other's On, and an empty one stays unset. Broken by hand
  (`!= nil && *`) it fails "off for a user who never chose".
- lightweight.test.cjs: On shown for a user who never chose; another
  setting's save posts no lightweight; Off posts false and shows Off;
  another save keeps false; On posts true; nothing scrolls. Its viewport
  is 1200 tall: rows added above had put Off under the window's foot
  (y≈1008 of 1000), where the mouse click did nothing.
- segs-glide and segs-press-redraw start from a user who turned it off,
  so On is still a pick away; README's lightweight line says the new
  default.

Run at this commit's parent (the #2683 test fix on origin/main
f73378365), chromium 1234 and webkit 2336, playwright 1.62.0:
- lightweight, segs-glide, segs-press-redraw, settings-general
  (--test-concurrency=1): 90 of 90. These are every GUI file that reads
  lightweight (grep); no others reach it.
- go test -timeout 45m ./internal/settings ./internal/gui: ok (gui 554s).
- gofmt -l internal/: nothing. GOOS=linux and GOOS=windows go vet -tags
  nogui ./...: clean.

Not tried: the real app's webview being let go after this change on
Windows or Linux; the release path is the same as with On chosen before.
2026-10-20 20:23:50 +08:00

97 lines
2.9 KiB
Go

package settings
import "testing"
// Lightweight mode (#580) is on for a user who never chose, 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("off for a user who never chose")
}
off, on := false, true
s := Load()
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})
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)
}
}
// 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")
}
}