diff --git a/internal/gui/assets/plugins/sessions/client.js b/internal/gui/assets/plugins/sessions/client.js index 6fcc3e0f2..dd2d8ed40 100644 --- a/internal/gui/assets/plugins/sessions/client.js +++ b/internal/gui/assets/plugins/sessions/client.js @@ -633,12 +633,22 @@ magpie.plugin("sessions", (ctx) => { if (data?.trash.length) tr.append(el("em", "", String(data.trash.length))); tr.onclick = () => { trashOn = !trashOn; selecting = false; picked.clear(); draw(); speedsOn(); }; // which agents' history is read is Settings › Privacy's (the scattered - // settings audit after netube99 on X); gateway mode reads none there + // settings audit after netube99 on X); gateway mode reads none there. + // The terminal a session opens in is General's: with that row here, + // a menu names both const go = el("button", "text sm-toset"); go.type = "button"; go.append(el("span", "", t("Settings")), " ›"); go.hidden = !!data?.reads?.gateway; - go.onclick = (e) => openSettingsAt(e, "privacy", "#sessionReadsList .row"); + const at = { privacy: "#sessionReadsList .row", general: "#sessionTerminalRow" }; + const where = (tab) => t("Settings") + " › " + $("#setTab-" + tab).textContent; + go.onclick = (e) => { + if (!sessionTerminalShows(prefs)) return openSettingsAt(e, "privacy", at.privacy); + e.stopPropagation(); + if (go.classList.contains("open")) return closeProtoMenu(); + openProtoMenu(go, [{ v: "privacy", name: "Agents' session history", note: where("privacy") }, { v: "general", name: "Session terminal", note: where("general") }], + null, (v, ev) => openSettingsAt(ev, v, at[v]), "Settings", "sess-menu", "right"); + }; h.append(q, sel, tr, go); return h; } diff --git a/internal/gui/assets/plugins/sessions/settings.js b/internal/gui/assets/plugins/sessions/settings.js index 62bea7dea..069b8d6ef 100644 --- a/internal/gui/assets/plugins/sessions/settings.js +++ b/internal/gui/assets/plugins/sessions/settings.js @@ -4,12 +4,15 @@ // status), and before start.js draws Settings; drawn whether the plugin is // on or off. +// a Mac's, and Windows' and Linux's when a terminal is found there; the +// Sessions page's Settings › asks it too +window.sessionTerminalShows = (s) => !web && (document.body.classList.contains("mac") || !!s?.terminalApps?.length); + function renderSessionTerminal(s, keep) { const row = $("#sessionTerminalRow"); - // a Mac's, and Windows' and Linux's when a terminal is found there const mac = document.body.classList.contains("mac"); const apps = [...(s.terminalApps || [])]; - row.hidden = web || !mac && !apps.length; + row.hidden = !sessionTerminalShows(s); if (row.hidden) return; const select = $("#sessionTerminalSelect"); if (mac && !apps.some((app) => app.id === "com.apple.Terminal")) apps.unshift({ id: "com.apple.Terminal", name: "Terminal" }); diff --git a/internal/gui/tests/sessions-to-settings.test.cjs b/internal/gui/tests/sessions-to-settings.test.cjs index d7a70ab18..ad3f3dbca 100644 --- a/internal/gui/tests/sessions-to-settings.test.cjs +++ b/internal/gui/tests/sessions-to-settings.test.cjs @@ -3,7 +3,10 @@ // and the Sessions page it is about didn't lead there once its first ask was // answered (the scattered settings audit after netube99 on X). Its head now // has a Settings › that opens Privacy at those rows, lit, with Back to -// Sessions; gateway mode, which reads no agent's history, has none. Every +// Sessions; gateway mode, which reads no agent's history, has none. Where +// a session can open in a terminal (a Mac, or a terminal found), General's +// Session terminal is Sessions' too, so Settings › is a menu of both, and +// each reaches its row lit. Every // language, Chromium and WebKit, at 1100 and 420 wide, nothing past the // window's edge or over the head's other buttons. const assert = require("node:assert/strict"); @@ -49,8 +52,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", test(`${engine} ${lang} ${width}: Sessions leads to Settings › Privacy's session history`, async (t) => { const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); t.after(() => browser.close()); - const open = async (gateway) => { + const open = async (gateway, platform = "Linux x86_64") => { const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage(); + await page.addInitScript((p) => Object.defineProperty(Navigator.prototype, "platform", { get: () => p }), platform); page.setDefaultTimeout(6000); page.setDefaultNavigationTimeout(60000); page.errors = []; @@ -89,6 +93,30 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.locator("#view-sessions .sm-head").waitFor(); assert.deepEqual(page.errors, []); + // on a Mac a session opens in a terminal: Settings › names both + // places, and each one reaches its row, lit, the page unmoved + for (const [tab, row, name] of [["privacy", "#sessionReadsList .row", "Agents' session history"], ["general", "#sessionTerminalRow", "Session terminal"]]) { + page = await open(false, "MacIntel"); + const top = await page.locator(".sm-head").evaluate((h) => h.getBoundingClientRect().top); + await page.locator(".sm-head .sm-toset").click(); + const menu = page.locator(".proto-menu"); + await menu.waitFor(); + const items = menu.locator(".pm-item"); + assert.equal(await items.count(), 2); + assert.deepEqual(await items.locator(".pm-name").allTextContents(), [await tr(page, "Agents' session history"), await tr(page, "Session terminal")]); + assert.equal(await page.locator(".sm-head").evaluate((h) => h.getBoundingClientRect().top), top, "opening the menu moved nothing"); + const mb = await menu.boundingBox(); + assert(mb.x >= 0 && mb.x + mb.width <= width + 1, "the menu inside the window"); + const set = (await tr(page, "Settings")) + " › " + await page.locator("#setTab-" + tab).textContent(); + const item = items.filter({ has: page.locator(".pm-name", { hasText: await tr(page, name) }) }); + assert.equal(await item.locator(".pm-note").textContent(), set); + await item.click(); + await page.locator(`#view-settings ${row}.flash`).first().waitFor(); + assert.equal(await page.locator("#setTab-" + tab).getAttribute("aria-selected"), "true"); + assert.equal(await page.evaluate(() => document.scrollingElement.scrollTop), 0, "the window itself is not scrolled"); + assert.deepEqual(page.errors, []); + } + // gateway mode reads no agent's history: no link page = await open(true); assert.equal(await page.locator(".sm-head .sm-toset").isVisible(), false, "no Settings › in gateway mode");