settings: lightweight mode is off for a user who never chose

The owner, 10-21: "要默认关闭「轻量模式」,不然太卡了". With it on, the window
is made again and its page loaded again on every opening, which is slow.
28bec1507 had made it on for a user who never chose, against a hidden
webview growing ~20 MB a minute on Windows (#2515); that user now gets
the kept window again. A user who turned it on or off keeps their choice:
only an unset value changes meaning (LightweightOn, Settings › General's
row).

Run on origin/main b855cfee9 + this commit, macOS, playwright 1.62.0:
- go test ./internal/settings/ -run Lightweight ok; red with the old
  LightweightOn.
- lightweight.test.cjs, segs-glide, segs-press-redraw, settings-general:
  89/90 in chromium and webkit, every language; the red was
  segs-press-redraw chromium en 440px while a full GUI suite ran beside
  it, and the file passes 42/42 alone. lightweight.test.cjs goes 4 of 8
  red with app.js's old `!== false`.
- gofmt -l clean; GOOS=linux go vet -tags nogui and GOOS=windows go vet
  of internal/settings and internal/gui.

Shipped at the owner's word (10-21, "赶紧上线") before the full GUI suite
finished: it was stopped at ~2,040 passing tests (about a quarter of the
files, on b855cfee9 + the dialog change), with two reds,
desktop-longest chromium zh 640px and gateway-key-groups chromium en,
both under load at ~100. On origin/main c79400556 + both commits (rebased after onto
e68a0b1db, which adds only internal/sessions):
desktop-longest, gateway-key-groups, modal-morph, lightweight,
segs-glide, segs-press-redraw and settings-general 108/108 in chromium
and webkit; go test ./internal/settings/ ok; go test ./internal/gui/
-run 'Budget|Lightweight' ok; gofmt -l clean; GOOS=linux go vet -tags
nogui and GOOS=windows go vet of internal/settings and internal/gui.
Not run: the rest of the GUI suite.
This commit is contained in:
yetone
2026-10-21 18:45:23 +08:00
parent 1b9b97f8db
commit c627652e9a
6 changed files with 39 additions and 30 deletions
+1 -1
View File
@@ -19360,7 +19360,7 @@ function renderSettings() {
s.dock ? "on" : s.dockWindow ? "window" : "off", (v) => savePrefs({ ...keep, dock: v === "on", dockWindow: v === "window" })));
// a closed window's webview let go (#580): the app's windows alone
$("#lightweightRow").hidden = web;
$("#lightweightSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.lightweight !== false ? "on" : "off",
$("#lightweightSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.lightweight === true ? "on" : "off",
(v) => savePrefs({ ...keep, lightweight: v === "on" })));
// the display kept on too (#975): an agent recording the screen found it locked
$("#keepAwakeSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")], ["display", t("Screen on too")]],
+2 -2
View File
@@ -2158,8 +2158,8 @@ WebKit, in English and Chinese:
node --test internal/gui/tests/plugin-progressive.test.cjs
`lightweight.test.cjs` checks Settings → General's Lightweight mode row
(#580): on for a user who never chose, Off and On saved as `lightweight`
false and true without the page moving, another setting's save keeping the
(#580): off for a user who never chose, On and Off saved as `lightweight`
true and false without the page moving, another setting's save keeping the
choice or leaving it unchosen (no `lightweight` posted), no left-border
accent, and no such row on a browser's page (`web`). English and Chinese,
Chromium and WebKit, with `/api/settings` faked:
+13 -13
View File
@@ -1,7 +1,7 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// somls on #580: GUI版可否增加轻量模式,关闭面板退出webview,减少资源占用.
// Settings → General has a Lightweight mode row, on for a user who never
// chose: Off and On are saved as lightweight false and true, the click
// Settings → General has a Lightweight mode row, off for a user who never
// chose (the owner, 10-21: "太卡" on by default): On and Off are saved as lightweight false and true, the click
// moving nothing; the page saved again elsewhere keeps the choice, or
// leaves it unchosen; a browser's page (web) has no window
// to let go and shows no such row. In English and Chinese, with the API faked.
@@ -72,7 +72,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await row.locator(".name").innerText(), w.name);
assert.equal(await row.locator(".sub").innerText(), w.sub);
const opt = (name) => row.locator("#lightweightSegs .opt", { hasText: name });
assert.equal(await row.locator("#lightweightSegs .opt.on").innerText(), w.on, "on for a user who never chose");
assert.equal(await row.locator("#lightweightSegs .opt.on").innerText(), w.off, "off for a user who never chose");
const where = () => page.evaluate(() => [scrollX, scrollY, document.scrollingElement.scrollTop, ...[...document.querySelectorAll("*")].filter((e) => e.scrollTop).map((e) => e.scrollTop)]);
const before = await where();
const click = async (loc) => {
@@ -88,19 +88,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await click(page.locator("#dockSegs .opt").first()).catch(() => {});
for (let i = 0; i < 20 && posted.length === n; i++) await page.waitForTimeout(50);
if (posted.length > n) assert.equal("lightweight" in posted.at(-1), false, `another setting's save chose it: ${JSON.stringify(posted.at(-1))}`);
await click(opt(w.off));
for (let i = 0; i < 50 && posted.at(-1)?.lightweight !== false; i++) await page.waitForTimeout(50);
assert.equal(posted.at(-1)?.lightweight, false, `posted ${JSON.stringify(posted)}`);
assert.equal(st.lightweight, false);
assert.equal(await row.locator("#lightweightSegs .opt.on").innerText(), w.off);
// another setting saved keeps it off
await click(opt(w.on));
for (let i = 0; i < 50 && posted.at(-1)?.lightweight !== true; i++) await page.waitForTimeout(50);
assert.equal(posted.at(-1)?.lightweight, true, `posted ${JSON.stringify(posted)}`);
assert.equal(st.lightweight, true);
assert.equal(await row.locator("#lightweightSegs .opt.on").innerText(), w.on);
// another setting saved keeps it on
n = posted.length;
await click(page.locator("#dockSegs .opt").last()).catch(() => {});
for (let i = 0; i < 20 && posted.length === n; i++) await page.waitForTimeout(50);
if (posted.length > n) assert.equal(posted.at(-1).lightweight, false, "another setting's save turned it on");
await click(opt(w.on));
for (let i = 0; i < 50 && posted.at(-1)?.lightweight !== true; i++) await page.waitForTimeout(50);
assert.equal(posted.at(-1).lightweight, true);
if (posted.length > n) assert.equal(posted.at(-1).lightweight, true, "another setting's save turned it off");
await click(opt(w.off));
for (let i = 0; i < 50 && posted.at(-1)?.lightweight !== false; i++) await page.waitForTimeout(50);
assert.equal(posted.at(-1).lightweight, false);
assert.deepEqual(await where(), before, "the clicks moved the page");
// the row has no coloured stripe down its left
const left = await row.evaluate((e) => getComputedStyle(e).borderLeftWidth);
+1 -2
View File
@@ -132,8 +132,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const errors = [];
// WebKit's notice of a ResizeObserver loop is no error of the page's
page.on("pageerror", (e) => { if (!/ResizeObserver loop/.test(e.message)) errors.push(e.message); });
// turned off by the user, so On is a glide away (it is on for one
// who never chose)
// turned off by the user, so On is a glide away
const st = { lightweight: false }, ctl = { hold: 0, refuse: false };
await page.route("**/*", serve(lang, st, ctl));
// opened on another tab: General is drawn while hidden
+13 -5
View File
@@ -2,16 +2,24 @@ 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.
// 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("off for a user who never chose")
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)
+9 -7
View File
@@ -371,8 +371,9 @@ type Settings struct {
// Lightweight lets the webview of a window closed — the tray panel or
// the main window — go once it has stayed closed a while, and makes it
// again when it is opened (#580): less memory, a moment's wait. This
// computer's own (KeepOwn). Nil is on: a user who never chose has it,
// one who turned it off keeps it off (LightweightOn).
// computer's own (KeepOwn). Nil is off: a window made again on each
// opening was too slow to have by default (the owner, 10-21: "太卡");
// one who turned it on keeps it on (LightweightOn).
Lightweight *bool `json:"lightweight,omitempty"`
// KeepAwake keeps this computer from going to sleep by itself while
// agents work through the gateway and for a while after (xiao_wang24004
@@ -968,11 +969,12 @@ func CarryPerModel(in, cur *Settings) {
// models that can take more.
const WorkingWindow = 272000
// LightweightOn says whether lightweight mode is on: unless the user
// turned it off. A hidden webview kept for good holds what its page drew
// while hidden, which grew ~20 MB a minute on Windows under steady
// requests (#2515).
func (s Settings) LightweightOn() bool { return s.Lightweight == nil || *s.Lightweight }
// LightweightOn says whether lightweight mode is on: only when the user
// turned it on. It was on for a user who never chose, since a hidden
// webview kept for good holds what its page drew while hidden (~20 MB a
// minute on Windows under steady requests, #2515), but each opening then
// waited for the page to load again.
func (s Settings) LightweightOn() bool { return s.Lightweight != nil && *s.Lightweight }
// Working is the context window an agent is told for a model with one of
// n tokens (see FullContext).