gui: Settings left blank after a restart say why and are read again; a view entrance plays out of sight (WaiooT on X)

WaiooT on X, v0.1.4573 on the Mac: after Restart only or Restart to
update the window came back on Settings › About with nothing under the
header and sidebar.

Two ways the page leaves that pane blank, both fixed:
- Every page of Settings is drawn from one read of /api/settings. One
  that failed (a magpie just restarted still starting, or its read
  erring) left them all empty, and only the footer said why, for 8 s;
  nothing read them again. The view now says "Couldn't read the
  settings" with the reason and Try again, and reads them again by
  itself at 2, 4, 8 s up to every 30 s; the line goes once they are
  read. It lives in settingsunread.js, imported only when a read fails,
  so app.js stays under its budget with no raise (TestCoreScriptBudget
  ok). Words in zh, zh-TW, ja and de.
- A page out of sight (the Mac's window hidden, #4293) paused every CSS
  animation, a view's one-shot entrance too, so a view shown then sat at
  its first frame, opacity 0, until the page heard it was back. A view's
  entrance now plays out of sight (app.css), and a page told it is back
  finishes any view entrance still running (playViews).

Run (mote):
- settings-unread.test.cjs (new): 14 pass at this tree, both engines,
  en/zh/ja; on the old app.js, app.css and i18n.js all 14 red (no line,
  About empty; the out-of-sight view's opacity "0").
- settings-*.test.cjs, window-visibility, window-asleep, version-restart,
  i18n-keys, i18n-en-no-cjk, old-webkit, panel-units-follow,
  sidebar-settings-steady and refresh-page, both engines: 510 pass, 2
  red, both old-webkit and both red on the base 76b490576 as well:
  guideback.js unlisted (#6570) and a :has() in app.css (#7235).
- go test ./internal/gui -run 'TestCoreScriptBudget|TestI18n|TestAssets'
  ok.
- A real restart of a built magpie in a sandbox HOME (POST /api/restart,
  the handover, the new window's page reporting back): /api/settings
  answered in ~2 ms and About drew 18 rows, so an empty sandbox config
  didn't reproduce it; the new page's view did read opacity "0" while
  its window was out of sight.

Not tried: a visible window on a real Mac (over ssh the window never
shows), so which of the two the reporter met is not confirmed; the
reporter's own config.
This commit is contained in:
yetone
2026-11-20 11:27:11 +08:00
parent 6e6da86c81
commit c2924c36d4
6 changed files with 145 additions and 4 deletions
+7 -2
View File
@@ -33,7 +33,7 @@ three.
2. `startBackend` brings up the gateway, or finds another magpie serving it.
3. The panel and the window load `index.html` from `Handler`. `boot.js` passes the saved language, theme, colorblind mode, text size and desktop font choices before the first paint. It also puts in the look of the reader's own (`appearance.go`, CHENGJIAHEGOXIS on X): Settings › General's Accent color (`accent`, `#rrggbb`; `accentVars` darkens it on the light theme and lightens it on the dark one until it reads as text at 4.5:1; it also sets `--mark`, the ink of what is chosen: the open page's sidebar icon, a switch's or tab's chosen option, Library's switches and radios. `--mark` is `var(--fg)`, graphite, until the user picks an accent, so a picked colour shows on the page it is picked on. A picked colour also tints the theme's grounds, the window's and the tray panel's (`--bg`, `--card`, the pills, lines and the dark menus' `--pop-bg`; `tintVars`): each takes 5% (light) or 8% (dark) of the colour's hue, its own lightness kept, so a grey pick changes nothing and text keeps its contrast. A dark pick, one whose OKLab lightness is under 0.4 (Graphite and every preset are lighter), takes the dark grounds as far toward black as it is dark (`ground`, `darkness`), losing app.css's cool grey cast and taking more of the pick's hue as they go: black draws a #000000 page with its cards, pills, lines and menus the same neutral steps above it, and a deep navy a near-black navy page (`TestDarkPickDarkensPage`). Black's ink starts most of the way to white (`lifted`, by `depth`), so it is not Graphite's grey; on the light theme black is black ink, and white the light theme's dark ink (`TestBlackIsBlack`); with no accent, or under Omarchy, they are app.css's own. `TestTintBasesAreAppCSS` holds the Go bases to app.css, and `TestLookFixture` the GUI tests' `fixtures/look-accents.json` to `lookCSS`) and Background image (a PNG, JPEG, GIF or WebP of 16 MB at most, saved as `wallpaper` in magpie's folder by `POST /api/appearance/wallpaper` as base64 JSON, `{remove: true}` to take it away; `settings.Wallpaper` is its stamp), drawn behind the window's pages under a veil of the theme's background, never in the tray panel or under Omarchy. `bootPrefs.look` says which look was drawn; `applyPrefs` asks `/api/appearance/css` again only when the settings' look differs, and the rows are drawn by the lazy `appearance.js` (`appearance-look.test.cjs`, `appearance_test.go`).
4. The page reads `GET /api/state` and writes through `POST` routes. Each write answers with the new state, built under `held`.
5. Closing the window hides it. On the Mac a full-screen window first leaves full screen (`closeStep`). The system's close on the panel (a title bar's X, Alt+F4, a window manager's close key) hides it as Escape does, so the tray icon opens it again; a panel lightweight mode let go, no longer `h.panel`, closes (`makePanel`, `TestPanelCloseHidesIt`). A hidden macOS window keeps its WKWebView's page marked visible, so `hideWebview` tells the page it is out of sight before `orderOut`; that makes `document.hidden` and `visibilityState` true, stops the page's polling and frame loops, and pauses CSS animations. `showWebview` tells it it is visible again (#4293). Lightweight mode lets go only of a window closed this way: one covered by another app's window, minimised, or open as magpie was hidden is still open (`windowUp`, not Wails' `IsVisible`, which is the occlusion state), and so is it for the Dock while the window is open and for a restart (#1381, `TestCoveredWindowStaysUp`). On the Mac the tray icon and a usage cell close an open panel by the same test (`windowOpen` in `togglePanelNow` and `trayCellClick`, not Wails' `ToggleWindow`), so under a window over the whole screen, such as a remote-desktop server's privacy curtain, the icon still closes the panel instead of showing it again (#1661, `TestTrayCellClickReleasedPanel`). On Windows a hidden window's WebView2 is put on its low memory target (`lowWhileHidden`, [`memtarget_windows.go`](../../internal/gui/memtarget_windows.go): `ICoreWebView2_19::put_MemoryUsageTargetLevel`, on each hide, on a page that comes while hidden, and back to normal on each show), so the panel and the window kept loaded in the tray stop holding what they last drew; the page stays loaded and running, unlike lightweight mode. In the tray the WebView2 processes' private working set went from ~170 MB to 20 to 40 MB, while their commit charge stayed where it was (molamaker11 on X). WKWebView and WebKitGTK have nothing magpie can set for it.
5. Closing the window hides it. On the Mac a full-screen window first leaves full screen (`closeStep`). The system's close on the panel (a title bar's X, Alt+F4, a window manager's close key) hides it as Escape does, so the tray icon opens it again; a panel lightweight mode let go, no longer `h.panel`, closes (`makePanel`, `TestPanelCloseHidesIt`). A hidden macOS window keeps its WKWebView's page marked visible, so `hideWebview` tells the page it is out of sight before `orderOut`; that makes `document.hidden` and `visibilityState` true, stops the page's polling and frame loops, and pauses CSS animations, all but a view's entrance: held, a view shown out of sight stayed transparent at its first frame, a blank pane under the header and sidebar if the window came up without being told (WaiooT on X); a page told it is back finishes any view entrance still running (`playViews`). `showWebview` tells it it is visible again (#4293). Lightweight mode lets go only of a window closed this way: one covered by another app's window, minimised, or open as magpie was hidden is still open (`windowUp`, not Wails' `IsVisible`, which is the occlusion state), and so is it for the Dock while the window is open and for a restart (#1381, `TestCoveredWindowStaysUp`). On the Mac the tray icon and a usage cell close an open panel by the same test (`windowOpen` in `togglePanelNow` and `trayCellClick`, not Wails' `ToggleWindow`), so under a window over the whole screen, such as a remote-desktop server's privacy curtain, the icon still closes the panel instead of showing it again (#1661, `TestTrayCellClickReleasedPanel`). On Windows a hidden window's WebView2 is put on its low memory target (`lowWhileHidden`, [`memtarget_windows.go`](../../internal/gui/memtarget_windows.go): `ICoreWebView2_19::put_MemoryUsageTargetLevel`, on each hide, on a page that comes while hidden, and back to normal on each show), so the panel and the window kept loaded in the tray stop holding what they last drew; the page stays loaded and running, unlike lightweight mode. In the tray the WebView2 processes' private working set went from ~170 MB to 20 to 40 MB, while their commit charge stayed where it was (molamaker11 on X). WKWebView and WebKitGTK have nothing magpie can set for it.
6. The window opens as it was last left. Its settled size and whether it was maximised are kept in `settings.Window` and `settings.WindowMaximised` (`settle`; per machine, see `KeepOwn`). A maximised window keeps the size it restores to. `makeMain` opens it at that size (`openSize`). On its first show, `placeMain` maximises it again on the Mac and Windows (on Windows once the page has come). On Linux, `makeMain` makes it maximised with `StartState`. On Windows a size larger than the screen's work area is fitted and centred (`fitRoom`), and the larger size stays kept. Where it was left is kept too, in `settings.WindowAt` (its top left corner across every screen, in the system's coordinates), so after a restart or an update it opens there rather than in the middle (jorbenzhu on Discord). `keepAt` saves it once a move or resize has rested for half a second, unless the window is maximised, full screen, minimised or hidden; `settings.Save` writes through temp and rename, and a settings file that can't be read is left alone. On its first show `placeMain` puts it back (`putBack`): `openAt` takes the screen holding most of the window, moves the window fully onto that screen's work area, and leaves it centred when no screen holds any of it, such as a monitor that is gone, or when the screens or the file can't be read (`TestOpenAt`). Under Wayland a window can't place itself, so nothing is kept or put back there unless GDK_BACKEND is x11 (`keepsPlace`, `TestKeepsPlace`). The pin in the window's title bar, between Refresh and Settings (`#pin`, `renderOnTop`; NovaStudiosss on X, to watch Usage and Routing while working in another app), keeps the window above other apps' windows: `POST /api/window/ontop?on=1` (or `0`) saves `settings.OnTop` (`SetOnTop`, this computer's own, kept through a Settings save) and calls `SetAlwaysOnTop`, and `makeMain` opens the window pinned when it is set. boot.js says whether there is a pin (`pin`, `pinnable` in `ontop.go`) and whether it is pressed (`onTop`) before the first paint. There is none in the panel, in a browser page or `magpie web`, or under Wayland (the same `keepsPlace`: GTK's keep-above does nothing there), and the route refuses there with 400 and saves nothing (`TestPinKeepsWindowOnTop`, `TestPinRefusedWithoutAWindowToPin`, `window-pin.test.cjs`). The tray's panel isn't kept: on the Mac and Windows it opens under the tray icon, and on Linux where the click was.
7. The page's header is the window's title bar. `plainTitlebar` sets it up once the app has started, and again on a window lightweight mode made again (`madeAgain`). On Linux it hides GTK's title bar and keeps the shadow and the resize edges; GTK 3 leaves the corners square. On the Mac the traffic lights are inset into the header (`MacTitleBarHiddenInset`). In the design of macOS 26 a window with a toolbar has larger corners than one with a plain title bar, so `insetLights` ([`titlebar_darwin.go`](../../internal/gui/titlebar_darwin.go)) takes the toolbar off, and `MagpieLights` keeps the lights and the title bar's height where the toolbar had them: after a resize, a new title, light or dark, more contrast or less transparency, and leaving full screen. A sheet, such as the folder chooser, still begins below the title bar. A first press while another app is in front still moves the window from anywhere in that title bar (`firstPress`), as AppKit moved it with the toolbar; AppKit itself now does so only in a plain title bar's top 32pt. AppKit gives a program that design from macOS 26 when the program is linked against the macOS 26 SDK or a later one and its Info.plist doesn't ask for the earlier design (`UIDesignRequiresCompatibility`); `designOf26` reads each at run time, as the SDK depends on the toolchain that built magpie. The toolbar stays where it doesn't change the corners: in the earlier design, and on macOS 27, which gives a window with a toolbar a plain title bar's 16pt corners (`toolbarRounder` holds the window's radius against a window of its style with no toolbar, never shown); with the lights on the right (a right-to-left language), or when the title bar isn't laid out as expected; this is decided once, when the window is set up. A toolbar that stays has no menu: a right-click on the title bar offered *Icon and Text*, *Icon Only* and *Text Only* for it (AlanWang1027713 on X), so `quietToolbar` turns off `allowsDisplayModeCustomization` on macOS 15 and later and AppKit's own `_setWantsToolbarContextMenu:` before that, each looked up at run time; `TestMainWindowCorners` and `TestMainWindowRightToLeft` check the menu a right-click by the lights gets from the window frame. In full screen the title bar is AppKit's own. On Windows the main window is frameless (`mainFrameless` in [`mainwindow.go`](../../internal/gui/mainwindow.go)), so a wallpaper or the page's colour runs to its top instead of stopping under a separate strip (258a14 on X). Wails keeps the frame's styles, so it still has its shadow and Windows 11's rounded corners, and snaps with Win+arrows and by dragging to a screen's edge. Wails' frameless window has no frame left to resize from, only a band 4px wide inside the page, and the page's scrollbar covers it on the right (Puremilk_chun on X), so the main window keeps Windows' own resize border on its left, right and bottom, outside the page as on a framed window (`mainFrameCalc` in [`mainframe_windows.go`](../../internal/gui/mainframe_windows.go), asked first by `appWndProc`; `keepResizeFrame` names the window once Wails' runtime is ready; `TestMainWindowKeepsResizeBorder`). Its top is still the page's, resized by Wails' band; maximised or in full screen Wails sizes it as before. The page draws the caption buttons at the header's right (`#wincap`, shown by app.css under `html.win` from `layout.js` in the window and not on the web, run by `wincap.js`, which app.js imports in that window alone, Segoe Fluent Icons' glyphs, Close red on hover); they minimise, maximise or restore, and close (hide; the tray stays), and stay over a dialog's scrim (`wincap.js` undoes the `inert` that `modalBackground` sets on them). The header's own tools sit left of them. A double click on anything that drags the window maximises or restores it. The app tells the page whether the window is maximised (`captionJS`, on Wails' runtime ready and on a resize that changes it), which swaps maximise for restore and keeps Wails' resize edges inside the page off while maximised, so the top-right pixel is Close's (`TestCaptionKeepsEdgesOffWhileMaximised`, `win-caption.test.cjs`). Windows 11's snap layouts flyout over maximise isn't shown: it needs Wails' composition hosting (`--wails-non-client-region`), which forwards input by `SendMouseInput` only. The panel keeps its own window as before.
8. On the Mac, Settings › Show in Dock puts magpie in the Dock never (`DockNever`), while the window is open (the default; `DockWindow` records it chosen, for an older magpie that took none for never) or always (`Dock`, which wins). The default was never until ShouguangCao on X found the open window out of Command-Tab, so going back to it to paste a key copied elsewhere took the menu bar; a new install (no settings.json) reads With window, and Hide is a choice of its own (`inDock`, `dockChoice` in app.js, `TestDockFollowsWindowByDefault`, `dock-choice.test.cjs`). A file written before that has no `dockSettled`, and stored Hide as nothing, so a user who chose Hide can't be told from one who never chose: such a file with no Dock choice reads as Hide, and the first save writes it so with `dockSettled` (`settleDock`, `TestOlderSettingsKeepHide`, `TestNewInstallFollowsWindow`). A file nobody can read reads the same way. The page never sends `dockSettled`; the save keeps the file's (`TestSettingsSaveKeepsDockReading`). It is this computer's own, as the Dock choice is (`KeepOwn`). A full-screen window joins it whatever the setting (`inDock`, `dockOnFullscreen`). `openMain` joins before it shows the window (`setDock` runs on the main thread at once). An app activated out of the Dock (the quick panel's focus) that then joins it stays last in Command-Tab's order though it is in front, so joining to the front activates magpie by way of the Dock (`dockStep`, `activateAgain`; #1381, `TestDockStep`, `TestDockJoinLeadsCommandTab`). It does so without asking NSApp whether magpie is active: the Mac makes it the front app at once, and NSApp says so only once the main thread has taken that in, after the join on a busy Mac (#1651).
@@ -1423,7 +1423,12 @@ saying "Couldn't restart magpie". A browser on the app's page restarts the
app; `magpie web` runs again in its place (`webReexec`). `/api/update`
carries `run`, when this run started, and a browser's page reloads once a
run other than the one it restarted answers (`restartSelf` in
versionrow.js, imported when Restart is pressed). See
versionrow.js, imported when Restart is pressed). Every page of Settings is
drawn from one read of `/api/settings`; one that fails says so in the view
with Try again and is read again by itself, at 2, 4, 8 s up to every 30 s
(settingsunread.js, `settingsUnread`), where before the pages were left
blank with the error in the footer for 8 s (WaiooT on X,
`settings-unread.test.cjs`). See
`TestRestartStartsMagpieAgain`, `TestUpdateSaysItsRun`,
`TestTrayMenuLabels` and `version-restart.test.cjs`.
+4
View File
@@ -142,6 +142,10 @@ html.magpie-out-of-sight,
html.magpie-out-of-sight *,
html.magpie-out-of-sight *::before,
html.magpie-out-of-sight *::after { animation-play-state: paused !important; }
/* but a view's entrance plays: held, a view shown then stays transparent
at its first frame until the page hears it is back, and a window shown
without that word was a blank pane (WaiooT on X) */
html.magpie-out-of-sight .view { animation-play-state: running !important; }
/* out of sight a while: nothing is drawn, so WebKit lets go of every
layer's buffers, which it keeps for a hidden window (#5530) */
html.magpie-asleep body { content-visibility: hidden; }
+11 -2
View File
@@ -19843,8 +19843,13 @@ async function loadSettings() {
syncView = null;
// gateway mode turned in another tab, or the agents here come and gone
if (web && !!s.gatewayOn !== gatewayMode) setGatewayMode(!!s.gatewayOn);
$("#setUnread")?.remove(); // settingsunread.js's line, once read
renderSettings();
}
// Settings never read (a magpie just restarted still starting, or the read
// failed) left every page of them blank, with only the footer saying why
// (WaiooT on X): settingsunread.js says so in the page and reads them again
function settingsUnread(e) { statusErr(e); if (!prefs && view === "settings") import("./settingsunread.js").then((m) => m.unread(e)); }
// Writes of the settings, counted as they start and end: a read of them
// (the state, the settings) that one overlapped is from before it, and is
@@ -23400,7 +23405,7 @@ async function show(v) {
// Routing's accounts' windows as Usage read them (#1833), never an asked read
// and Providers' balances (rowBalance, plugins/usage/page.js)
if ((rtView(v) || v === "providers" && !featuresOff.has("usage")) && (!quotas || Date.now() - quotasAt > 60e3)) loadQuotas();
if (v === "settings") (settingsLoad = loadSettings()).then(back, statusErr);
if (v === "settings") (settingsLoad = loadSettings()).then(back, settingsUnread);
if (v === "plugins") window.loadPlugins?.()?.then(back);
syncTitle();
syncURL();
@@ -24400,6 +24405,10 @@ if (mode === "window") {
// loadBack: a window shown again hears visibilitychange and focus together;
// one read for both. A read asked over a second ago gets one more after it.
// a view's entrance held while out of sight ends as the window is back: a
// page shown with it held at its first frame was a blank pane under its
// header and sidebar (WaiooT on X)
function playViews() { for (const v of $$(".view")) for (const a of v.getAnimations?.() || []) try { a.finish(); } catch {} }
function loadBack() {
const f = loadBack.flight;
if (f && performance.now() - f.at < 1000) return f.done;
@@ -24412,7 +24421,7 @@ function loadBack() {
// and one gone from view, hidden or closed (which hides it first), says
// so: what its Sessions and Usage pages keep goes 30 s later unless a page
// asks again (pageAwayFor)
document.addEventListener("visibilitychange", () => { if (!document.hidden) { loadBack(); wag(); refreshLanes(); } else fetch("/api/page-away", { method: "POST", keepalive: true }).catch(() => {}); });
document.addEventListener("visibilitychange", () => { if (!document.hidden) { playViews(); loadBack(); wag(); refreshLanes(); } else fetch("/api/page-away", { method: "POST", keepalive: true }).catch(() => {}); });
// an agent's config can be rewritten, or the agent run round magpie, while the
// window is up: ask what drifted now and then, and redraw only on a change —
// never under an open menu
+4
View File
@@ -2541,6 +2541,7 @@ const I18N = {
"Code": "验证码",
"Sign-in didn't finish": "登录未完成",
"Try again": "重试",
"Couldn't read the settings": "无法读取设置",
"Signed in as {user}": "已登录 {user}",
"{user} added — switch to it any time": "已添加 {user},随时可以切换",
"{user} is already listed — its sign-in was renewed": "{user}:该账号已在列表中,已更新登录",
@@ -8047,6 +8048,7 @@ const I18N = {
"Code": "驗證碼",
"Sign-in didn't finish": "登入未完成",
"Try again": "重試",
"Couldn't read the settings": "無法讀取設定",
"Signed in as {user}": "已登入 {user}",
"{user} added — switch to it any time": "已新增 {user},隨時可以切換",
"{user} is already listed — its sign-in was renewed": "{user}:該帳號已在列表中,已更新登入",
@@ -13522,6 +13524,7 @@ const I18N = {
"Code": "コード",
"Sign-in didn't finish": "サインインが完了しませんでした",
"Try again": "再試行",
"Couldn't read the settings": "設定を読み込めませんでした",
"Signed in as {user}": "{user} としてサインインしました",
"{user} added — switch to it any time": "{user} を追加しました。いつでも切り替えられます",
"{user} is already listed — its sign-in was renewed": "{user} はすでに一覧にあります。サインインを更新しました",
@@ -19040,6 +19043,7 @@ const I18N = {
"Code": "Code",
"Sign-in didn't finish": "Anmeldung nicht abgeschlossen",
"Try again": "Erneut versuchen",
"Couldn't read the settings": "Die Einstellungen konnten nicht gelesen werden",
"Signed in as {user}": "Angemeldet als {user}",
"{user} added — switch to it any time": "{user} hinzugefügt — jederzeit wechselbar",
"{user} is already listed — its sign-in was renewed": "{user} ist bereits aufgeführt — die Anmeldung wurde erneuert",
+26
View File
@@ -0,0 +1,26 @@
// Settings that couldn't be read, imported from settingsUnread (app.js) when
// a read fails, so it weighs nothing on the core. A window back after a
// restart found Settings › About blank under its header and sidebar
// (WaiooT on X): every page of Settings is drawn from that read, and only
// the footer said, for 8 s, that it had failed. The view now says so, with
// Try again, and reads the settings again by itself, sooner first.
let timer, tries = 0;
export function unread(e) {
if (prefs || view !== "settings") return;
let line = $("#setUnread");
if (!line) {
line = el("div", "empty-state");
line.id = "setUnread";
$("#view-settings .set-head").after(line);
}
const again = el("button", "link", t("Try again"));
again.onclick = () => {
clearTimeout(timer);
if (prefs || view !== "settings") return;
(settingsLoad = loadSettings()).then(() => { tries = 0; backAfterLoad($("#view-settings")); }, settingsUnread);
};
line.replaceChildren(el("b", "", t("Couldn't read the settings")), e.message || "", " ", again);
clearTimeout(timer);
timer = setTimeout(() => again.click(), Math.min(30, 2 ** ++tries) * 1e3);
}
@@ -0,0 +1,93 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// After Restart only or Restart to update, WaiooT on X found the window back
// on Settings › About with nothing under the header and sidebar:
// - Settings that couldn't be read left every page of them blank, with only
// the footer saying why for 8 s. The page now says so in the view, with
// Try again, and reads them again by itself;
// - a view shown while the page was out of sight (the Mac's window hidden,
// or not yet told it is shown) held its entrance at its first frame,
// transparent. A view's entrance now plays out of sight too.
// Both engines, three languages; no backend, the API is faked here.
const assert = require("node:assert/strict");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { fixture } = require("./fixtures/caller-keys.cjs");
const words = {
en: { unread: "Couldn't read the settings", again: "Try again" },
zh: { unread: "无法读取设置", again: "重试" },
ja: { unread: "設定を読み込めませんでした", again: "再試行" },
};
async function open(engine, lang, failing) {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const ctx = await browser.newContext({ viewport: { width: 1000, height: 760 } });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.settingsTab", "about"); } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(8000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
const fx = fixture(lang, "light", []);
// reads of the settings fail until the test lets them through
const reads = { settings: 0, failing };
await page.route("**/*", (route) => {
const u = new URL(route.request().url());
if (u.pathname === "/api/settings" && route.request().method() === "GET" && reads.settings++ >= 0 && reads.failing) {
return route.fulfill({ status: 502, contentType: "text/plain", body: "magpie is starting" });
}
return fx(route);
});
return { browser, page, errors, reads };
}
const aboutRows = (page) => page.locator("#about .row").count();
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const [lang, w] of Object.entries(words)) {
test(`${engine} ${lang}: Settings that couldn't be read say so, and Try again reads them`, async (t) => {
const { browser, page, errors, reads } = await open(engine, lang, true);
t.after(() => browser.close());
await page.goto("http://magpie.test/?view=settings");
const line = page.locator("#view-settings #setUnread");
await line.waitFor({ state: "visible" });
assert.match(await line.innerText(), new RegExp(w.unread));
assert.equal(await aboutRows(page), 0);
reads.failing = false;
await line.getByRole("button", { name: w.again }).click();
await page.waitForFunction(() => document.querySelectorAll("#about .row").length > 0);
assert.equal(await line.count(), 0, "the line goes once the settings are read");
assert.deepEqual(errors, []);
});
test(`${engine} ${lang}: Settings that couldn't be read are read again by themselves`, async (t) => {
const { browser, page, errors, reads } = await open(engine, lang, true);
t.after(() => browser.close());
await page.goto("http://magpie.test/?view=settings");
await page.locator("#view-settings #setUnread").waitFor({ state: "visible" });
reads.failing = false;
// the next read is at most 4 s away
await page.waitForFunction(() => document.querySelectorAll("#about .row").length > 0, null, { timeout: 15000 });
assert.ok(reads.settings >= 2);
assert.equal(await page.locator("#setUnread").count(), 0);
assert.deepEqual(errors, []);
});
}
test(`${engine}: a view shown out of sight is not left transparent`, async (t) => {
const { browser, page, errors } = await open(engine, "en", false);
t.after(() => browser.close());
await page.goto("http://magpie.test/?view=agents");
await page.waitForFunction(() => typeof window.magpieWindowVisibility === "function" && !!document.querySelector("#view-agents:not([hidden])"));
await page.evaluate(() => { window.magpieWindowVisibility(false); show("settings"); });
await page.waitForFunction(() => document.querySelectorAll("#about .row").length > 0);
// the entrance is .24 s; well past it, the view is drawn whole
await page.waitForTimeout(800);
const seen = await page.evaluate(() => {
const v = document.querySelector("#view-settings");
return { hidden: v.hidden, opacity: getComputedStyle(v).opacity, outOfSight: document.documentElement.classList.contains("magpie-out-of-sight") };
});
assert.deepEqual(seen, { hidden: false, opacity: "1", outOfSight: true });
assert.deepEqual(errors, []);
});
}