plugins: Sign in on Installed takes the reader down to the plugin's sign-in

Sign in on Plugins › Installed (or a plugin card) opens the Providers add
sheet with the plugin's sign-in drawn at the sheet's foot, under every
tile. With many plugins the sheet is taller than the window and the reader
was left at its top, the sign-in out of sight: the click seemed to do
nothing (the owner, on magpie-intelligence-check).

The click now passes its event, so pluginSignIn scrolls the sign-in into
the middle of the view on purpose. In WebKit that alone didn't hold: the
list show() loads redraws the sheet after the scroll, WebKit pulls the view
to 0 while it is drawn, and inside the purpose window that 0 was taken as
the reader's, then backToReader returned there. arrived(v) ends the
purpose window once the scroll is done and keeps where it left the view as
where the reader is, so the redraw is put back to the sign-in.

Run:
- plugin-signin-scrolls.test.cjs (new; 24 signed-in plugins and one
  signed out, 900x560, Chromium and WebKit, en and zh): 6/6 pass. On
  origin/main 0/6 ("the page went down to the sign-in"); with the scroll
  but without arrived(), Chromium passes and WebKit fails 2/2.
- GUI: plugin*, *scroll*, *signin*, builtins: 1033 pass, 0 fail.
- go test -tags nogui ./internal/gui: ok (script budget, guard tests).
No Go changes.
This commit is contained in:
yetone
2026-10-19 16:05:09 +08:00
parent 224ea7d5be
commit 33dbdcc529
3 changed files with 108 additions and 4 deletions
+15 -2
View File
@@ -7235,13 +7235,19 @@ async function openPlugins(q) {
}
// pluginSignIn: a plugin's provider signed in to as every subscription is,
// in the Providers add sheet
async function pluginSignIn(id) {
// in the Providers add sheet. Its sign-in is drawn at the sheet's foot,
// under every tile: the click that asked for it, on the Plugins page, takes
// the reader there, with room around it for what the sign-in asks next.
async function pluginSignIn(id, e) {
const go = scrollOnPurpose(e, 3000);
if (!await show("providers")) return;
closeModal();
adding = true; editing = null; draft = null; presetQuery = "";
renderProviders();
startSignIn(id);
if (!go) return;
$("#addSheet .signing")?.scrollIntoView({ block: "center" });
arrived($("#view-providers"));
}
// openProvider: a provider opened in the Providers tab
@@ -22243,6 +22249,13 @@ function scrollOnPurpose(e, ms = 1000) {
readerScrolls(ms);
return true;
}
// arrived: a scroll asked for is done. Where it left v is where the reader
// is now, and what redraws after it (a load come in, which WebKit lets pull
// the view up while it is drawn) is put back there, not taken as theirs.
function arrived(v) {
readerLeaves(v);
purposeUntil = performance.now();
}
const SCROLL_KEYS = new Set(["PageUp", "PageDown", "Home", "End", "ArrowUp", "ArrowDown", " "]);
// Enter/Space can move focus to another field (opening a form, or validation).
// Reveal that field only when the keyboard action moved it out of sight.
+2 -2
View File
@@ -470,7 +470,7 @@
b.classList.add("go");
b.textContent = t("Sign in");
b.title = subs.length > 1 ? t("Sign in to {name}", { name: out.name }) : "";
b.onclick = (ev) => { ev.stopPropagation(); pluginSignIn(out.id); };
b.onclick = (ev) => { ev.stopPropagation(); pluginSignIn(out.id, ev); };
return b;
}
// an update out: the one button says so in place of Signed in or
@@ -1229,7 +1229,7 @@
// button names the one it signs in to and stays quiet
const out = subs.find((x) => !x.signedIn), some = subs.some((x) => x.signedIn);
const s = el("button", "text" + (here || some ? "" : " primary"), some ? t("Sign in to {name}", { name: out.name }) : t("Sign in"));
s.onclick = () => pluginSignIn(out.id);
s.onclick = (ev) => pluginSignIn(out.id, ev);
val.append(s);
}
// switched on again: a built-in it can carry is offered its way, in
@@ -0,0 +1,91 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Sign in on Plugins › Installed opens the Providers add sheet with that
// plugin's sign-in drawn at the sheet's foot, under every tile. With enough
// plugins the sheet is taller than the window, and the click left the reader
// at the top, the sign-in out of sight: the Sign in seemed to do nothing. The
// click that asked for it now takes the reader down to it.
// In Chromium and WebKit, en and zh; the API is faked here.
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 LAST = "opencode-zz-last-auth";
// 24 plugins signed in already, each with a tile in the sheet, and the one
// signed out last
const subs = [];
for (let i = 0; i < 24; i++) {
const n = String(i).padStart(2, "0");
subs.push({ id: `p${n}`, pid: `p${n}`, name: `Plugin ${n}`, icon: "generic", spec: `opencode-p${n}-auth`, signedIn: true, models: 2, methods: [{ type: "api", label: "API key" }] });
}
subs.push({ id: "zzlast", pid: "zzlast", name: "Last One", icon: "generic", spec: LAST, signedIn: false, models: 2, methods: [{ type: "api", label: "API key" }] });
function server(lang) {
const providers = { providers: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: subs };
const plugins = { plugins: subs.map((x) => ({ spec: x.spec, providers: [x.name], named: true, version: "0.1.0", moved: [] })), bun: true, bunVersion: "1.3.0", picker: false, mirror: 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:"${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({ agents: [], profiles: [], settings: { lang, theme: "light" } });
if (url.pathname === "/api/providers") return json(providers);
if (url.pathname === "/api/plugins") return json(plugins);
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/plugin-signin/prompt") return json({});
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: "" }); }
};
}
const words = { en: { signIn: "Sign in" }, zh: { signIn: "登录" } };
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": Sign in on Installed takes the reader to the plugin's sign-in", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const lang of ["en", "zh"]) {
await t.test(lang, async () => {
const ctx = await browser.newContext({ viewport: { width: 900, height: 560 }, reducedMotion: "reduce" });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.pluginTab", "installed"); } catch {} });
const page = await ctx.newPage();
t.after(() => ctx.close());
page.setDefaultTimeout(15000); // a busy machine takes seconds over a click
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang));
await page.goto("http://magpie.test/?view=plugins");
const row = page.locator("#view-plugins .pm-row", { hasText: LAST });
const button = row.locator("button", { hasText: new RegExp(`^${words[lang].signIn}$`) });
await button.waitFor();
// the reader scrolls down to the row: a scroll no reader made is put
// back, Playwright's own among them
await page.mouse.move(450, 300);
for (let i = 0; i < 40 && !(await button.evaluate((b) => { const r = b.getBoundingClientRect(); return r.top >= 0 && r.bottom <= innerHeight; })); i++) {
await page.mouse.wheel(0, 300);
await page.waitForTimeout(50);
}
await button.click();
const box = page.locator("#addSheet .signing");
await box.locator(".callback-form input").waitFor();
const at = await page.evaluate(() => {
const v = document.querySelector("#view-providers"), b = document.querySelector("#addSheet .signing");
const r = b.getBoundingClientRect(), w = v.getBoundingClientRect();
return { top: v.scrollTop, height: v.scrollHeight, client: v.clientHeight, inSight: r.top >= w.top && r.top < w.bottom };
});
assert(at.height > 1.5 * at.client, `the sheet is taller than the window (${at.height} over ${at.client})`);
assert(at.top > 0, "the page went down to the sign-in");
assert(at.inSight, "the sign-in is in sight");
assert.match(await box.innerText(), /Last One/);
assert.deepEqual(errors, []);
});
}
});
}