gui: magpie web on a phone has a tab bar with More (geraldpppppp on X)

On a phone, magpie web's pages sat in a strip under the header that
scrolled sideways, with nothing to show that more pages lay past its
edge. Agents, Library and the rest looked missing. The pages are now a
tab bar at the foot, as an iPhone app's (HIG): each tab its mark over its
word, the page open marked. Five tabs at most: with more pages than
that, the fifth is More, and its menu lists the rest with their marks
and a tick on the open one. More is marked while one of them is open,
and it carries the dot when one of them has one. phonetabs.js does
this. app.js loads it lazily only on a phone, so the core script
doesn't grow. A status line comes up over the bar. The bar is only for
the window, never the tray panel (body.panel).

Agents still isn't shown in gateway mode on a machine with no agents,
as designed (Settings > General > Gateway mode brings it back). Library
has been shown in gateway mode since f285426ac.

Tests: phone-tabs.test.cjs (new) runs at 390x844 in chromium and webkit,
in en, zh, zh-TW, ja and de, with gateway mode on and off. It checks:
- five tabs with More fifth, at the foot, 44px tall;
- nothing scrolls sideways;
- every page is reached from the bar or from More, and More's menu opens
  above the bar;
- the bar covers no page content and no status line;
- a desktop browser has no More.
reader.cjs gets openPage() (the tab, or More's menu). mobile-web,
phone-no-sideways, routing-held-dot and name-suffix-saved open pages
through it. phone-web checks the bar at the foot. old-webkit lists
phonetabs.js as lazy. market-more waits for the view's own foot, not the
window's, which is now above the bar. group-from-model-add wheels Add
wholly into the view before its press, because at 600x420 WebKit took a
press on Add's half-hidden middle as one on the header.

Run on mote:
- The whole GUI suite once (450 files, concurrency 3). 33 red files
  were then run on this change's base and on the branch. The reds only
  on the branch were the four tests that tapped tabs now under More,
  phone-web's old label check, market-more, group-from-model-add (webkit
  600x420), and the panel tests agent-menu-label, zcode-models and
  panel-fit-tabs (webkit). The panel tests are web:true at 360-380px, so
  the bar's padding reached the panel. It is now scoped :not(.panel).
- After the fixes: phone-web, market-more, group-from-model-add,
  agent-menu-label, zcode-models, panel-fit-tabs, phone-tabs,
  mobile-web, phone-no-sideways, routing-held-dot, name-suffix-saved,
  old-webkit and i18n-keys. All are green except reds already filed on
  main: #5919 (old-webkit :has), #5869 (phone-no-sideways de 375) and
  #5215 (tray-cell-click, a web:false panel test). mobile-web's 900/1280
  desktop screenshots need git, so they were run with BASE_REF set to a
  commit of the base's assets: 30/30 pass in both engines, so the
  desktop is unchanged.
- gofmt, go vet for darwin, linux (nogui) and windows, and go test
  ./internal/gui.
- Again at the pushed head, rebased on origin/main ca7a39291: the 13
  GUI files above (239 pass; reds only #5919, #5869 and mobile-web's
  git-less desktop compare), gofmt, vet on all three, and go test
  ./internal/gui ok. TestCoreScriptBudget was over at the old base
  662546e78 and passes here: app.js is ~430 bytes smaller.
- Rebased again on 388ca9ad4 (two agent commits touching app.js and
  i18n.js): the budget tests, i18n-keys, phone-tabs and phone-web
  pass (34 of 34). Then onto 0baa223ec (Kun; a one-line app.js change)
  with no further run before the push.

Broken by hand:
- Without layoutNav's import of phonetabs.js, phone-tabs is 20 of 24 red.
- Without :not(.panel), panel-fit-tabs (webkit, 5 languages) and
  agent-menu-label go red.

Not tried: a real iPhone's Safari, or the LAN share opened on a real
phone.
This commit is contained in:
yetone
2026-11-10 22:10:55 +08:00
parent 0baa223ec9
commit 6bac8f8a59
15 changed files with 304 additions and 50 deletions
File diff suppressed because one or more lines are too long
+31 -12
View File
@@ -339,24 +339,43 @@ body:not(.side-nav) #nav button[data-view="groups"], body.side-nav .rt-togroups
.top.packed .seg { min-width: 0; flex: 0 1 auto; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.top.packed .seg::-webkit-scrollbar { display: none; }
/* magpie web on a phone, or a browser as narrow (phoneWeb): the magpie and
the icons in a row, the tabs at their size in a row of their own under
them, sliding sideways when they don't fit (they were squeezed into the
room between, too small to read or tap) */
the icons in the header, the pages a tab bar at the foot, as an iPhone
app's: each tab its mark over its word, five at most, the fifth More
when there are more (phonetabs.js). A strip that slid sideways hid the
pages past its edge (geraldpppppp on X) */
@media (max-width: 760px), (pointer: coarse) and (max-width: 1024px) {
body.web:not(.panel) { --tabbar: calc(50.5px + env(safe-area-inset-bottom)); padding-bottom: var(--tabbar); }
body.web .top {
height: auto; min-height: 48px; flex-wrap: wrap; gap: 4px 8px;
padding: calc(6px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
height: auto; min-height: 48px; gap: 4px 8px;
padding: calc(6px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
}
body.web .top .brand, body.web .top .actions { min-height: 40px; align-items: center; }
body.web .top #nav {
position: relative; left: auto; top: auto; transform: none;
order: 3; flex: 0 0 100%; min-width: 0; max-width: 100%;
overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: none;
body.web:not(.panel) .top #nav {
position: fixed; z-index: 15; left: 0; right: 0; top: auto; bottom: 0; transform: none;
display: flex; height: var(--tabbar); padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
border-radius: 0; border-top: .5px solid var(--line);
background: color-mix(in srgb, var(--bg) 86%, transparent);
-webkit-backdrop-filter: saturate(1.6) blur(20px); backdrop-filter: saturate(1.6) blur(20px);
}
body.web .top #nav::-webkit-scrollbar { display: none; }
body.web .top #nav button { flex: none; height: 40px; padding: 0 14px; font-size: 14px; }
body.web:not(.panel) .top #nav > :is(.thumb, .tb-over), body.web:not(.side-nav, .panel) .top #nav > [data-view="groups"] { display: none; }
body.web:not(.panel) .top #nav > button {
flex: 1 1 0; min-width: 0; height: 50px; padding: 5px 2px 3px; border-radius: 0;
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
font-size: 10.5px; font-weight: 500; line-height: 1.1; color: var(--muted);
}
body.web:not(.panel) .top #nav > button.on { color: var(--fg); }
body.web:not(.panel) .top #nav > button > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.web:not(.panel) .top #nav .nav-ic { display: block; flex: none; width: 23px; height: 23px; }
body.web:not(.panel) .top #nav > button.has-dot::after { top: 5px; right: calc(50% - 17px); }
body.web .top .actions { gap: 4px; }
/* a status line comes up over the bar, not under it */
html body.web:not(.panel) :is(.foot .status:not(:empty):not(.lift), .status.lift) { bottom: calc(var(--tabbar) + 10px); }
}
/* More's menu: each page with its tab's mark */
.nav-more-menu .pm-head { display: none; }
.nav-more-menu .pm-item { align-items: center; gap: 10px; padding: 9px 10px; }
.nav-more-menu .nav-ic { display: block; flex: none; width: 20px; height: 20px; color: var(--fg-2); }
.nav-more-menu .pm-name { font-size: 14px; }
@keyframes update-in { from { opacity: 0; max-width: 0; margin-right: 0; padding: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@@ -4338,7 +4357,7 @@ body.panel .modal { padding: 16px 12px; }
body.web .view {
--view-left: max(12px, env(safe-area-inset-left));
--view-right: max(12px, env(safe-area-inset-right));
padding: 2px max(0px, calc(var(--view-right) - var(--bar, 0px))) max(12px, env(safe-area-inset-bottom)) var(--view-left);
padding: 2px max(0px, calc(var(--view-right) - var(--bar, 0px))) 12px var(--view-left); /* the tab bar keeps the home indicator clear */
}
body.web .foot .status { min-width: 0; overflow-wrap: anywhere; }
body.web .row-head { height: auto; min-height: 40px; flex-wrap: wrap; gap: 4px; }
+6 -14
View File
@@ -23202,7 +23202,7 @@ async function show(v) {
$("#pageTitle").textContent = t(title);
if (mode === "window") {
markNav(v);
if (!sideNav()) { slide($("#nav"), "nav"); navInSight(); }
if (!sideNav()) slide($("#nav"), "nav");
else navTopGo($("#nav").querySelector("button[data-view].on"), true);
}
$("#prefs").classList.toggle("on", v === "settings");
@@ -23542,18 +23542,9 @@ function wag() {
document.querySelector(".brand")?.addEventListener("mouseenter", wag);
setTimeout(wag, 250);
// magpie web on a phone, or a browser as narrow: the header is two rows,
// the magpie and the icons over the tabs, which scroll sideways when they
// don't fit, the one open kept in sight
// magpie web on a phone, or a browser as narrow: the tabs are a bar at the foot
function phoneWeb() { return document.body.classList.contains("web") && matchMedia("(max-width: 760px), (pointer: coarse) and (max-width: 1024px)").matches; }
function navInSight() {
const nav = $("#nav"), on = nav?.querySelector("button.on");
if (!phoneWeb() || !on || nav.scrollWidth <= nav.clientWidth) return;
const l = on.offsetLeft - 16, r = on.offsetLeft + on.offsetWidth + 16 - nav.clientWidth;
if (nav.scrollLeft > l) nav.scrollLeft = l;
else if (nav.scrollLeft < r) nav.scrollLeft = r;
}
matchMedia("(max-width: 760px), (pointer: coarse) and (max-width: 1024px)").addEventListener?.("change", () => { layoutNav(); fitTop(); navInSight(); });
matchMedia("(max-width: 760px), (pointer: coarse) and (max-width: 1024px)").addEventListener?.("change", () => { layoutNav(); fitTop(); });
// A narrow window has no room for the whole header: the name goes, leaving
// the magpie, and Update becomes its arrow; narrower still, the tabs stop
@@ -23623,7 +23614,8 @@ try { navPick = localStorage.getItem("magpie.navLayout") || ""; } catch { /* by
if (navPick !== "side" && navPick !== "top") navPick = "";
function layoutNav() {
if (mode !== "window") return;
// magpie web on a phone has its own tab bar and no title bar
// magpie web on a phone has its own tab bar (phonetabs.js) and no title bar
if (phoneWeb()) import("./phonetabs.js").catch(() => {});
const on = !phoneWeb() && (navPick ? navPick === "side" : sideQuery.matches);
if (layoutNav.done && on === sideNav()) {
// the button goes with the phone's layout all the same
@@ -23654,7 +23646,7 @@ function layoutNav() {
navSubs.quiet = true;
navSubs();
navSubs.quiet = false;
if (!on) { slide(nav, "nav"); navInSight(); } else { sideGwRead(); renderSideGw(); }
if (!on) slide(nav, "nav"); else { sideGwRead(); renderSideGw(); }
navTopGo(navTopOn(), false);
sideWidth();
renderSideToggle();
+4
View File
@@ -4620,6 +4620,7 @@ const I18N = {
"npm didn't answer: {error}": "npm 没有响应:{error}",
"Couldn't read the folder's README: {error}": "无法读取该文件夹的 README:{error}",
"More in Plugins": "插件中还有更多",
"More pages": "更多",
"Subscriptions magpie doesn't sign in to itself: install a plugin for one in the Plugins tab": "magpie 未内置的订阅:在「插件」页安装对应插件即可",
"Agents magpie has no setup of its own for: install a plugin for one in the Plugins tab, and it is listed here": "magpie 未内置的 Agent:在「插件」页安装对应插件,它就会出现在这里",
"look for a plugin": "找找插件",
@@ -9525,6 +9526,7 @@ const I18N = {
"npm didn't answer: {error}": "npm 沒有回應:{error}",
"Couldn't read the folder's README: {error}": "無法讀取該資料夾的 README:{error}",
"More in Plugins": "外掛中還有更多",
"More pages": "更多",
"Subscriptions magpie doesn't sign in to itself: install a plugin for one in the Plugins tab": "magpie 未內建的訂閱:在「外掛」頁安裝對應外掛即可",
"Agents magpie has no setup of its own for: install a plugin for one in the Plugins tab, and it is listed here": "magpie 未內建的 Agent:在「外掛」頁安裝對應外掛,它就會出現在這裡",
"look for a plugin": "找找外掛",
@@ -14451,6 +14453,7 @@ const I18N = {
"npm didn't answer: {error}": "npm から応答がありません:{error}",
"Couldn't read the folder's README: {error}": "フォルダの README を読めませんでした:{error}",
"More in Plugins": "プラグインにもっとあります",
"More pages": "その他",
"Subscriptions magpie doesn't sign in to itself: install a plugin for one in the Plugins tab": "magpie が自分ではサインインしないサブスクリプション:「プラグイン」タブで対応するプラグインをインストールしてください",
"Agents magpie has no setup of its own for: install a plugin for one in the Plugins tab, and it is listed here": "magpie に設定が組み込まれていないエージェント:「プラグイン」タブで対応するプラグインをインストールすると、ここに表示されます",
"look for a plugin": "プラグインを探す",
@@ -19391,6 +19394,7 @@ const I18N = {
"npm didn't answer: {error}": "npm hat nicht geantwortet: {error}",
"Couldn't read the folder's README: {error}": "README des Ordners konnte nicht gelesen werden: {error}",
"More in Plugins": "Mehr unter Erweiterungen",
"More pages": "Mehr",
"Subscriptions magpie doesn't sign in to itself: install a plugin for one in the Plugins tab": "Abos, bei denen sich magpie nicht selbst anmeldet: Installieren Sie dafür eine Erweiterung im Tab Erweiterungen",
"Agents magpie has no setup of its own for: install a plugin for one in the Plugins tab, and it is listed here": "Agents, für die magpie keine eigene Einrichtung hat: Installieren Sie dafür eine Erweiterung im Tab Erweiterungen, dann erscheint er hier",
"look for a plugin": "nach einer Erweiterung suchen",
+53
View File
@@ -0,0 +1,53 @@
// magpie web on a phone (app.js phoneWeb): the pages are a tab bar at the
// window's foot, as an iPhone app's (app.css). Five fit; with more, the
// fifth is More, a menu of the rest, marked while one of them is open
// (geraldpppppp on X: Agents and the Library were past the edge of a
// strip that scrolled sideways, and nothing said it did). Imported by
// layoutNav the first time the page is a phone's.
const nav = $("#nav");
const more = el("button", "nav-more");
more.type = "button";
more.setAttribute("aria-haspopup", "menu");
more.setAttribute("aria-expanded", "false");
more.innerHTML = '<svg class="nav-ic" viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><g fill="currentColor"><circle cx="4.5" cy="10" r="1.5"/><circle cx="10" cy="10" r="1.5"/><circle cx="15.5" cy="10" r="1.5"/></g></svg>';
const word = el("span");
more.append(word);
let over = [];
function fit() {
for (const b of nav.querySelectorAll(".tb-over")) b.classList.remove("tb-over");
// what the bar has: the pages shown, gateway mode's, a plugin's and
// the switched-off ones left out (app.js navHides, app.css)
const pages = phoneWeb() ? [...nav.querySelectorAll(":scope > button[data-view]")].filter((b) => getComputedStyle(b).display !== "none") : [];
over = pages.length > 5 ? pages.slice(4) : [];
for (const b of over) b.classList.add("tb-over");
if (!over.length) more.remove();
else if (nav.lastElementChild !== more) nav.append(more);
// "More" alone is the heatmap's 多; the tab's is its own word
const said = t("More pages");
word.textContent = said === "More pages" ? "More" : said;
more.setAttribute("aria-label", said);
const open = over.find((b) => b.classList.contains("on"));
more.classList.toggle("on", !!open);
if (open) more.setAttribute("aria-current", "page"); else more.removeAttribute("aria-current");
more.classList.toggle("has-dot", over.some((b) => b.classList.contains("has-dot")));
watch.takeRecords(); // its own changes aren't news
}
const watch = new MutationObserver(fit);
// a page shown or left out, the one open, a dot, a language's words
watch.observe(nav, { childList: true, attributes: true, subtree: true, attributeFilter: ["class", "hidden", "data-replaced"] });
matchMedia("(max-width: 760px), (pointer: coarse) and (max-width: 1024px)").addEventListener?.("change", fit);
more.onclick = () => {
if (more.classList.contains("open")) return closeProtoMenu();
const open = over.find((b) => b.classList.contains("on"));
openProtoMenu(more, over.map((b) => ({ v: b.dataset.view, name: b.textContent.trim(), literalName: true })), open?.dataset.view ?? "",
(v) => over.find((b) => b.dataset.view === v)?.click(), "More pages", "nav-more-menu", "right");
// each page with its tab's mark, as an iPhone's More list has
const box = document.querySelector(".nav-more-menu");
box?.querySelectorAll(".pm-item").forEach((item, i) => {
const ic = over[i]?.querySelector(".nav-ic");
if (ic) item.querySelector(".pm-words").before(ic.cloneNode(true));
});
};
fit();
@@ -106,11 +106,18 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.mouse.wheel(0, 120);
await page.waitForTimeout(60);
}
let now = await seen();
// and back up until the whole of Add is in the view: a press on
// its middle, with its top still under the header, can land on
// the header in WebKit
const whole = () => add.evaluate((btn) => {
const r = btn.getBoundingClientRect(), v = btn.closest("main.view").getBoundingClientRect();
return r.top >= v.top && r.bottom <= v.bottom;
});
let now = (await whole()) && (await seen());
for (let i = 0; i < 80 && !now; i++) {
await page.mouse.wheel(0, -120);
await page.mouse.wheel(0, -60);
await page.waitForTimeout(60);
now = await seen();
now = (await whole()) && (await seen());
}
assert.ok(now, "Add is under the pointer's reach to be clicked");
await page.mouse.click(now.x, now.y);
+2 -1
View File
@@ -90,7 +90,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// a click adds cards under the ones shown and moves nothing (the
// button brought into view by the wheel, as a reader would)
await box.hover();
while (await button.evaluate((b) => b.getBoundingClientRect().bottom > innerHeight)) await page.mouse.wheel(0, 600);
// (the page ends above a phone's tab bar, so its own foot, not the window's)
while (await button.evaluate((b) => b.getBoundingClientRect().bottom > b.closest("main.view").getBoundingClientRect().bottom)) await page.mouse.wheel(0, 600);
// the wheel's last scroll told the page, a frame on
await page.evaluate(() => new Promise((ok) => requestAnimationFrame(() => requestAnimationFrame(ok))));
const first = cards.nth(59);
+5 -5
View File
@@ -13,7 +13,7 @@ const path = require("node:path");
const { execFileSync } = require("node:child_process");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { reach } = require("./reader.cjs");
const { reach, openPage } = require("./reader.cjs");
const { PNG } = require("playwright-core/lib/utilsBundle");
const assets = path.resolve(__dirname, "../assets");
@@ -133,10 +133,10 @@ async function open(browser, lang, width, { original = false, touch = true, open
}
async function go(page, view) {
// Playwright scrolls each real navigation button into sight before clicking;
// this exercises the phone's horizontal navigation strip too.
await page.locator(view === "settings" ? "#prefs" : `#nav [data-view="${view}"]`).click();
await page.locator(`#view-${view}`).waitFor();
// the page's tab, or on a phone's tab bar More and its row for a page
// past the fifth (phonetabs.js)
if (view === "settings") await page.locator("#prefs").click();
await (view === "settings" ? page.locator(`#view-${view}`).waitFor() : openPage(page, view));
if (view === "library") await page.locator("#view-library .lib-more:not(:disabled)").waitFor();
if (view === "plugins") await page.locator("#view-plugins .pm-find").waitFor();
if (view === "usage") {
@@ -13,6 +13,7 @@
// is written. Every language, at a wide and a narrow window.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const { openPage } = require("./reader.cjs");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
@@ -113,7 +114,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the groups tab is the sidebar's; the header's row reaches them from Routing
const tab = page.locator('#nav button[data-view="groups"]');
if (await tab.isVisible()) await tab.click();
else { await page.locator('#nav button[data-view="routing"]').click(); await page.locator("#rtToGroups").click(); }
else { await openPage(page, "routing"); await page.locator("#rtToGroups").click(); }
await picked(page.locator(".rt-gnames .opt.on"), await tr("Off"));
assert.deepEqual(posts, [], "nothing is written");
assert.deepEqual(errors, []);
+2 -2
View File
@@ -168,10 +168,10 @@ test("compat.js is the first of the page's own scripts", async () => {
// panelarrange.js when its Allowances tab's Arrange is, modelfind.js
// when Model settings draws many models, agentsmanager.js when the
// Agents page's Manage is pressed, agentsuffix.js when an agent's Details
// open;
// open, phonetabs.js when magpie web is laid out for a phone;
// the checks above
// still read them
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js", "pageshare.js", "panelfirst.js", "panelarrange.js", "modelfind.js", "agentsmanager.js", "agentsuffix.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js", "pageshare.js", "panelfirst.js", "panelarrange.js", "modelfind.js", "agentsmanager.js", "agentsuffix.js", "phonetabs.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
});
test("the styles hold up in Safari 15.0", async () => {
@@ -9,6 +9,7 @@
// 390 and 430 in English, Chromium and WebKit; no backend, the API is
// faked. MAGPIE_ASSETS runs it on older assets.
const assert = require("node:assert/strict");
const { openPage } = require("./reader.cjs");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
@@ -182,7 +183,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
if (process.env.ARTIFACT_DIR) await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-${view}-${sub ?? ""}.png`) });
}
// the Requests table, wider than the phone, scrolls in its own box
await page.locator("#nav [data-view=usage]").click();
await openPage(page, "usage");
await page.locator("#usageTab .opt").nth(1).click();
assert(await page.locator("#ledWrap").evaluate((e) => e.scrollWidth > e.clientWidth + 100), "the table is wider than the phone");
assert.deepEqual(bad, [], "views wider than the phone, or a band held at its foot");
+158
View File
@@ -0,0 +1,158 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// magpie web on a phone (geraldpppppp on X: 优化移动端 UI,为什么看不到agent
// 以及资源库之类的那些入口?). The pages were a strip that scrolled sideways
// with nothing saying it did, and Agents and the Library lay past its edge.
// Now they are a tab bar at the window's foot, as an iPhone app's: five tabs,
// the fifth More when more pages show, its menu the rest with their icons.
// Every page is a tap or two away, the bar covers no part of a page or its
// status line, and nothing scrolls sideways. In gateway mode (Agents left
// out) and with every page; in every language; at 390px.
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 assets = path.resolve(__dirname, "../assets");
const LANGS = { en: "More", zh: "更多", "zh-TW": "更多", ja: "その他", de: "Mehr" };
function serve(lang, gateway) {
const providers = { providers: [], presets: [], excluded: [], gateway: { running: true, window: true } };
const state = { agents: [], profiles: [], settings: { lang, theme: "light", redact: true } };
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:true${gateway ? ",gateway:true" : ""}};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json(state);
if (url.pathname === "/api/providers") return json(providers);
if (url.pathname === "/api/settings") return json({ lang, theme: "light", web: true, gatewayOn: gateway, gatewayWhy: gateway ? "no-agents" : "" });
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/plugins/market") return json({ listings: [], state: { bun: true, bunVersion: "1.3.0", plugins: [], picker: false } });
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)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
async function open(browser, lang, gateway, view) {
const context = await browser.newContext({ viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, hasTouch: true, isMobile: browser.browserType().name() === "chromium", reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.errors = [];
page.on("pageerror", (e) => page.errors.push(e.message));
await page.route("**/*", serve(lang, gateway));
await page.goto("http://magpie.test/" + (view ? "?view=" + view : ""));
await page.waitForSelector("#nav", { state: "visible" });
await page.waitForFunction(() => document.querySelector("#nav .nav-more") || document.querySelectorAll("#nav > button[data-view]").length);
await page.waitForTimeout(300);
return page;
}
// the tabs the bar shows, in order, each with its box
const tabs = (page) => page.$$eval("#nav > button", (bs) => bs.filter((b) => {
const r = b.getBoundingClientRect();
return getComputedStyle(b).display !== "none" && r.width > 0 && r.height > 0;
}).map((b) => {
const r = b.getBoundingClientRect();
return { view: b.dataset.view || "more", on: b.classList.contains("on"), x: r.x, y: r.y, w: r.width, h: r.height, label: b.textContent.trim() };
}));
// every page the reader may open: the nav's buttons that a phone's bar or its More list carries
const pages = (page) => page.$$eval("#nav > button[data-view]", (bs) => bs.filter((b) => !b.hidden && !b.dataset.replaced && b.dataset.view !== "groups" && getComputedStyle(b).display !== "none" || b.classList.contains("tb-over")).map((b) => b.dataset.view));
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const [lang, moreWord] of Object.entries(LANGS)) {
for (const gateway of [false, true]) {
test(`${engine} ${lang}${gateway ? " gateway mode" : ""}: every page is reachable from the tab bar at 390px`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await open(browser, lang, gateway, gateway ? "providers" : "agents");
const all = await pages(page);
assert.ok(all.includes("library"), "the Library is a page here");
assert.equal(all.includes("agents"), !gateway, "Agents shows unless gateway mode leaves it out");
const bar = await tabs(page);
assert.equal(bar.length, 5, "five tabs: " + JSON.stringify(bar.map((b) => b.view)));
assert.equal(bar[4].view, "more", "the fifth is More");
assert.equal(bar[4].label, moreWord, "More in this language");
const vw = await page.evaluate(() => innerWidth), vh = await page.evaluate(() => innerHeight);
for (const b of bar) {
assert.ok(b.x >= 0 && b.x + b.w <= vw + 0.5, b.view + " is inside the window: " + JSON.stringify(b));
assert.ok(b.y + b.h <= vh + 0.5 && b.y > vh - 100, b.view + " sits at the window's foot: " + JSON.stringify(b));
assert.ok(b.h >= 44, b.view + " is a touch target");
}
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "nothing scrolls sideways");
const onBar = bar.slice(0, 4).map((b) => b.view);
// the bar's own pages open with a tap
for (const v of onBar) {
await page.locator(`#nav > button[data-view="${v}"]`).tap();
await page.waitForSelector("#view-" + v, { state: "visible" });
}
// the rest are in More's list, each with its icon, and open from it
const rest = all.filter((v) => !onBar.includes(v));
assert.ok(rest.length >= 1);
for (const v of rest) {
await page.locator("#nav .nav-more").tap();
const menu = page.locator(".nav-more-menu");
await menu.waitFor({ state: "visible" });
const items = await menu.locator(".pm-item").count();
assert.equal(items, rest.length, "More lists every page the bar hasn't");
assert.equal(await menu.locator(".pm-item .nav-ic").count(), rest.length, "each with its tab's icon");
const mb = await menu.boundingBox(), more = await page.locator("#nav .nav-more").boundingBox();
assert.ok(mb.y + mb.height <= more.y + 1, "the menu opens above the bar");
assert.ok(mb.x >= 0 && mb.x + mb.width <= vw + 0.5, "inside the window");
await menu.locator(".pm-item").nth(rest.indexOf(v)).tap();
await page.waitForSelector("#view-" + v, { state: "visible" });
assert.equal(await page.locator(".nav-more-menu").count(), 0, "the menu closes");
const now = await tabs(page);
assert.ok(now.find((b) => b.view === "more").on, "More is marked while " + v + " is open");
assert.ok(!now.slice(0, 4).some((b) => b.on), "no other tab is marked");
}
// back on a tab of the bar, More lets go of its mark
await page.locator(`#nav > button[data-view="${onBar[0]}"]`).tap();
await page.waitForSelector("#view-" + onBar[0], { state: "visible" });
assert.equal((await tabs(page)).find((b) => b.view === "more").on, false);
assert.deepEqual(page.errors, []);
});
}
}
test(`${engine}: the bar covers no part of a page or its status line`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await open(browser, "en", false, "settings");
const bar = await page.locator("#nav").boundingBox();
// the page's foot scrolls clear of the bar
const last = await page.evaluate(async () => {
const v = document.querySelector(".view:not([hidden])");
v.scrollTop = v.scrollHeight;
await new Promise((r) => setTimeout(r, 200));
return Math.min(v.getBoundingClientRect().bottom, Math.max(...[...v.children].filter((e) => e.getBoundingClientRect().height > 0).map((e) => e.getBoundingClientRect().bottom)));
});
assert.ok(last <= bar.y + 1, `the page's last line (${last}) ends above the bar (${bar.y})`);
// a status message sits above it
await page.evaluate(() => { const s = document.querySelector(".foot .status") || document.querySelector(".status"); s.textContent = "Saved"; });
await page.waitForTimeout(100);
const st = await page.evaluate(() => { const s = document.querySelector(".foot .status") || document.querySelector(".status"); const r = s.getBoundingClientRect(); return { y: r.y, h: r.height, shown: getComputedStyle(s).display !== "none" }; });
if (st.shown && st.h > 0) assert.ok(st.y + st.h <= bar.y + 1, "the status line is above the bar: " + JSON.stringify(st));
assert.deepEqual(page.errors, []);
});
test(`${engine}: a desktop browser keeps the header's tabs, with no More`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const context = await browser.newContext({ viewport: { width: 1280, height: 800 }, reducedMotion: "reduce" });
const page = await context.newPage();
await page.route("**/*", serve("en", false));
await page.goto("http://magpie.test/?view=providers");
await page.waitForSelector("#view-providers", { state: "visible" });
await page.waitForTimeout(300);
assert.equal(await page.locator("#nav .nav-more").count(), 0);
assert.equal(await page.locator("#nav .tb-over").count(), 0);
const nav = await page.locator("#nav").boundingBox();
assert.ok(nav.y < 200, "the tabs are at the top: " + JSON.stringify(nav));
});
}
+11 -8
View File
@@ -1,7 +1,7 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// magpie web on a phone (jiakun_zhao on X: 移动端的显示效果非常不友好,甚至滚动
//会抽搐). The header is two rows, the magpie and the icons over the tabs at
// their size, sliding sideways, the one open in sight; a setting's control
//会抽搐). The header is the magpie and the icons, the tabs a bar at the
// window's foot (geraldpppppp on X), the one open marked in sight; a setting's control
// too wide beside its name goes under it rather than cut the name; iOS isn't
// let zoom into a field it focuses. And a flick's scroll, which goes on
// after the finger is lifted with no touch event, is the reader's: the page
@@ -89,15 +89,18 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
// the header: two rows, the tabs at their size, the one open in sight
// the header: the magpie and the icons; the tabs a bar at the foot, as
// an iPhone app's, each its mark over its word (phone-tabs.test.cjs)
let page = await open(browser, phone, true, "plugins");
const [top, nav, actions, brand] = [await box(page, ".top"), await box(page, "#nav"), await box(page, ".top .actions"), await box(page, ".top .brand")];
const vh = await page.evaluate(() => innerHeight);
assert.ok(nav.y >= actions.y + actions.height - 1 && nav.y >= brand.y + brand.height - 1, "the tabs are under the magpie and the icons");
assert.ok(nav.width >= top.width - 30, `the tabs take the row: ${nav.width} of ${top.width}`);
const tab = await page.locator("#nav button").first().evaluate((b) => [parseFloat(getComputedStyle(b).fontSize), b.getBoundingClientRect().height]);
assert.ok(tab[0] >= 13 && tab[1] >= 30, `a tab is readable and tappable: ${tab}`);
const on = await box(page, "#nav button.on");
assert.ok(on.x >= nav.x - 1 && on.x + on.width <= nav.x + nav.width + 1, "Plugins, open, is in sight");
assert.ok(Math.abs(nav.y + nav.height - vh) <= 1, `the tabs are at the window's foot: ${nav.y + nav.height} of ${vh}`);
assert.ok(nav.width >= top.width - 1, `the tabs take the window's width: ${nav.width} of ${top.width}`);
const tab = await page.locator("#nav button").first().evaluate((b) => [parseFloat(getComputedStyle(b).fontSize), b.getBoundingClientRect().height, getComputedStyle(b.querySelector(".nav-ic")).display]);
assert.ok(tab[0] >= 10 && tab[1] >= 44 && tab[2] !== "none", `a tab is readable and tappable, with its mark: ${tab}`);
const on = await box(page, "#nav > button.on:not(.tb-over)"); // a page under More hides its own tab
assert.ok(on && on.x >= nav.x - 1 && on.x + on.width <= nav.x + nav.width + 1, "Plugins, open, is marked in sight (More while it is past the fifth)");
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth), 390, "nothing runs off the side");
assert.equal(await page.locator(".top").getAttribute("class"), "top", "none of the narrow window's squeezing");
assert.match(await page.locator('meta[name="viewport"]').getAttribute("content"), /maximum-scale=1/, "iOS doesn't zoom into a field");
+15 -1
View File
@@ -320,4 +320,18 @@ async function closeRequest(page) {
await page.locator("#ledReqPane").waitFor({ state: "hidden" });
}
module.exports = { openRequest, closeRequest, provPrefsProviders, openProvPrefs, inEditor, settled, inView, reach, wheelTo, click, openPart, watchSettingsReads, settingsDrawn, agentRow, openAgentSettings, pickItem };
// openPage opens a page from the navigation as the reader does: its tab, or,
// on a phone's tab bar where it is past the fifth, More and then its row in
// More's menu (phonetabs.js).
async function openPage(page, view) {
const tab = page.locator(`#nav [data-view="${view}"]`);
if (await tab.isVisible()) await tab.click();
else {
await page.locator("#nav .nav-more").click();
const name = (await tab.textContent()).trim();
await page.locator(".nav-more-menu .pm-item", { hasText: name }).first().click();
}
await page.locator(`#view-${view}`).waitFor();
}
module.exports = { openPage, openRequest, closeRequest, provPrefsProviders, openProvPrefs, inEditor, settled, inView, reach, wheelTo, click, openPart, watchSettingsReads, settingsDrawn, agentRow, openAgentSettings, pickItem };
+2 -1
View File
@@ -8,6 +8,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { openPage } = require("./reader.cjs");
const assets = path.resolve(__dirname, "../assets");
const iso = (ms) => new Date(ms).toISOString();
@@ -75,7 +76,7 @@ for (const engine of engines) for (const lang of langs) for (const width of widt
// another view first, the request already under way
await page.goto("http://magpie.test/?view=agents");
await page.waitForTimeout(800);
await page.locator('#nav button[data-view="routing"]').click();
await openPage(page, "routing");
await page.waitForFunction(() => document.querySelector(".rt-sky .pkt.held"), null, { timeout: 6000 });
await page.waitForTimeout(400);
const atSeat = async (when) => {