diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 9278261fe..14afa0ce6 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -4545,16 +4545,13 @@ async function backAsNew(was) { } } -// servedAnew reloads a browser's page (magpie web, or the app's page) -// that another version of magpie now answers for, and says whether it did. -// The page restarted to update itself reloads in backAsNew; one whose -// magpie restarted for another's update (the app's window put it in, and -// magpie web followed, or the app restarted under its own page) ran on as -// the old page, its Update pill still offering the version already in -// (visamzh on X). +// servedAnew reloads, once, a browser's page that another version of +// magpie now answers for (visamzh on X): its magpie restarted into an +// update put in elsewhere. The badge and the Version row both ask. +let reloadingAnew = false; function servedAnew(u) { if (!web || !pageVersion || !u?.current || u.current === pageVersion) return false; - location.reload(); + if (!reloadingAnew) { reloadingAnew = true; location.reload(); } return true; } @@ -24136,9 +24133,7 @@ setInterval(async () => { } window.addEventListener("focus", () => loadBack()); setInterval(renderUpdateBadge, 15 * 60 * 1000); // a window left open still hears of a new version -// a browser's page on screen hears within a minute that its magpie -// restarted into an update put in elsewhere (servedAnew), without a click -// into it first +// a browser's page on screen hears of it within a minute (servedAnew) if (web) setInterval(() => { if (!document.hidden) renderUpdateBadge(); }, 60e3); // renderPluginDot puts a dot on Plugins while a plugin's update waits for // the reader (someone else's plugin, or one pinned; the community's update diff --git a/internal/gui/tests/update-served-anew.test.cjs b/internal/gui/tests/update-served-anew.test.cjs index e302d20ba..c09e0e8aa 100644 --- a/internal/gui/tests/update-served-anew.test.cjs +++ b/internal/gui/tests/update-served-anew.test.cjs @@ -40,6 +40,9 @@ function server(lang, web, ctl) { if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: settingsPayload(lang), fx: settingsPayload(lang).fx }); if (url.pathname === "/api/settings") return json(settingsPayload(lang)); if (url.pathname === "/api/update") { + // the badge's and the Version row's reads answer a few ms apart, as + // on a busy machine: a page that reloads for each one is loaded twice + if (ctl.version !== "0.1.400" && ctl.reads++) await new Promise((r) => setTimeout(r, 5)); return json(ctl.version === "0.1.400" ? { state: "ready", current: "0.1.400", latest: "0.1.401" } : { state: "latest", current: "0.1.401", latest: "0.1.401" }); @@ -76,23 +79,22 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", t.after(() => browser.close()); for (const width of [1100, 420]) for (const lang of langs) { await t.test(`${lang} at ${width}: clicked back into`, async () => { - const ctl = { version: "0.1.400", pages: 0 }; + const ctl = { version: "0.1.400", pages: 0, reads: 0 }; const { page, errors } = await open(browser, width, lang, true, ctl); // the app's window put 0.1.401 in, and magpie web restarted into it ctl.version = "0.1.401"; await page.evaluate(() => window.dispatchEvent(new Event("focus"))); await page.waitForFunction(() => !window.oldPage && document.readyState === "complete"); - assert.equal(ctl.pages, 2, "loaded again once"); await page.waitForTimeout(400); assert.equal(await pill(page).isHidden(), true, "the reloaded page offers no update"); - assert.equal(ctl.pages, 2, "no reload after the first"); + assert.equal(ctl.pages, 2, "loaded again once"); assert.deepEqual(errors, []); await page.context().close(); }); } for (const lang of langs) { await t.test(`${lang}: left on screen, within a minute`, async () => { - const ctl = { version: "0.1.400", pages: 0 }; + const ctl = { version: "0.1.400", pages: 0, reads: 0 }; const { page, errors } = await open(browser, 1100, lang, true, ctl, true); ctl.version = "0.1.401"; await page.clock.runFor(61e3); @@ -103,7 +105,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", }); } await t.test("the app's own window doesn't reload", async () => { - const ctl = { version: "0.1.400", pages: 0 }; + const ctl = { version: "0.1.400", pages: 0, reads: 0 }; const { page, errors } = await open(browser, 1100, "en", false, ctl); ctl.version = "0.1.401"; await page.evaluate(() => window.dispatchEvent(new Event("focus")));