diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 9a68d29f4..f177cb819 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -20091,7 +20091,7 @@ function renderSettings() { } // gateway mode leaves out what is written into this computer's agents' // files, and the alerts its desktop would show - for (const r of [$("#plainNamesSegs").parentElement, $("#usageAlertRow"), $("#balanceAlertRow"), $("#resetReminderRow"), $("#turnDoneRow"), $("#maskAlertRow")]) r.hidden = gatewayMode; + for (const r of [$("#plainNamesSegs").parentElement, $("#usageAlertRow"), $("#balanceAlertRow"), $("#resetReminderRow"), $("#turnDoneRow")]) r.hidden = gatewayMode; // the parts' tabs, one gone whose rows are all hidden here setSetTab(setTab); } @@ -21252,8 +21252,6 @@ function renderAlerts(s, keep) { const turnOpts = [["0", t("Off")], ...mins.map((m) => [String(m * 60), t("{n} min", { n: m })])]; if (d && !mins.some((m) => m * 60 === d)) turnOpts.push([String(d), d % 60 ? t("{n} s", { n: d }) : t("{n} min", { n: d / 60 })]); $("#turnDoneSegs").replaceChildren(segs(turnOpts, String(d), (v) => savePrefs({ ...keep, turnDoneAlert: Number(v) }))); - // a value masked for the first time (Must2333 on X): off until turned on - $("#maskAlertSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.maskAlert ? "on" : "off", (v) => savePrefs({ ...keep, maskAlert: v === "on" }))); } // AGENT_PREFS: an agent's own settings, by its id, each a row kept in diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index 12b3322f9..7bdc5cf0c 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -323,10 +323,6 @@
Task done alert
-
-
Masking alert
A notification when masking swaps a value for the first time: its kind and how many, never the value itself
-
-
diff --git a/internal/gui/assets/plugins/redact/client.js b/internal/gui/assets/plugins/redact/client.js index 21dc95f22..7fe72525e 100644 --- a/internal/gui/assets/plugins/redact/client.js +++ b/internal/gui/assets/plugins/redact/client.js @@ -7,9 +7,12 @@ // list under it each request (or each value) masking changed (between // them, folded, demo.js's 小鹊 shows how masking works), and a // request opened says what it carried, what the vendor got instead, and -// how each value was found and put back. The hooks are what the shell -// asks of it: open, refresh (the window came back), reload (Refresh in -// the sidebar), leave, and focus (a masked call's badge opens its request). +// how each value was found and put back. The Masking alert closes the +// page (it sat in Settings › Usage, where nb5p looked for it in vain), +// after the list, so the requests still start in the first screen. The +// hooks are what the shell asks of it: open, refresh (the window came +// back), reload (Refresh in the sidebar), leave, and focus (a masked +// call's badge opens its request). magpie.plugin("redact", (ctx) => { ctx.slots.add("page", { key: "masking", @@ -26,6 +29,12 @@ magpie.plugin("redact", (ctx) => {
+
+
+
Masking alert
A notification when masking swaps a value for the first time: its kind and how many, never the value itself
+
+
+
`, open() { return maskPageOpen(); }, diff --git a/internal/gui/assets/plugins/redact/page.js b/internal/gui/assets/plugins/redact/page.js index dfbdd1de5..ebbb695e4 100644 --- a/internal/gui/assets/plugins/redact/page.js +++ b/internal/gui/assets/plugins/redact/page.js @@ -90,6 +90,7 @@ function maskPageOpen() { } function maskPageLoad(force) { maskDrawAll(); + (prefs ? Promise.resolve() : loadSettings()).then(drawMaskAlert).catch(() => {}); const sum = maskLoad(force)?.then(() => { drawMaskCard(); drawMaskList(); }); const recs = maskL.read && force ? maskRefresh() : maskL.read ? null : maskFetch(); return Promise.all([sum, recs]); @@ -99,6 +100,15 @@ function maskDrawAll() { drawMaskList(); if (maskO) drawMaskOne(); } +// the Masking alert (Must2333 on X): a notification when a value is +// masked for the first time, off until turned on. Gateway mode leaves it +// out, as it does the other alerts its desktop would show +function drawMaskAlert() { + const s = prefs || {}; + $("#maskPrefs").hidden = gatewayMode; + $("#maskAlertSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.maskAlert ? "on" : "off", + (v) => savePrefs({ ...prefsKeep(s), maskAlert: v === "on" }).then(drawMaskAlert))); +} // while the page is on screen it keeps up with requests as they go setInterval(() => { if (view !== "masking" || document.hidden) return; @@ -628,7 +638,7 @@ function maskOneOpen(key, r) { if (!key) return; maskTipOff(); const o = maskO = { key, r: r || maskL.records.find((x) => x.key === key) || null, sent: undefined, leaves: null, vals: new Map(), view: "both", pick: "", open: new Set(), whole: new Set() }; - $("#maskCard").hidden = $("#maskList").hidden = $("#maskDemo").hidden = true; + $("#maskCard").hidden = $("#maskList").hidden = $("#maskDemo").hidden = $("#maskPrefs").hidden = true; xqd?.wake(); $("#maskOne").hidden = false; drawMaskOne(); @@ -658,6 +668,7 @@ function maskOneClose() { $("#maskOne").hidden = true; $("#maskOne").replaceChildren(); $("#maskCard").hidden = $("#maskList").hidden = $("#maskDemo").hidden = false; + $("#maskPrefs").hidden = gatewayMode; xqd?.wake(); drawMaskList(); } diff --git a/internal/gui/assets/plugins/redact/redact.css b/internal/gui/assets/plugins/redact/redact.css index ee95e3554..32012d014 100644 --- a/internal/gui/assets/plugins/redact/redact.css +++ b/internal/gui/assets/plugins/redact/redact.css @@ -86,6 +86,7 @@ /* the list: a bar, facets that narrow it, a day at a time */ .msk-list { margin-top: 14px; } +.msk-prefs { margin-top: 14px; border-radius: 14px; } .msk-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; } .msk-live { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); } .msk-live i { width: 6px; height: 6px; border-radius: 50%; background: var(--green, var(--accent)); animation: msk-live 2.4s ease-in-out; } diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md index 67050c5bb..59d875c1b 100644 --- a/internal/gui/tests/README.md +++ b/internal/gui/tests/README.md @@ -144,10 +144,11 @@ node --test --test-concurrency=1 internal/gui/tests/gateway-caller-keys.test.cjs ## Other Browser Regressions -`mask-alert.test.cjs` checks Settings › Usage's Masking alert (Must2333 on -X): after the task done alert, Off to begin with; On saves `maskAlert`, -another setting saved later keeps it, Off saves false, no click moves the -page, and the row goes while masking is switched off. Every language at 900 +`mask-alert.test.cjs` checks Insights › Masking's Masking alert (Must2333 on +X): after the page's list and not in Settings › Usage (nb5p on Discord), Off +to begin with; On saves `maskAlert`, another setting saved later keeps it, +Off saves false, no click moves the page, and the row goes while masking is +switched off. Every language at 900 and 380 wide, in Chromium and WebKit, with the API faked. `local-address.test.cjs` checks the Address of a local server's provider diff --git a/internal/gui/tests/mask-alert.test.cjs b/internal/gui/tests/mask-alert.test.cjs index a7fd215da..959e0b324 100644 --- a/internal/gui/tests/mask-alert.test.cjs +++ b/internal/gui/tests/mask-alert.test.cjs @@ -1,10 +1,12 @@ // Run with Node's test runner and Playwright on the module path; see README.md. // The masking alert (Must2333 on X: 我还希望能即时的知道发生了替换,但不是 -// 通过随时监控网关的方式): Settings › Usage has "Masking alert" after the -// task done alert, Off to begin with; On saves maskAlert, another setting -// saved later keeps it, Off saves false, and no click moves the page. With -// masking switched off in Plugins › Built-in the row goes with it. Every -// language, wide and narrow, both engines; the API is faked here. +// 通过随时监控网关的方式): Insights › Masking has "Masking alert" after its +// list of requests, and Settings › Usage no longer does (nb5p on Discord: 这个脱敏提醒被 +// 放到额度设置里了,害得我找半天没找到). Off to begin with; On saves +// maskAlert, another setting saved later keeps it, Off saves false, and no +// click moves the page. With masking switched off in Plugins › Built-in the +// row goes with it. Every language, wide and narrow, both engines; the API +// is faked here. const assert = require("node:assert/strict"); const fs = require("node:fs/promises"); const path = require("node:path"); @@ -57,7 +59,7 @@ const words = { sub: "Eine Benachrichtigung, wenn ein Wert zum ersten Mal maskiert wird: Art und Anzahl, nie der Wert selbst" }, }; -async function open(engine, width, lang, posts, featuresOff, t, name) { +async function open(engine, width, lang, posts, featuresOff, t, name, where = "?view=masking") { const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); const page = await (await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" })).newPage(); t.after(async () => { @@ -73,15 +75,15 @@ async function open(engine, width, lang, posts, featuresOff, t, name) { page.on("pageerror", (e) => errors.push(e.message)); await page.route("**/*", server(lang, posts, featuresOff)); await watchSettingsReads(page); - await page.goto("http://magpie.test/?view=settings&tab=usage"); - await settingsDrawn(page); // rows found are the ones that stay (#1659) + await page.goto("http://magpie.test/" + where); + if (where.includes("settings")) await settingsDrawn(page); // rows found are the ones that stay (#1659) return { page, errors }; } for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { for (const lang of Object.keys(words)) { for (const width of [900, 380]) { - test(`${engine} ${lang} ${width}px: the masking alert is turned on and off on the Settings page`, async (t) => { + test(`${engine} ${lang} ${width}px: the masking alert is turned on and off on the Masking page`, async (t) => { const posts = []; const { page, errors } = await open(engine, width, lang, posts, [], t, "mask-alert"); const posted = async (n) => { for (let i = 0; i < 100 && posts.length < n; i++) await page.waitForTimeout(20); assert.equal(posts.length, n, "posts"); return posts[n - 1]; }; @@ -93,15 +95,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal((await page.locator("#maskAlertRow .sub").textContent()).trim(), w.sub); assert.deepEqual(await opts.allTextContents(), [w.off, w.on]); assert.equal(await page.locator("#maskAlertSegs .opt.on").textContent(), w.off, "off until turned on"); - // it is the row after the task done alert, in the same group - assert.equal(await page.locator("#turnDoneRow + #maskAlertRow").count(), 1); + // it is the Masking page's, after its list of requests + assert.equal(await page.locator("#view-masking #maskList + #maskPrefs > #maskAlertRow").count(), 1); + assert.equal(await page.locator("#view-settings #maskAlertRow").count(), 0, "no copy in Settings"); const over = await page.evaluate(() => { const row = document.querySelector("#maskAlertRow").getBoundingClientRect(); return [...document.querySelectorAll("#maskAlertRow *")].filter((e) => e.getBoundingClientRect().right > Math.max(row.right, innerWidth) + 1).map((e) => e.className || e.id); }); assert.deepEqual(over, [], "nothing past the edge"); - const scrolled = () => page.locator("#view-settings").evaluate((v) => v.scrollTop); + const scrolled = () => page.locator("#view-masking").evaluate((v) => v.scrollTop); await reach(page, opts.nth(1)); let top = await scrolled(); await opts.nth(1).click(); @@ -110,11 +113,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await page.locator("#maskAlertSegs .opt.on").textContent(), w.on); assert.equal(await scrolled(), top, "the click moved the page"); - // another setting saved later keeps it - await reach(page, page.locator("#currencySegs .opt").nth(1)); + // another setting saved later keeps it: the card's Turn off masking + const offBtn = page.locator("#maskCard .msk-head button.text"); + await reach(page, offBtn); top = await scrolled(); - await page.locator("#currencySegs .opt").nth(1).click(); - assert.equal((await posted(2)).maskAlert, true, "kept by another save"); + await offBtn.click(); + const second = await posted(2); + assert.equal(second.redact, false, "the card's switch saved"); + assert.equal(second.maskAlert, true, "kept by another save"); await page.waitForTimeout(300); assert.equal(await scrolled(), top, "no click moved the page"); @@ -126,8 +132,15 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", }); } } + test(`${engine}: Settings › Usage has no masking alert`, async (t) => { + const { page, errors } = await open(engine, 900, "en", [], [], t, "mask-alert-usage", "?view=settings&tab=usage"); + await page.locator("#turnDoneSegs .opt").first().waitFor(); + assert.equal(await page.locator("#view-settings #maskAlertRow").count(), 0); + assert.equal(await page.locator("#turnDoneRow").isVisible(), true); + assert.deepEqual(errors, []); + }); test(`${engine}: with masking switched off, its alert goes too`, async (t) => { - const { page, errors } = await open(engine, 900, "en", [], ["redact"], t, "mask-alert-off"); + const { page, errors } = await open(engine, 900, "en", [], ["redact"], t, "mask-alert-off", "?view=settings&tab=usage"); await page.locator("#turnDoneSegs .opt").first().waitFor(); assert.equal(await page.locator("#maskAlertRow").isVisible(), false); assert.equal(await page.locator("#turnDoneRow").isVisible(), true);