gui: Settings › General › Sidebar pages leaves pages out of the sidebar for this browser (youimark on X)

Gateway mode hides Agents only for magpie web without agents, and the Library
only goes with its built-in plugin. A docker gateway asked to close both. The
new row is a multi-tick menu of the sidebar's pages (Providers stays), kept in
localStorage magpie.navHidden; navHides and offView read it beside gateway mode
and the built-in plugins, and start.js opens Providers when Agents is out.

Main's TestCoreScriptBudget was already 351 bytes over at origin/main
(1,534,153 > 1,533,802); this commit cuts comments in app.js to land at
1,533,596, under it, with no raise.

Run, on wsl-run (xiaomi-gpu), chromium + webkit: nav-pages-hidden 2 pass;
broken by hand (navHides without the new term) 2 red. settings-general went
red on the first draft (the row was 56 tall, the others 51, the button in a
wrapper) and passes now. i18n-keys, i18n-en-no-cjk, last-page, gateway-mode,
sidebar, phone-tabs 0 fail. go test -tags nogui -run TestCoreScriptBudget ok.
Red the same on an origin/main copy (7 and 14 fails, not from this change):
builtins webkit, side-toggle (both engines) and settings-search ("searching
posts nothing": /api/update/using); filed with this push.
Not tried: a real docker deployment, the full GUI suite, the Mac and Linux
apps, sidebar-glide (3 fails under load, base not compared).
This commit is contained in:
yetone
2026-11-11 17:29:38 +08:00
parent 772d502ffd
commit 22f2759d71
7 changed files with 130 additions and 21 deletions
File diff suppressed because one or more lines are too long
+7 -19
View File
@@ -19988,6 +19988,7 @@ function renderSettings() {
$("#birdSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.noBird ? "off" : "on", (v) => savePrefs({ ...keep, noBird: v === "off" })));
renderLangPick(s, keep);
renderGatewayMode(s);
window.renderNavPages ? renderNavPages() : import("./navpages.js").then(() => renderNavPages(), () => {});
// a browser tab has its own zoom, and magpie leaves it to it
$("#textSizeRow").hidden = web;
// the keys that do it too, in the choices' tooltip
@@ -20217,9 +20218,6 @@ function renderSettings() {
setSetTab(setTab);
}
// Gateway mode's switch, in magpie web alone (gatewaymode.go): Automatic
// (on with --gateway or no agents here), On or Off. Turned, the tabs follow
// at once.
function renderGatewayMode(s) {
$("#gatewayModeRow").hidden = !web;
if (!web) return;
@@ -23193,9 +23191,7 @@ async function show(v) {
jumpNext = false;
// a built-in page a plugin's page replaces (magpie.page.replaces) opens that
v = magpie.replacing?.(v) || v;
// a page gateway mode leaves out (a link to it, an address kept) opens Providers
if (gatewayMode && GATEWAY_HIDES.includes(v)) v = "providers";
// and one a built-in plugin switched off has, offView
v = offView(v);
if (v !== view) {
if (v === "plugins" && pluginUpdates) window.pluginTabTo?.("installed");
@@ -23223,7 +23219,6 @@ async function show(v) {
view = v;
renderBack();
window.hideAccounts?.page();
// the page the reader leaves is the one the window opens on next (keptView)
if (mode === "window") { try { localStorage.setItem("magpie.lastView", v); } catch { /* not kept */ } }
const title = pageName(v);
$("#pageTitle").dataset.en = title;
@@ -23289,23 +23284,18 @@ function setGatewayMode(on) {
}
// offView: v, or the page a plugin switched off sends it to (yyddbds)
function offView(v) {
if (!featureHides($(`#nav button[data-view="${v}"]`))) return v;
if (v === "groups" && !featureHides($('#nav button[data-view="routing"]'))) return "routing";
return gatewayMode ? "providers" : "agents";
const gone = (x) => featureHides($(`#nav button[data-view="${x}"]`)) || navMine().includes(x);
if (!gone(v)) return v;
if (v === "groups" && !gone("routing")) return "routing";
return gatewayMode || gone("agents") ? "providers" : "agents";
}
// navHides leaves out the tabs of the pages gateway mode or a built-in
// plugin switched off leaves out
const navMine = () => { try { return JSON.parse(localStorage.getItem("magpie.navHidden") || "[]"); } catch { return []; } }; // navpages.js
function navHides() {
if (mode !== "window") return;
for (const b of $("#nav").querySelectorAll("button[data-view]")) b.hidden = (gatewayMode && GATEWAY_HIDES.includes(b.dataset.view)) || featureHides(b);
for (const b of $("#nav").querySelectorAll("button[data-view]")) b.hidden = (gatewayMode && GATEWAY_HIDES.includes(b.dataset.view)) || featureHides(b) || navMine().includes(b.dataset.view);
}
// applyFeatures takes the built-in plugins' state from a read of the
// settings, or a switch on Plugins › Built-in:
// what is off leaves the window, and the page open, if it went, gives way
// to Agents (Providers in gateway mode)
function applyFeatures(list) {
if (!Array.isArray(list)) return;
// each plugin's settings to its code in the page (kernel.js)
for (const f of list) if (f.schema) magpie.configure(f.id, f.config);
const off = new Set(list.filter((f) => !f.on).map((f) => f.id));
if (off.size === featuresOff.size && [...off].every((id) => featuresOff.has(id))) return;
@@ -23320,8 +23310,6 @@ function applyFeatures(list) {
setSetTab(setTab);
navSubs();
}
// Plugins › Built-in: a row and a switch each (plugins.yml, builtins.go);
// one in use can't be switched off; its settings under it (ui.form)
function renderBuiltins(box, list, done) {
const broken = list.find((f) => f.broken)?.broken;
const rows = list.flatMap((f) => {
+8
View File
@@ -781,6 +781,8 @@ const I18N = {
"Drag to put them in the order {agent} lists them; new models go last": "拖动排列 {agent} 列表中的顺序;新模型排在最后",
"Drag to put them in the order magpie hands them to {agent}; new models go last": "拖动排列 magpie 交给 {agent} 的模型顺序;新模型排在最后",
"{n} hidden": "已隐藏 {n} 个",
"Sidebar pages": "侧边栏页面",
"All shown": "全部显示",
"{n} at 0": "{n} 个为 0",
"Fold the ones at 0": "收起为 0 的",
"Nothing left here: every window used up, or a balance of 0": "已没有剩余额度的账号和密钥:每个额度窗口都已用完,或余额为 0",
@@ -5852,6 +5854,8 @@ const I18N = {
"Drag to put them in the order {agent} lists them; new models go last": "拖動排列 {agent} 列表中的順序;新模型排在最後",
"Drag to put them in the order magpie hands them to {agent}; new models go last": "拖動排列 magpie 交給 {agent} 的模型順序;新模型排在最後",
"{n} hidden": "已隱藏 {n} 個",
"Sidebar pages": "側邊欄頁面",
"All shown": "全部顯示",
"{n} at 0": "{n} 個為 0",
"Fold the ones at 0": "收起為 0 的",
"Nothing left here: every window used up, or a balance of 0": "已沒有剩餘額度的帳號和金鑰:每個額度時段都已用完,或餘額為 0",
@@ -10888,6 +10892,8 @@ const I18N = {
"Drag to put them in the order {agent} lists them; new models go last": "ドラッグで {agent} の一覧の並び順を変更。新しいモデルは末尾に追加されます",
"Drag to put them in the order magpie hands them to {agent}; new models go last": "ドラッグで magpie が {agent} に渡すモデルの並び順を変更。新しいモデルは末尾に追加されます",
"{n} hidden": "{n} 件非表示",
"Sidebar pages": "サイドバーのページ",
"All shown": "すべて表示",
"{n} at 0": "{n} 件が 0",
"Fold the ones at 0": "0 のものをたたむ",
"Nothing left here: every window used up, or a balance of 0": "残りがないアカウントとキー:すべてのウィンドウを使い切ったか、残高が 0",
@@ -15942,6 +15948,8 @@ const I18N = {
"Drag to put them in the order {agent} lists them; new models go last": "Ziehen, um die Reihenfolge in {agent} festzulegen; neue Modelle kommen ans Ende",
"Drag to put them in the order magpie hands them to {agent}; new models go last": "Ziehen, um die Reihenfolge festzulegen, in der magpie {agent} die Modelle übergibt; neue Modelle kommen ans Ende",
"{n} hidden": "{n} ausgeblendet",
"Sidebar pages": "Seiten in der Seitenleiste",
"All shown": "Alle sichtbar",
"{n} at 0": "{n} bei 0",
"Fold the ones at 0": "Die bei 0 einklappen",
"Nothing left here: every window used up, or a balance of 0": "Konten und Schlüssel ohne Rest: jedes Zeitfenster aufgebraucht oder ein Guthaben von 0",
+3
View File
@@ -193,6 +193,9 @@
<div class="who"><div class="name" data-t>Gateway mode</div><div class="sub" id="gatewayModeSub"></div></div>
<div id="gatewayModeSegs"></div>
</div>
<div class="row pref" id="navPagesRow" hidden>
<div class="who"><div class="name" data-t>Sidebar pages</div></div>
</div>
<div class="row pref app-only" id="textSizeRow">
<div class="who"><div class="name" data-t>Text size</div></div>
<div id="textSizeSegs"></div>
+36
View File
@@ -0,0 +1,36 @@
// Settings › General › Sidebar pages (youimark on X: a docker gateway has
// no use for Agents or Library): which pages this browser leaves out of
// the sidebar, kept in localStorage magpie.navHidden as this reader's own
// (navMine in app.js reads it). app.js imports this when Settings draws,
// so it weighs nothing on the core.
window.renderNavPages = function () {
const row = $("#navPagesRow");
if (!row) return;
const pages = [...$("#nav").querySelectorAll("button[data-view]")]
.filter((b) => b.dataset.view !== "providers" && !(gatewayMode && GATEWAY_HIDES.includes(b.dataset.view)) && !featureHides(b))
.map((b) => ({ v: b.dataset.view, name: b.querySelector("[data-t]")?.dataset.en || b.textContent.trim() }));
row.hidden = mode !== "window" || !pages.length;
if (row.hidden) return;
const mine = navMine();
const n = pages.filter((p) => mine.includes(p.v)).length;
let b = row.querySelector(".nav-pages-pick");
if (!b) {
b = el("button", "sess-pick pref-pick nav-pages-pick");
b.type = "button";
menuOf(b);
b.onclick = () => {
const now = navMine();
openProtoMenu(b, pages.map((p) => ({ v: p.v, name: p.name })), pages.map((p) => p.v).filter((v) => !now.includes(v)), (shown) => {
const keep = now.filter((v) => !pages.some((p) => p.v === v));
const hide = [...keep, ...pages.map((p) => p.v).filter((v) => !shown.includes(v))];
try { localStorage.setItem("magpie.navHidden", JSON.stringify(hide)); } catch { /* not kept */ }
navHides();
if (offView(view) !== view) show(offView(view));
else if (!sideNav()) slide($("#nav"), "nav");
window.renderNavPages();
}, "Sidebar pages", "", "left", true);
};
row.append(b);
}
b.textContent = n ? t("{n} hidden", { n }) : t("All shown");
};
+1 -1
View File
@@ -17,7 +17,7 @@ function keptView() {
try { v = localStorage.getItem("magpie.lastView") || ""; } catch { /* none kept */ }
return OPEN_VIEWS.includes(v) ? v : ""; // one gateway mode leaves out, show() makes Providers
}
const firstView = mode === "window" ? keptView() : "";
const firstView = mode === "window" ? keptView() || (navMine().includes("agents") ? "providers" : "") : "";
// from the tray panel's More in Plugins (q): Discover, once show() picked the tab (#3579)
if (OPEN_VIEWS.includes(firstView)) show(firstView).then(() => view === "plugins" && params.has("q") && window.pluginQuery?.(params.get("q")));
else if (mode === "window" && !gatewayMode && !sideNav()) slide($("#nav"), "nav");
@@ -0,0 +1,74 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Settings › General › Sidebar pages (youimark on X: a docker gateway has no
// use for Agents or Library): the pages ticked off leave the sidebar, are
// kept for this browser (localStorage magpie.navHidden), and the window
// that would open on one opens Providers. Chromium and WebKit. No backend:
// the API is 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 assets = path.resolve(__dirname, "../assets");
const BASE = "http://magpie.test/";
function server({ web = false, gateway = false } = {}) {
return async (route) => {
const url = new URL(route.request().url());
const json = (d) => route.fulfill({ json: d });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"en",theme:"light",web:${web}${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({ agents: [], profiles: [], settings: { lang: "en", theme: "light" } });
if (url.pathname === "/api/settings") return json({ theme: "light", lang: "en", version: "0.1.400", gateway: "http://127.0.0.1:3425", web, gatewayOn: web && gateway, visionModels: [], imageGenModels: [], lanURLs: [] });
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
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: "" }); }
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: a page left out of the sidebar stays out, for this browser`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const context = await browser.newContext({ viewport: { width: 1100, height: 700 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server());
const hidden = () => page.evaluate(() => [...document.querySelectorAll("#nav button[data-view]")].filter((b) => b.hidden).map((b) => b.dataset.view));
await page.goto(BASE + "?view=settings");
await page.waitForSelector("#navPagesRow:not([hidden]) .nav-pages-pick");
assert.deepEqual(await hidden(), [], "all shown at first");
assert.match(await page.locator(".nav-pages-pick").innerText(), /All shown/);
await page.locator(".nav-pages-pick").click();
await page.locator(".pm-item", { hasText: /^Agents/ }).click();
await page.locator(".pm-item", { hasText: /^Library/ }).click();
await page.keyboard.press("Escape");
assert.deepEqual((await hidden()).sort(), ["agents", "library"]);
assert.match(await page.locator(".nav-pages-pick").innerText(), /2 hidden/);
// kept: a reload, and the window opening on Agents, gives way to Providers
await page.evaluate(() => localStorage.removeItem("magpie.lastView")); // as a window opened fresh
await page.goto(BASE);
await page.waitForSelector("#nav button.on");
assert.deepEqual((await hidden()).sort(), ["agents", "library"]);
assert.equal(await page.evaluate(() => document.querySelector("#nav button.on").dataset.view), "providers");
// and put back
await page.goto(BASE + "?view=settings");
await page.waitForSelector(".nav-pages-pick");
await page.locator(".nav-pages-pick").click();
await page.locator(".pm-item", { hasText: /^Agents/ }).click();
await page.keyboard.press("Escape");
assert.deepEqual(await hidden(), ["library"]);
assert.deepEqual(errors, []);
});
}