gui: a provider's editor grows with a large window (5046312 on Discord)
5046312 on Discord: in a large, wide window the provider editor (Codex's, with its accounts, meters, cap pill, switches and many option rows) stayed a 600px box in the middle, cramped, and asked for a better layout or a resizable sheet. drawEditor's editor now carries `roomy`, and openModal copies it onto #modal's dialog as it already did `wide`. `.modal .dialog.roomy` is min(max(600px, 56vw), 880px, 100%): 600 up to a 1071px window, then 56% of it, at most 880, as a Mac sheet takes the room its content needs. Its height already follows the content up to the window, so no new height rule. A question that takes the editor's place in the same dialog (Sign out's forget-ask, Disconnect, ...) drops the class and stays 600. No drag handle. The rows themselves are unchanged. Every provider editor (subscriptions, keys, new providers, presets) goes through drawEditor. The core-script budget is not raised (7 bytes under). Sizes (chromium, en; width x height of the dialog): window before after 2560x1440 600 x 1228 880 x 1038.5 1440x900 600 x 810 806.4 x 810 1100x800 600 616 1024x768 600 600 560x420 512 512 390 web 374 374 Run at the pushed tree (this commit on 019b308f1; the whole-suite runs below at earlier bases, editor-roomy, i18n-keys and the budget tests again at019b308f1): - editor-roomy.test.cjs (new), chromium and webkit, en zh zh-TW ja de, at 2560, 1440, 1100, 1024, 800, 560 and 390 (magpie web): the width, the dialog in the window, head and buttons in sight, no sideways scroll, nothing past its sides; and at 2560 Sign out's question is 600 and the editor is 880 again after Cancel. 80/80 on mote and on WSL. - go test -tags nogui ./internal/gui on mote (TestCoreScriptBudget): ok. - The whole GUI suite on WSL magpie-desktop (Linux, both engines) at ed852df10 (the same change on838d12d6f): 18363 tests, 17874 pass, 489 red in 100 files. The 100 files again alone at head and at origin/mainb2f7818d2: 472 and 452 red, the same tests save flakes that change language between runs. editor-advanced-align, gateway-key-models, codex-predictions and codex-credits-first, one at a time: identical reds on both. Named issues: #4471 (WSL whole-suite reds, the class), #4203 agent-panel-name-width, #4683 balance-fix, #4908 codex-credits-first, #2624 codex-predictions, #4616 gateway-key-models, #4541 page-width-steady, #3699 allow-ips. Broken by hand: the test on origin/main's assets fails 40 of 80 (every size from 1100 up, "dialog is 880px wide...: 600"), the narrow ones pass; with openModal's toggle made add-only, the Sign out case fails 10/10 ("the question is 600px wide"). Not tried: the real Wails app on macOS, Windows and Linux (WebKitGTK); the whole GUI suite on mote (another session's full suite held it); other dialogs, left at 600 on purpose.
This commit is contained in:
@@ -529,6 +529,7 @@ covers it in both engines, every language and a narrow window.
|
||||
- A connected agent's row in the window opens and closes on a click anywhere on it that isn't one of its controls, as a disclosure row does on the Mac (NG_shiyu on X, `connectRow` in [`app.js`](../../internal/gui/assets/app.js)): the click is handed to the row's *Models {n}* link (`expandLink`), which stays the control the keyboard and a screen reader use and keeps `aria-expanded`. Buttons, links, inputs, anything with a role, the grip and the opened sheet (`.ag-exp`) keep their own clicks, and a click that ends a text selection does nothing. The panel's rows did this already (`agent-row-disclose.test.cjs`).
|
||||
- An agent whose own model menu is the list picked in magpie (ZCode, Claude Desktop, Cursor Private Inference, …: `listsMenu`) says that list as its ticks are, on its button and on the panel row (`menuSaid` in [`app.js`](../../internal/gui/assets/app.js)): every model ticked is *All N models*, one or two by their names, more as *Showing x / N models*, none as *No models*. It never says the first names and a +N: routing groups come first, so that read as a pick of one group and one model while every model was on (NG_shiyu on X). Other agents' start pickers still say the one model or group they start on (`agent-menu-label.test.cjs`).
|
||||
- Every page of the window keeps to one width, at most 1200px of content centred, with a 16px gutter in a narrow window (`padding: max(16px, calc(50% - 600px))` on each `#view-…`, #860). Routing, Usage and Sessions are in that rule too (面条 on Discord), so a large screen doesn't stretch them edge to edge while the others sit in the middle; their columns follow the room they get (`byWidth`). See `page-width.test.cjs`.
|
||||
- Every dialog in `#modal` is 600px wide (`.modal .dialog`), a long text's editor 880 (`.wide`). A provider's editor (`drawEditor`, its accounts, meters and many rows) is `.roomy` and grows with a large window as a Mac sheet takes the room its content needs: 600 up to a 1071px window, then 56% of it, at most 880 (5046312 on Discord). `openModal` copies both classes from the content, so a question that takes the editor's place (Sign out's) stays 600. Its height already follows the content up to the window. See `editor-roomy.test.cjs`.
|
||||
- The page must work in Chromium (Windows' WebView2) and WebKit (macOS, and WebKitGTK on Linux). GUI tests run in both engines.
|
||||
- In the design of macOS 26 the main window has the corners of a window with a plain title bar, and its lights stay where the toolbar had them. `TestMainWindowCorners` ([`titlebar_darwin_test.go`](../../internal/gui/titlebar_darwin_test.go)) measures this in a process of its own, with package `windowshape`: after a new title and size and a new system appearance, as AppKit draws that appearance, where a first press with another app in front begins a window drag, and where a sheet begins. It runs that process as linked against the macOS 26 SDK and against macOS 15's, whatever SDK the toolchain has (`runAppKitSDK` and `stampSDK` give the copy it runs that SDK, and sign it again). In the earlier design, on an older macOS or with macOS 15's SDK, it checks that the window keeps its toolbar; `TestMainWindowRightToLeft` checks that it keeps it with the lights on the right. Both run in CI's macOS job. No test covers `UIDesignRequiresCompatibility`: AppKit reads it from an app bundle's Info.plist, LaunchServices registers each bundle that runs, and a press sent within a process run from one doesn't always begin a window drag.
|
||||
- On Linux the panel is frameless and the main window has a hidden title bar (`plainTitlebar`). GTK 3 asks KDE's Wayland session (KWin's decoration protocol) for a frame drawn by KWin on any window without client-side decorations, an undecorated one too, so `ownFrame` tells KWin the panel draws its own on each realize (#1283). GTK 4 builds ask for none themselves. With no KWin title bar, and with a Wayland window placed by the compositor rather than by the icon, the panel's header is its drag handle on Linux, as the window's is (`--wails-draggable` in `app.js`; `panel-drag-linux.test.cjs`); on the Mac and Windows the panel isn't dragged (#1430).
|
||||
|
||||
@@ -3975,6 +3975,10 @@ html.theming, html.theming *, html.theming *::before, html.theming *::after {
|
||||
border-radius: 14px; background: var(--card);
|
||||
box-shadow: 0 0 0 1px var(--line), 0 24px 60px rgba(0, 0, 0, .32), 0 2px 8px rgba(0, 0, 0, .12);
|
||||
}
|
||||
/* a provider's editor (accounts, meters, many rows) grows with a large
|
||||
window, as a Mac sheet takes the room its content needs: 600 up to a
|
||||
1071px window, then 56% of it, at most 880 */
|
||||
.modal .dialog.roomy { width: min(max(600px, 56vw), 880px, 100%); }
|
||||
.modal .dialog.swap { animation: content-in .22s var(--ease); }
|
||||
/* In a dialog the editor's head and buttons stay put and only the fields
|
||||
between them scroll; both bars are the same height, their contents
|
||||
|
||||
@@ -8757,8 +8757,8 @@ function openModal(content, quiet) {
|
||||
d.classList.remove("swap");
|
||||
if (!fresh && !quiet) { void d.offsetWidth; d.classList.add("swap"); } // content changed: a soft refresh, not a re-entrance
|
||||
frame(content);
|
||||
// an editor of long text (a prompt's) takes a wider dialog
|
||||
d.classList.toggle("wide", content.classList.contains("wide"));
|
||||
// a prompt's editor is wider, a provider's grows with the window
|
||||
for (const c of ["wide", "roomy"]) d.classList.toggle(c, content.classList.contains(c));
|
||||
// Keep focus through a redraw of an open editor.
|
||||
const active = d.contains(document.activeElement) ? document.activeElement : null;
|
||||
const focusID = active?.id;
|
||||
@@ -9083,7 +9083,7 @@ function drawEditor(p, presetID) {
|
||||
: pr
|
||||
? { id: pr.id, name: pr.name, preset: pr.id, key: "", chosen: [], extra: [], headers: [] }
|
||||
: { id: "", name: "", preset: "", chat: "", responses: "", anthropic: "", decide: "", catalog: "", key: "", api: "openai", chosen: [], extra: [], headers: [], icon: "" });
|
||||
const ed = el("div", "editor" + (isNew ? " new" : ""));
|
||||
const ed = el("div", "editor roomy" + (isNew ? " new" : ""));
|
||||
ed.onclick = (e) => e.stopPropagation();
|
||||
|
||||
{
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A provider's editor takes the room a large window offers (5046312 on
|
||||
// Discord: in a large, wide window Codex's editor, its accounts with their
|
||||
// meters, cap pill, switches and option rows, stayed a 600px box in the
|
||||
// middle, cramped). From a 1071px window it grows with the window, 56% of
|
||||
// its width, up to 880px, as a Mac sheet takes the room its content needs;
|
||||
// narrower it is 600px as before, and in magpie web on a phone (390px) it
|
||||
// fits the window with nothing across it cut off or scrolled sideways. A
|
||||
// question that takes the editor's place in the same dialog (Sign out's)
|
||||
// stays 600px. Chromium and WebKit, every language, the API faked.
|
||||
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 { strings } = require("./strings.cjs");
|
||||
|
||||
// MAGPIE_ROOMY_ASSETS: an older asset directory, to see this fail on it
|
||||
const assets = path.resolve(process.env.MAGPIE_ROOMY_ASSETS || path.join(__dirname, "../assets"));
|
||||
const { I18N } = strings();
|
||||
const tr = (lang, k) => (lang === "en" ? k : I18N[lang]?.[k] || k);
|
||||
|
||||
const accounts = Array.from({ length: 5 }, (_, i) => ({ user: `account-${i + 1}@example.invalid`, active: i === 0, on: true, plan: i % 2 ? "pro" : "plus" }));
|
||||
const codex = { id: "codex", name: "Codex", icon: "codex", models: Array.from({ length: 12 }, (_, i) => ({ id: `gpt-6-${i + 1}`, on: i % 3 !== 2 })), agents: [], key: {}, routing: "smart",
|
||||
account: { agent: "codex", agentName: "Codex", agentIcon: "codex", user: accounts[0].user, logins: accounts } };
|
||||
const SOLO = "solo@example.invalid";
|
||||
const solo = { ...codex, account: { ...codex.account, user: SOLO, logins: [{ user: SOLO, plan: "plus", active: true, on: true }] } };
|
||||
const inHours = (h) => new Date(Date.now() + h * 36e5).toISOString();
|
||||
const usage = () => Object.fromEntries(accounts.map((a, i) => [a.user, { provider: "codex", windows: [{ name: "5 hours", used: 10 + 15 * i, resetsAt: inHours(3) }, { name: "Weekly", used: 5 * i, resetsAt: inHours(100) }] }]));
|
||||
|
||||
function serve(lang, { web = false, one = false } = {}) {
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:${JSON.stringify(lang)},theme:"light",web:${web}};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [one ? solo : codex], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
|
||||
if (url.pathname === "/api/login/usage") return json(usage());
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
|
||||
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)];
|
||||
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
// the window, the width the editor's dialog takes in it, and whether it is
|
||||
// magpie web (a phone's is the narrowest; the app's window is 560 at least)
|
||||
const SIZES = [[2560, 1440, 880], [1440, 900, 806.4], [1100, 800, 616], [1024, 768, 600], [800, 600, 600], [560, 420, 512], [390, 844, 374, true]];
|
||||
|
||||
const measure = (page) => page.evaluate(() => {
|
||||
const r = (e) => { const b = e.getBoundingClientRect(); return { top: b.top, bottom: b.bottom, left: b.left, right: b.right, width: b.width, height: b.height }; };
|
||||
const d = document.querySelector("#modal .dialog"), body = d.querySelector(".ebody");
|
||||
// every element in the editor that is drawn: none reaches past the
|
||||
// dialog's sides (an element that scrolls sideways itself, the model
|
||||
// chips' strip, holds what is in it)
|
||||
const out = [];
|
||||
for (const e of d.querySelectorAll(".editor *")) {
|
||||
const b = e.getBoundingClientRect();
|
||||
if (!b.width || !b.height || e.closest("[hidden]") || getComputedStyle(e).visibility === "hidden") continue;
|
||||
let inScroller = false;
|
||||
for (let p = e.parentElement; p && p !== body; p = p.parentElement) if (/auto|scroll/.test(getComputedStyle(p).overflowX)) inScroller = true;
|
||||
if (inScroller) continue;
|
||||
if (b.left < r(d).left - 1 || b.right > r(d).right + 1) out.push(`${e.tagName.toLowerCase()}.${[...e.classList].join(".")} ${Math.round(b.left)}..${Math.round(b.right)}`);
|
||||
}
|
||||
return {
|
||||
view: { width: innerWidth, height: innerHeight }, dialog: r(d), head: r(d.querySelector(".ehead")), bar: r(d.querySelector(".editor > .bar")),
|
||||
across: body.scrollWidth - body.clientWidth, pageAcross: document.scrollingElement.scrollWidth - innerWidth,
|
||||
out: out.slice(0, 5),
|
||||
};
|
||||
});
|
||||
|
||||
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, height, want, web] of SIZES) {
|
||||
test(`${engine} ${lang} ${width}x${height}${web ? " web" : ""}: Codex's editor is ${want}px wide, nothing across it cut off`, 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 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, { web }));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator('.row.provider[data-id="codex"]').click();
|
||||
await page.locator("#modal .ebody").waitFor();
|
||||
// the allowances drawn in, the dialog settled
|
||||
await page.waitForFunction(() => document.querySelectorAll("#modal .acc .aq .skeleton").length === 0 && document.querySelectorAll("#modal .acc .aq").length === 5);
|
||||
await page.waitForFunction(() => !document.querySelector("#modal .dialog").getAnimations().length);
|
||||
const at = await measure(page);
|
||||
t.diagnostic(`dialog ${at.dialog.width}x${at.dialog.height} in ${width}x${height}`);
|
||||
if (process.env.ARTIFACT_DIR && lang === "en") await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `editor-roomy-${engine}-${width}x${height}.png`) });
|
||||
assert.ok(Math.abs(at.dialog.width - want) < 1, `the editor's dialog is ${want}px wide in a ${width}x${height} window: ${at.dialog.width}`);
|
||||
assert.ok(at.dialog.left >= 0 && at.dialog.right <= width && at.dialog.top >= 0 && at.dialog.bottom <= height, `the dialog fits the window: ${JSON.stringify(at.dialog)}`);
|
||||
assert.ok(at.head.top >= 0 && at.bar.bottom <= height, `its head and buttons are in sight: ${JSON.stringify([at.head, at.bar])}`);
|
||||
assert.equal(at.across, 0, "the editor's body doesn't scroll sideways");
|
||||
assert.ok(at.pageAcross <= 0, `the page doesn't scroll sideways: ${at.pageAcross}`);
|
||||
assert.deepEqual(at.out, [], "nothing in the editor reaches past its sides");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
|
||||
test(`${engine} ${lang} 2560x1440: Sign out's question in the editor's place stays 600px, and the editor grows again after Cancel`, 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: 2560, height: 1440 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, { one: true }));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator('.row.provider[data-id="codex"]').click();
|
||||
await page.locator("#modal .acc .aq .skeleton").first().waitFor({ state: "detached" });
|
||||
await page.waitForFunction(() => !document.querySelector("#modal .dialog").getAnimations().length);
|
||||
assert.equal(await page.evaluate(() => document.querySelector("#modal .dialog").getBoundingClientRect().width), 880, "the editor is 880px");
|
||||
await page.locator("#modal .acc .acc-more").click();
|
||||
await page.locator("#modal .acc button", { hasText: tr(lang, "Sign out") }).click();
|
||||
await page.locator("#modal .forget-ask").waitFor();
|
||||
await page.waitForFunction(() => !document.querySelector("#modal .dialog").getAnimations().length);
|
||||
assert.equal(await page.evaluate(() => document.querySelector("#modal .dialog").getBoundingClientRect().width), 600, "the question is 600px wide");
|
||||
await page.locator("#modal .forget-ask button", { hasText: tr(lang, "Cancel") }).click();
|
||||
await page.locator("#modal .acc").first().waitFor();
|
||||
await page.waitForFunction(() => !document.querySelector("#modal .dialog").getAnimations().length);
|
||||
assert.equal(await page.evaluate(() => document.querySelector("#modal .dialog").getBoundingClientRect().width), 880, "the editor is back at 880px");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user