panel: the tray panel opens the window from its header icon only, no second "Open magpie" in its foot
yogurt36 on Discord: the menu bar panel had a button to open the window
at the top (the header's open-as-a-window icon, #open) and another at
the bottom (the foot's "Open magpie", #openMain). Both called
api("window/main"). The foot's button is gone; the foot keeps what is
its own: Profiles, the status line and Quit. The four "Open magpie"
strings it alone used are out of i18n.js (the tray menu's own
"Open magpie" lives in traymenu.go and is unchanged).
Test: internal/gui/tests/panel-open-once.test.cjs, both engines, all five
languages: the header's icon opens the window, the foot's buttons are
Profiles and Quit only, Quit worded in each language.
Run:
- panel-open-once, Chromium on mote: 5/5 ok; i18n-keys on mote: 4/4 ok.
- panel-open-once, WebKit on Linux (wsl-run, magpie-desktop): 5/5 ok.
WebKit does not launch on mote right now (several pw_run.sh from other
sessions hung for hours; a bare webkit.launch() times out at 80s).
- Broken by hand: the test against the old assets (origin/main
0a9d9702f) is red in every language, "the foot's buttons" lists
'openMain'.
- Every GUI file that loads the panel, its foot or i18n (146 files),
both engines, on Linux WSL: 2170 tests, 2107 ok, 63 red. The 12 red
files run alone at concurrency 1: 62 red with this change, 64 red at
0a9d9702f without it, the same tests (agent-panel-name-width,
redact-rule-edit, remote-magpie, text-size, tray-totals and others).
Filed: #4120 and #4400 (Linux WSL reds at main), #3407, #4398, #4203,
#4082, #3501, #1866.
At the pushed head (rebased on 30939aa84^): panel-open-once
Chromium + i18n-keys on mote 9/9 ok, WebKit on Linux 5/5 ok.
Not run: the whole GUI suite (mote and WSL both had other sessions'
full GUI suites running), the Go suite (no Go changed). Not tried in
the real tray panel on a Mac.
This commit is contained in:
@@ -202,7 +202,7 @@ body.window.mac .seg { top: calc(50% + 1px / var(--zoom, 1)); } /* 50% centres i
|
||||
.brand { display: flex; align-items: center; gap: 6px; font-weight: 600; letter-spacing: .01em; }
|
||||
body.window:not(.mac):not(.linux):not(.web) .brand { display: none; } /* Windows' title bar above already shows the icon and the name; a browser tab has no title bar of the app's */
|
||||
/* app.js removes these controls later; keep them out of the first paint too. */
|
||||
body.window :is(#open, #openMain, #quit),
|
||||
body.window :is(#open, #quit),
|
||||
body:not(.window.linux) #winclose { display: none; }
|
||||
/* Linux: the header is the title bar, so it closes the window too — round,
|
||||
as GNOME draws its close button, and set a little apart from the icons */
|
||||
|
||||
@@ -23546,13 +23546,12 @@ $("#sync").onclick = async () => {
|
||||
}
|
||||
};
|
||||
$("#open").onclick = () => api("window/main", {});
|
||||
$("#openMain").onclick = () => api("window/main", {});
|
||||
$("#quit").onclick = () => api("window/quit", {});
|
||||
$("#winclose").onclick = () => winRuntime.then((w) => w?.Window.Close()); // hides it: the tray stays
|
||||
$(".top").addEventListener("dblclick", (e) => {
|
||||
if (document.body.classList.contains("linux") && !e.target.closest("button, nav")) winRuntime.then((w) => w?.Window.ToggleMaximise());
|
||||
});
|
||||
if (mode === "window") { $("#open").remove(); $("#openMain").remove(); $("#quit").remove(); }
|
||||
if (mode === "window") { $("#open").remove(); $("#quit").remove(); }
|
||||
else { $("#nav").remove(); $("#side").remove(); }
|
||||
if (mode !== "window" || !document.body.classList.contains("linux")) $("#winclose").remove();
|
||||
|
||||
|
||||
@@ -496,7 +496,6 @@ const I18N = {
|
||||
"Usage refreshed": "用量已刷新",
|
||||
"Allowances refreshed": "额度已刷新",
|
||||
"Open as a window": "在窗口中打开",
|
||||
"Open magpie": "打开 magpie",
|
||||
"Quit": "退出",
|
||||
"Filter…": "筛选…",
|
||||
|
||||
@@ -4696,7 +4695,6 @@ const I18N = {
|
||||
"Usage refreshed": "用量已重新整理",
|
||||
"Allowances refreshed": "額度已重新整理",
|
||||
"Open as a window": "在視窗中開啟",
|
||||
"Open magpie": "開啟 magpie",
|
||||
"Quit": "退出",
|
||||
"Filter…": "篩選…",
|
||||
"No agents found": "沒有找到 Agent",
|
||||
@@ -8859,7 +8857,6 @@ const I18N = {
|
||||
"Usage refreshed": "使用量を更新しました",
|
||||
"Allowances refreshed": "利用枠を更新しました",
|
||||
"Open as a window": "ウィンドウで開く",
|
||||
"Open magpie": "magpie を開く",
|
||||
"Quit": "終了",
|
||||
"Filter…": "絞り込み…",
|
||||
"No agents found": "エージェントが見つかりません",
|
||||
@@ -13039,7 +13036,6 @@ const I18N = {
|
||||
"Usage refreshed": "Nutzung aktualisiert",
|
||||
"Allowances refreshed": "Kontingente aktualisiert",
|
||||
"Open as a window": "Als Fenster öffnen",
|
||||
"Open magpie": "magpie öffnen",
|
||||
"Quit": "Beenden",
|
||||
"Filter…": "Filtern…",
|
||||
"No agents found": "Keine Agenten gefunden",
|
||||
|
||||
@@ -455,7 +455,6 @@
|
||||
<span id="pqAge" class="pq-age" hidden></span>
|
||||
<span id="status" class="status" role="status" aria-atomic="true"></span>
|
||||
<span class="grow"></span>
|
||||
<button class="text" id="openMain" data-t>Open magpie</button>
|
||||
<button class="text" id="quit" data-t>Quit</button>
|
||||
</footer>
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// The tray panel opens the main window from one place: the header's
|
||||
// open-as-a-window icon. Its foot had an "Open magpie" button too, which did
|
||||
// the same (yogurt36 on Discord); the foot keeps Profiles, the status line
|
||||
// and Quit, which are its own.
|
||||
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");
|
||||
|
||||
function handler(lang, calls) {
|
||||
const state = { agents: [{ id: "codex", name: "codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
|
||||
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:"${lang}",theme:"light",web: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/window/main" || url.pathname === "/api/window/quit") { calls.push(url.pathname); return route.fulfill({ status: 204 }); }
|
||||
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
|
||||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
|
||||
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 route.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"]) {
|
||||
test(`${engine} ${lang}: the tray panel opens the window from one button`, 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: 380, height: 520 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(8000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
const calls = [];
|
||||
await page.route("**/*", handler(lang, calls));
|
||||
await page.goto("http://magpie.test/?mode=panel");
|
||||
await page.locator("#agents .row.agent").first().waitFor();
|
||||
|
||||
// the header's icon opens the window
|
||||
await page.locator(".top #open").click();
|
||||
for (let i = 0; i < 100 && !calls.length; i++) await page.waitForTimeout(50);
|
||||
assert.deepEqual(calls, ["/api/window/main"], "the header's icon opens the window");
|
||||
|
||||
// and the foot has no second way to it: Profiles and Quit are its only buttons
|
||||
const foot = await page.locator(".foot button").evaluateAll((bs) => bs.map((b) => b.id));
|
||||
assert.deepEqual(foot, ["profBtn", "quit"], "the foot's buttons");
|
||||
|
||||
// the foot keeps Quit, worded in the panel's language
|
||||
const quit = page.locator(".foot #quit");
|
||||
assert(await quit.isVisible(), "Quit stays in the foot");
|
||||
const want = { en: "Quit", zh: "退出", "zh-TW": "退出", ja: "終了", de: "Beenden" }[lang];
|
||||
assert.equal((await quit.textContent()).trim(), want);
|
||||
assert.equal(await page.locator("#openMain").count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user