diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index a4e3afab5..a82fb53ff 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -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). diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 1a7a370e6..b20e37da9 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -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 diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 27c8c818a..1e95bb5fb 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -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(); { diff --git a/internal/gui/tests/editor-roomy.test.cjs b/internal/gui/tests/editor-roomy.test.cjs new file mode 100644 index 000000000..b02166497 --- /dev/null +++ b/internal/gui/tests/editor-roomy.test.cjs @@ -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, []); + }); + } +}