Files
magpie/internal/gui/assets/start.js
T
yetone b0c2b5e261 gui: a page left out of the sidebar still opens from a link, ?view= or a search hit
Settings › General › Sidebar pages (magpie.navHidden) took a page out of
the sidebar, and offView then sent every way to it (a link, ?view=, a
Settings search hit, a plugin's show()) to Agents or Providers with
nothing said, so the page was unreachable. offView now redirects only a
page gateway mode or a switched-off built-in plugin leaves out. Hiding
stays a sidebar choice: the window's own kept page (magpie.lastView)
isn't reopened when it is hidden, so a fresh window still opens on the
first page, or Providers when Agents is hidden too (keptView in
start.js).

nav-pages-hidden: with Library hidden, show("library") and ?view=library
open Library; a kept lastView of library opens Providers.

Run (mica, at this tree; mote at load 27):
- nav-pages-hidden, nav-pages-order, last-page, gateway-mode, Chromium
  and WebKit: 19 pass, 1 red, last-page WebKit, red the same on
  origin/main and filed (#7033).
- go test ./internal/gui -run 'TestCoreScriptBudget|TestI18n|TestCSS': ok.

Broken by hand, each red, then put back:
- the new test on origin/main's app.js and start.js: 2 of 2 red (line
  69, Library not opened), both engines.
- keptView without the navMine check: Chromium red at line 76 (the
  window reopened the hidden page).

Not tried: the real app window, the full GUI suite.
2026-11-18 12:31:23 +08:00

28 lines
1.7 KiB
JavaScript

// The window's start, loaded last: app.js, the plugins' pages and the
// scripts after app.js are all there, so the first page shown has its
// code (the Usage page's is a plugin's, run after app.js).
// the plugins' pages wired up (kernel.js), before the first is shown
magpie.start();
navHides(); // the pages built-in plugins switched off have, from boot.js
// The window opens on the page the reader last left, as a Mac app comes back
// as it was (molvqingtai, lc on Discord): a page asked for (?view=, a link
// from the tray or a reload) first, then the one kept; a page gateway mode
// leaves out, or one there is no longer, gives way to the first page.
// the pages the window can open on besides the first (Agents)
const OPEN_VIEWS = ["providers", "plugins", "settings", ...magpie.pages()];
function keptView() {
const asked = params.get("view");
if (asked === "agents" || OPEN_VIEWS.includes(asked)) return asked;
let v = "";
try { v = localStorage.getItem("magpie.lastView") || ""; } catch { /* none kept */ }
// one gateway mode leaves out, show() makes Providers; one left out of the sidebar isn't reopened
return OPEN_VIEWS.includes(v) && !navMine().includes(v) ? v : "";
}
const firstView = mode === "window" ? keptView() || (navMine().includes("agents") ? "providers" : "") : "";
// from the tray panel's More in Plugins (q): Discover, once show() picked the tab (#3579)
if (OPEN_VIEWS.includes(firstView)) show(firstView).then(() => view === "plugins" && params.has("q") && window.pluginQuery?.(params.get("q")));
else if (mode === "window" && !gatewayMode && !sideNav()) slide($("#nav"), "nav");
// in gateway mode the first page is Providers, Agents' tab gone
if (gatewayMode) setGatewayMode(true);
load();