From f36e744c300fcaf7ceb77ca0ef5061eaacfe0499 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 12 Oct 2026 22:41:51 +0800 Subject: [PATCH] =?UTF-8?q?gui:=20Settings=20=E2=80=BA=20General=20says=20?= =?UTF-8?q?each=20setting's=20name=20alone=20where=20it=20says=20enough,?= =?UTF-8?q?=20and=20Language=20is=20one=20menu=20(1ooogle=20on=20X)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1ooogle's mockup on X redrew Settings › General the way macOS System Settings reads it. The owner approved, and this follows it. Rows that now show only their name: - Appearance, Text size, Interface and Code font, the tray click, Provider in model names, the Codex titles, auto-review and memories model rows, Open at login and Show in Dock. - A font row's line shows only while its fonts are loading or have failed. - The text size keys (⌘0 / Ctrl+0) move into the choices' tooltip. Rows that keep one short line, because the name alone doesn't explain the setting or what it costs: - Codex subagents, Long conversations, Lightweight mode, Prevent sleep and Session terminal. Renames: - "Tray icon" becomes "Click the tray icon to", with the choices "Open the quick panel" and "Open the main window" (点击托盘图标: 打开快捷面板 / 打开主窗口). - "Keep awake while agents work" becomes "Prevent sleep" (防止休眠: 在 magpie 运行任务时,让电脑保持唤醒状态). - "Dock" becomes "Show in Dock" (显示程序坞). Language is one button showing the language picked (renderLangPick). It opens in the app's own menu (openProtoMenu, styled like Session terminal's sess-pick), not a native ) showing the language; +// its menu, the app's own, lists all six, and a pick saves lang and +// draws the page in it, the button staying under the pointer; +// - no row has a coloured stripe down its left. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); +const { watchSettingsReads, settingsDrawn } = require("./reader.cjs"); + +const assets = path.resolve(__dirname, "../assets"); +const names = { en: "English", zh: "简体中文", "zh-TW": "繁體中文", ja: "日本語", de: "Deutsch" }; +const appearance = { en: "Appearance", zh: "外观", "zh-TW": "外觀", ja: "外観", de: "Darstellung" }; +const system = { en: "System", zh: "跟随系统", "zh-TW": "跟隨系統", ja: "システム", de: "System" }; +// the rows whose name says enough, found by the control they hold +const bare = ["#themeSegs", "#langPick", "#textSizeSegs", "#traySegs", "#plainNamesSegs", "#codexTitlesPick", "#codexAutoReviewPick", "#loginSegs", "#dockSegs"]; +// the rows that keep a line, one each +const kept = ["#fullContextSegs", "#lightweightSegs", "#keepAwakeSegs", "#sessionTerminalRow .sess-pick"]; + +function serve(lang, posted, st) { + const settings = () => ({ lang, theme: "light", searchVendors: [], searchAPIs: [], ...st }); + return async (r) => { + const url = new URL(r.request().url()); + const json = (data, status = 200) => r.fulfill({ status, json: data }); + if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` }); + if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: settings() }); + if (url.pathname === "/api/settings") { + if (r.request().method() === "POST") { + const b = JSON.parse(r.request().postData()); + posted.push(b); + Object.assign(st, b); + } + return json(settings()); + } + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } }); + if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + await r.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) for (const width of [1000, 440]) { + test(`${engine} ${lang} ${width}px: Settings → General says each name alone where it says enough, Language one menu`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width, height: 760 } })).newPage(); + page.setDefaultTimeout(5000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.addInitScript(() => Object.defineProperty(navigator, "platform", { get: () => "MacIntel" })); + const posted = [], st = {}; + await page.route("**/*", serve(lang, posted, st)); + await watchSettingsReads(page); + await page.goto("http://magpie.test/?view=settings&tab=general"); + await settingsDrawn(page); + await page.locator("#langPick span").waitFor(); + + const rows = await page.evaluate(([bare, kept]) => { + const row = (sel) => document.querySelector(sel)?.closest(".row"); + return { + bare: bare.map((sel) => { const r = row(sel); return [sel, !r ? "missing" : r.hidden ? "hidden" : [...r.querySelectorAll(".sub")].filter((s) => s.getClientRects().length && s.textContent.trim()).map((s) => s.textContent)]; }), + kept: kept.map((sel) => { + const r = row(sel), s = r?.querySelector(".sub"); + return [sel, !r || r.hidden ? "missing" : !s ? "no line" : { text: s.textContent, lines: Math.round(s.getBoundingClientRect().height / parseFloat(getComputedStyle(s).lineHeight || 16)), cut: s.scrollWidth > s.clientWidth + 1 }]; + }), + stripes: [...document.querySelectorAll("#setPage-general .row")].filter((r) => parseFloat(getComputedStyle(r).borderLeftWidth) > 1).length, + sideways: document.documentElement.scrollWidth > innerWidth, + }; + }, [bare, kept]); + for (const [sel, subs] of rows.bare) assert.deepEqual(subs, [], `${sel}'s row says its name alone`); + for (const [sel, sub] of rows.kept) { + assert.equal(typeof sub, "object", `${sel}: ${sub}`); + assert.ok(sub.text.trim() && sub.lines <= 1, `${sel}: ${JSON.stringify(sub)}`); + if (width === 1000) assert.equal(sub.cut, false, `${sel}'s line is cut short: ${sub.text}`); + } + assert.equal(rows.stripes, 0, "a row has a stripe down its left"); + assert.equal(rows.sideways, false, "the page scrolls sideways"); + + // Language: one button showing the language, the app's menu listing all six + const pick = page.locator("#langPick"); + assert.equal(await pick.evaluate((b) => b.tagName), "BUTTON"); + assert.equal(await page.locator("#setPage-general select").count(), 0, "no native