Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Window frame: the traffic lights move into the bar only beside a page that draws it (#4006)
Omkar Satpute46fcf2c0e83b
diff --git a/electron/chrome-rail.d.mts b/electron/chrome-rail.d.mtsindex 045d0e6ac2..2dbb2e5796 100644--- a/electron/chrome-rail.d.mts+++ b/electron/chrome-rail.d.mts@@ -5,15 +5,19 @@ export declare const RAIL_OFFER_GRACE_MS: number;* person hid it. Never the places on it. */export interface ChromeRailState { available: boolean; hidden: boolean }/** `window.ogb.rail`. The page beside the rail offers the button that hides and shows it: `state()` from a document is- * that offer, and main hides the rail only beside a document that made it. `expand` and `onSkin` are the rail's own- * page's, on this app's pages only. Each is absent on an older app. */+ * that offer, and main hides the rail only beside a document that made it. `drawsFrame()` from a document says it draws+ * the window's frame, so main puts the traffic lights in its top bar. `expand`, `onSkin` and `onFramed` are the rail's+ * own page's, on this app's pages only. Each is absent on an older app. */export interface ChromeRailBridge {state?(): Promise<ChromeRailState>;+ drawsFrame?(): Promise<void>;/** From the person's click. */setHidden?(hidden: boolean): Promise<ChromeRailState>;onState?(callback: (state: ChromeRailState) => void): () => void;expand?(on: boolean): Promise<void>;onSkin?(callback: (skin: string) => void): () => void;+ /** Whether the page beside the rail draws the window's frame, as main hears it. */+ onFramed?(callback: (framed: boolean) => void): () => void;}export interface ChromeRail {attach(window: unknown): void;@@ -21,6 +25,7 @@ export interface ChromeRail {expand(on: boolean): void;owns(event: unknown): boolean;shown(): boolean;+ framed(): boolean;expanded(): boolean;send(channel: string, ...values: unknown[]): void;install(ipcMain: { handle(channel: string, handler: (...args: any[]) => unknown): void }): void;diff --git a/electron/chrome-rail.mjs b/electron/chrome-rail.mjsindex 3187c4c13b..2945187550 100644--- a/electron/chrome-rail.mjs+++ b/electron/chrome-rail.mjs@@ -7,14 +7,22 @@// sheets (+, the list past eight) open over the whole window: while one is open the view covers the window,// transparent but for the sheet, and goes back to its strip when it closes.//+// The page beside the rail draws the window's frame (its top bar, with the traffic lights in it) when it says so, as each+// document does once it is on screen. One that doesn't, a Cloud or a server of the person's own on an older release,+// gets the window as that release made it: the traffic lights back where it left room for them, and the rail's places+// under them. A new document has the same few seconds as for the button before the window changes back.+//// The person may hide it with a button on the page beside it. That page may be a Cloud or a server of their own on an// older release with no such button, so the rail hides only beside a document that offered one; a new document has a// few seconds to offer it, and the rail comes back beside one that doesn't, or that stops responding.+import { TRAFFIC_LIGHTS } from "./window-chrome.mjs";+export const CHROME_RAIL_WIDTH = 36;export const CHROME_RAIL_PATH = "/rail";-/** How long a rail the person hid stays hidden for the page's next document to offer its button. */+/** How long a rail the person hid stays hidden, and a framed window stays framed, for the page's next document. */export const RAIL_OFFER_GRACE_MS = 5_000;+/** Chromium's net::ERR_ABORTED: a load replaced by another, not a page that failed. */const ABORTED = -3;@@ -34,6 +42,8 @@ const ABORTED = -3;*/export function createChromeRail({ createView, preload, args, url, wanted, prefs = () => null, changed = () => {}, log = () => {} }) {let view = null, win = null, shown = false, expanded = false;+ // Whether the page beside draws the frame; the window opens as if it does (windowChromeOptions).+ let framed = true, frameGrace = null;// The document beside the rail offered its button; a new one may still (`grace`); the page stopped responding.let offered = false, grace = null, hung = false, told = "";const alive = () => Boolean(win && !win.isDestroyed());@@ -61,11 +71,25 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefsstopGrace();grace = setTimeout(() => { grace = null; rail.refresh(); }, RAIL_OFFER_GRACE_MS);};+ /** The traffic lights where the page beside makes room for them (macOS only), and the rail's page told. */+ const frameDrawn = (next) => {+ clearTimeout(frameGrace); frameGrace = null;+ if (next === framed) return;+ framed = next;+ if (alive()) win.setWindowButtonPosition?.(framed ? TRAFFIC_LIGHTS.framed : TRAFFIC_LIGHTS.unframed);+ rail.send("rail:framed", framed);+ };+ /** A framed window stays framed while the next document has its few seconds to say it draws the frame too. */+ const awaitFrame = () => {+ clearTimeout(frameGrace);+ frameGrace = framed ? setTimeout(() => frameDrawn(false), RAIL_OFFER_GRACE_MS) : null;+ };/** The page beside the rail has another document, or lost the one it had. */const nextDocument = () => {const keep = hidden();offered = false; hung = false; told = "";if (keep) startGrace(); else stopGrace();+ awaitFrame();rail.refresh();};/** The page beside the rail asks: the window's own page, in its main frame (never a frame inside it). */@@ -80,6 +104,7 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefscontents.on("will-navigate", stay);contents.on("will-redirect", stay);contents.on("render-process-gone", () => { log("chrome rail: its page went away; loading it again"); void contents.loadURL(url()).catch(() => {}); });+ contents.on("did-finish-load", () => contents.send("rail:framed", framed));void contents.loadURL(url()).catch((error) => log(`chrome rail: ${error?.message ?? error}`));return view;};@@ -88,8 +113,9 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefsattach(next) {win = next;shown = false; expanded = false; offered = false; hung = false; told = "";- // The window's first document has the same time as any other to offer the button.+ // The window's first document has the same time as any other to offer the button and to draw the frame.if (choseHidden()) startGrace(); else stopGrace();+ awaitFrame();win.on("resize", layout);const contents = win.webContents;// Each new document is told again, once it is ready.@@ -102,7 +128,7 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefscontents.on("responsive", () => { hung = false; rail.refresh(); });win.once("closed", () => {if (view && !view.webContents.isDestroyed()) view.webContents.close?.({ waitForBeforeUnload: false });- stopGrace();+ stopGrace(); clearTimeout(frameGrace); frameGrace = null;view = null; win = null; shown = false; expanded = false; offered = false;});rail.refresh();@@ -138,6 +164,7 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefs/** The rail's own page asks (never a place's page). */owns: (event) => Boolean(view && event?.sender === view.webContents && event.senderFrame === view.webContents.mainFrame),shown: () => shown,+ framed: () => framed,expanded: () => expanded,/** The rail's page asks for the whole window while a sheet of its own is open, and gives it back after. The page* beside it offers the button that hides and shows it; asking is the offer, made again by each document. */@@ -158,6 +185,10 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefs});fromPage("rail:offer", () => {});fromPage("rail:hide", (hide) => prefs()?.setRailHidden(hide === true));+ ipcMain.handle("rail:draws-frame", (event) => {+ if (!pageBeside(event)) throw new Error("rail:draws-frame is only available to the page beside the window's rail");+ frameDrawn(true);+ });},/** Tells the rail's page something (the places changed, the skin of the page beside it). */send(channel, ...values) {diff --git a/electron/chrome-rail.node-test.mjs b/electron/chrome-rail.node-test.mjsindex 1740cd9117..1800c16e5a 100644--- a/electron/chrome-rail.node-test.mjs+++ b/electron/chrome-rail.node-test.mjs@@ -5,6 +5,7 @@ import test from "node:test";import vm from "node:vm";import { CHROME_RAIL_PATH, CHROME_RAIL_WIDTH, RAIL_OFFER_GRACE_MS, createChromeRail } from "./chrome-rail.mjs";+import { TRAFFIC_LIGHTS } from "./window-chrome.mjs";const RAIL = "http://127.0.0.1:8799/rail";@@ -13,8 +14,8 @@ function appWindow() {const page = Object.assign(new EventEmitter(), { mainFrame: { id: "page-frame" }, told: [], states: [], destroyed: false,send(channel, value) { if (channel === "rail:beside") this.told.push(value); if (channel === "rail:state") this.states.push(value); }, isDestroyed() { return this.destroyed; } });const children = [];- const win = Object.assign(new EventEmitter(), { webContents: page, size: [1440, 900], destroyed: false,- getContentSize() { return this.size; }, isDestroyed() { return this.destroyed; },+ const win = Object.assign(new EventEmitter(), { webContents: page, size: [1440, 900], destroyed: false, lights: [],+ getContentSize() { return this.size; }, isDestroyed() { return this.destroyed; }, setWindowButtonPosition(point) { this.lights.push(point); },contentView: { addChildView: (view) => children.push(view), removeChildView: (view) => children.splice(children.indexOf(view), 1) } });return { win, page, children };}@@ -174,6 +175,32 @@ test("after the page moves on, a hidden rail waits a few seconds for the new pagassert.deepEqual([w.rail.shown(), w.page.told.at(-1)], [false, 0], "until that one offers its button");});+test("the traffic lights sit in the frame's top bar beside a page that draws it, and go back where an older release left room for them", (t) => {+ t.mock.timers.enable({ apis: ["setTimeout"] });+ const w = world();+ w.rail.attach(w.win);+ const framed = () => w.made[0].webContents.sent.filter(([channel]) => channel === "rail:framed").map(([, value]) => value);+ t.mock.timers.tick(RAIL_OFFER_GRACE_MS - 1);+ w.ask("rail:draws-frame");+ t.mock.timers.tick(RAIL_OFFER_GRACE_MS);+ assert.deepEqual([w.rail.framed(), w.win.lights, framed()], [true, [], []], "this app's page draws the frame in time: the window stays as it opened");+ w.page.emit("did-navigate");+ t.mock.timers.tick(RAIL_OFFER_GRACE_MS - 1);+ assert.equal(w.rail.framed(), true, "still time for the next page");+ t.mock.timers.tick(1);+ assert.deepEqual([w.rail.framed(), w.win.lights, framed()], [false, [TRAFFIC_LIGHTS.unframed], [false]],+ "an older Cloud's page, which never says so: the lights go back to its row, and the rail's places under them");+ w.made[0].webContents.emit("did-finish-load");+ assert.deepEqual(framed(), [false, false], "the rail's page, loaded again, hears it too");+ w.page.emit("did-navigate");+ w.ask("rail:draws-frame");+ assert.deepEqual([w.rail.framed(), w.win.lights.at(-1), framed().at(-1)], [true, TRAFFIC_LIGHTS.framed, true], "the next page draws it: back in the bar at once");+ const [view] = w.made;+ for (const event of [{ sender: view.webContents, senderFrame: view.webContents.mainFrame }, { sender: w.page, senderFrame: { id: "an-iframe" } }, {}]) {+ assert.throws(() => w.handlers.get("rail:draws-frame")(event), /only available to the page beside the window's rail/);+ }+});+test("a page that stops responding, crashes or gives way to an error page gets the rail back", (t) => {t.mock.timers.enable({ apis: ["setTimeout"] });const w = world({ hidden: true });@@ -266,16 +293,17 @@ test("the rail's own page keeps its size at any zoom of this app's page (Chromiu}});-test("every page beside the rail, from any server, gets the button's bridge and learns only whether there is a rail to hide; the rail's own channels stay this app's", async () => {+test("every page beside the rail, from any server, gets the button's bridge, learns only whether there is a rail to hide, and says when it draws the frame; the rail's own channels stay this app's", async () => {const remote = pageWithPreload("https://bots.example.test", "/", (channel) => (channel === "rail:offer" ? { available: "yes", hidden: 1, places: [{ id: "home" }] } : { available: true, hidden: true }));- assert.deepEqual(Object.keys(remote.bridge.rail), ["state", "setHidden", "onState"]);+ assert.deepEqual(Object.keys(remote.bridge.rail), ["state", "drawsFrame", "setHidden", "onState"]);/** A value made in the page's own context, as this one sees it. */const plain = (value) => JSON.parse(JSON.stringify(value));assert.deepEqual(plain(await remote.bridge.rail.state()), { available: false, hidden: false }, "two plain answers, nothing else main might send");await assert.rejects(remote.bridge.rail.setHidden(true), /Choose to hide or show/, "a server's page hides it only from the person's click");remote.navigator.userActivation.isActive = true;assert.deepEqual(plain(await remote.bridge.rail.setHidden(true)), { available: true, hidden: true });- assert.deepEqual(plain(remote.invoked), [["rail:offer"], ["rail:hide", true]]);+ await remote.bridge.rail.drawsFrame();+ assert.deepEqual(plain(remote.invoked), [["rail:offer"], ["rail:hide", true], ["rail:draws-frame"]]);const heard = [];const stop = remote.bridge.rail.onState((state) => heard.push(state));remote.hear("rail:state", { available: true, hidden: false, places: ["home"] });@@ -283,7 +311,14 @@ test("every page beside the rail, from any server, gets the button's bridge andremote.hear("rail:state", { available: true, hidden: true });assert.deepEqual(plain(heard), [{ available: true, hidden: false }]);const local = pageWithPreload("http://127.0.0.1:8799", "/");- assert.deepEqual(Object.keys(local.bridge.rail), ["state", "setHidden", "onState", "expand", "onSkin"]);+ assert.deepEqual(Object.keys(local.bridge.rail), ["state", "drawsFrame", "setHidden", "onState", "expand", "onSkin", "onFramed"]);+ const framed = [];+ const unheard = local.bridge.rail.onFramed((value) => framed.push(value));+ local.hear("rail:framed", false);+ local.hear("rail:framed", "yes");+ unheard();+ local.hear("rail:framed", true);+ assert.deepEqual(framed, [false, false], "only true is framed");await local.bridge.rail.setHidden(false);assert.deepEqual(plain(local.invoked), [["rail:hide", false]], "this app's own page, as for its other choices");});diff --git a/electron/preload.cjs b/electron/preload.cjsindex 355e8a8708..1256055d7b 100644--- a/electron/preload.cjs+++ b/electron/preload.cjs@@ -158,10 +158,12 @@ const bridge = {},},// The window's own rail (this app's page at /rail, beside every place's page): while a sheet of its own is open it- // covers the window; the skin of the page beside it comes from main. The page beside it, from whichever server,- // offers the button that hides and shows it, and learns only whether there is one to hide, never its places.+ // covers the window; the skin of the page beside it comes from main, and whether that page draws the window's frame.+ // The page beside it, from whichever server, offers the button that hides and shows it, and learns only whether there+ // is one to hide, never its places; it says when it draws the frame, so main puts the traffic lights in its top bar.rail: {state: () => ipcRenderer.invoke("rail:offer").then(railState),+ drawsFrame: () => ipcRenderer.invoke("rail:draws-frame"),setHidden: (hidden) => isLocalPage || navigator.userActivation?.isActive === true? ipcRenderer.invoke("rail:hide", hidden === true).then(railState) : Promise.reject(new Error("Choose to hide or show your computers.")),onState: (cb) => {@@ -176,6 +178,11 @@ const bridge = {ipcRenderer.on("rail:skin", handler);return () => ipcRenderer.removeListener("rail:skin", handler);},+ onFramed: (cb) => {+ const handler = (_event, framed) => cb(framed === true);+ ipcRenderer.on("rail:framed", handler);+ return () => ipcRenderer.removeListener("rail:framed", handler);+ },} : {}),},// Buying another Cloud from the rail's +, on this app's page or a hosted Cloud's: plain words in, what the sheet saysdiff --git a/electron/window-chrome.mjs b/electron/window-chrome.mjsindex 45796c7cc5..fe9d7ed724 100644--- a/electron/window-chrome.mjs+++ b/electron/window-chrome.mjs@@ -5,10 +5,14 @@ export function windowBackground(prefersDark) {return prefersDark ? "#121212" : "#fcfcfc";}-/** macOS: the traffic lights (14px) centred in the page's 28px top bar (src/components/WindowFrameBar.tsx), 12px in. */+/** macOS: where the traffic lights (14px) sit. In the frame's 28px top bar, 12px in, while the page beside the rail draws+ * that frame (src/components/WindowFrameBar.tsx); where an older page made room for them otherwise. The window opens with+ * them in the bar, and main moves them as each page says (chrome-rail.mjs). */+export const TRAFFIC_LIGHTS = { framed: { x: 12, y: 7 }, unframed: { x: 16, y: 16 } };+export function windowChromeOptions(platform) {if (platform === "darwin") {- return { titleBarStyle: "hiddenInset", trafficLightPosition: { x: 12, y: 7 } };+ return { titleBarStyle: "hiddenInset", trafficLightPosition: TRAFFIC_LIGHTS.framed };}if (platform === "win32") {return { titleBarStyle: "hidden" };diff --git a/src/components/PlacesRail.frame.test.ts b/src/components/PlacesRail.frame.test.tsnew file mode 100644index 0000000000..c0028aa682--- /dev/null+++ b/src/components/PlacesRail.frame.test.ts@@ -0,0 +1,54 @@+// @vitest-environment happy-dom+import { act, createElement } from "react";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, expect, it, vi } from "vitest";+import type { RailState } from "../../electron/cloud-rail.mjs";++const fixture = vi.hoisted(() => ({ windowChrome: "mac-inset" as "mac-inset" | "win-caption" }));+vi.mock("@/lib/analytics", () => ({ track: vi.fn() }));+vi.mock("./DesktopCapabilities", async (importOriginal) => ({+ ...await importOriginal<typeof import("./DesktopCapabilities")>(),+ useDesktopCapabilities: () => ({ capabilities: { windowChrome: fixture.windowChrome }, ready: true }),+}));++import { setLocale } from "@/lib/i18n";+import { refreshPlaces } from "@/lib/places";+import { PlacesRail } from "./PlacesRail";++(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;+let host: HTMLDivElement, root: Root | null = null;+let tell: (framed: boolean) => void = () => {};+const rail: RailState = { places: [{ id: "home", name: "My Cloud", color: null, kind: "cloud", opens: true, active: true }], add: { cloud: true, link: false, address: false } };++beforeEach(() => {+ setLocale("en");+ Object.assign(window, { ogb: {+ workspaces: { places: async () => rail, onChanged: () => () => {} },+ rail: { expand: async () => {}, onSkin: () => () => {}, onFramed: (callback: (framed: boolean) => void) => { tell = callback; return () => {}; } },+ } });+ host = document.createElement("div");+ document.body.append(host);+});+afterEach(async () => { await act(async () => root?.unmount()); root = null; host.remove(); });++async function mount() {+ root = createRoot(host);+ await act(async () => { await refreshPlaces(); root!.render(createElement(PlacesRail, { chrome: true })); });+}+const above = () => host.querySelector("[data-places-rail] > div[aria-hidden]")!.className;++it("starts its places under the frame's top bar while the page beside draws it, and under the traffic lights' old place beside an older page", async () => {+ await mount();+ expect(above(), "the window opens framed").toContain("h-[37px]");+ await act(async () => tell(false));+ expect(above(), "macOS: under the traffic lights where an older release put them").toContain("h-[52px]");+ await act(async () => tell(true));+ expect(above()).toContain("h-[37px]");+});++it("on Windows beside an older page, keeps that release's small gap: there are no traffic lights", async () => {+ fixture.windowChrome = "win-caption";+ await mount();+ await act(async () => tell(false));+ expect(above()).toContain("h-3");+});diff --git a/src/components/PlacesRail.tsx b/src/components/PlacesRail.tsxindex c1172eff48..5ca9f8cf4d 100644--- a/src/components/PlacesRail.tsx+++ b/src/components/PlacesRail.tsx@@ -14,6 +14,7 @@ import { cloudColor, cloudColorFill } from "@/lib/cloud-look";import { activeLocale, t } from "@/lib/i18n";import { localizedRelativeTime } from "@/lib/memory";import { useAdvancedMode } from "@/lib/interface-mode";+import { useBesideFramed } from "@/lib/chrome-rail";import { makeHome, placeInitials, recolorPlace, removePlace, usePlaces, type RailPlace } from "@/lib/places";import { useDesktopCapabilities, windowFramed } from "./DesktopCapabilities";import { MENU_ROW, MENU_SHEET } from "./menu-recipe";@@ -242,6 +243,7 @@ export function PlacesRail({ chrome = false }: { chrome?: boolean }) {const state = usePlaces();const calm = !useAdvancedMode();const { capabilities } = useDesktopCapabilities();+ const besideFramed = useBesideFramed();const [more, setMore] = useState(false);const [adding, setAdding] = useState(false);const [connecting, setConnecting] = useState<string | null>(null);@@ -268,6 +270,10 @@ export function PlacesRail({ chrome = false }: { chrome?: boolean }) {void bridge?.open?.(place.id).catch(() => {});};const framed = windowFramed(capabilities.windowChrome), draggable = framed;+ // In a framed window the rail is part of the frame: the window's own rail runs the full height, its top in the frame's+ // top bar (the traffic lights' place), so its places start under that bar. Beside a page that doesn't draw the frame+ // (an older release), they start where that release left them: under the traffic lights' old place on macOS.+ const above = !framed ? "h-3" : !chrome ? "h-[9px]" : besideFramed ? "h-[37px]" : capabilities.windowChrome === "mac-inset" ? "h-[52px]" : "h-3";// SAFETY: Electron's -webkit-app-region is not in React's CSSProperties type; the renderer accepts it as an inline style.const drag = draggable ? ({ WebkitAppRegion: "drag" } as CSSProperties) : undefined;const noDrag = draggable ? ({ WebkitAppRegion: "no-drag" } as CSSProperties) : undefined;@@ -280,9 +286,7 @@ export function PlacesRail({ chrome = false }: { chrome?: boolean }) {};return <nav ref={navRef} aria-label={t("rail.label")} data-places-rail style={drag}className={cn("relative w-9 shrink-0 flex-col items-center bg-frame", chrome ? "flex h-full" : "hidden md:flex", !framed && (calm ? "border-r border-ink/[0.04]" : "border-r border-hairline/50"))}>- {/* In a framed window the rail is part of the frame: the window's own rail runs the full height, its top in the- frame's top bar (the traffic lights' place), so its places start under that bar. */}- <div aria-hidden="true" className={!framed ? "h-3 shrink-0" : chrome ? "h-[37px] shrink-0" : "h-[9px] shrink-0"} />+ <div aria-hidden="true" className={cn(above, "shrink-0")} /><ul className="flex min-h-0 flex-col items-center gap-2 overflow-y-auto py-[3px]" style={noDrag}>{shown.map((place) => <li key={place.id} className="flex"><PlaceTile place={place} calm={calm} canPair={canPair} onOpen={open} onMenu={openMenu} />diff --git a/src/components/WindowFrameBar.test.ts b/src/components/WindowFrameBar.test.tsindex 8a50f727a3..ed781dc925 100644--- a/src/components/WindowFrameBar.test.ts+++ b/src/components/WindowFrameBar.test.ts@@ -10,8 +10,9 @@ const fixture = vi.hoisted(() => ({rail: { available: true, hidden: false } as { available: boolean; hidden: boolean } | null,update: null as UpdaterState | null,dispatch: vi.fn(),+ frameDrawn: vi.fn(),}));-vi.mock("@/lib/chrome-rail", () => ({ useChromeRail: () => fixture.rail, setChromeRailHidden: () => {} }));+vi.mock("@/lib/chrome-rail", () => ({ useChromeRail: () => fixture.rail, setChromeRailHidden: () => {}, sayFrameDrawn: fixture.frameDrawn }));vi.mock("@/lib/updater", () => ({ useUpdaterState: () => fixture.update }));vi.mock("@/state/store", () => ({ useStore: () => ({ state: {}, dispatch: fixture.dispatch }) }));vi.mock("./DesktopCapabilities", async (importOriginal) => ({@@ -34,6 +35,7 @@ beforeEach(() => {fixture.rail = { available: true, hidden: false };fixture.update = null;fixture.dispatch.mockClear();+ fixture.frameDrawn.mockClear();});afterEach(async () => { await act(async () => root?.unmount()); root = null; host.remove(); });@@ -64,6 +66,15 @@ describe("the window frame's top bar", () => {expect(bar()).toBeNull();});+ it("tells main it draws the frame, so the traffic lights move into its bar; a window with its own title bar says nothing", async () => {+ await mount(createElement(WindowFrameBar));+ expect(fixture.frameDrawn).toHaveBeenCalledTimes(1);+ await act(async () => root!.unmount());+ fixture.windowChrome = "native";+ await mount(createElement(WindowFrameBar));+ expect(fixture.frameDrawn).toHaveBeenCalledTimes(1);+ });+it("opens the app's settings", async () => {await mount(createElement(WindowFrameBar));await act(async () => bar()!.querySelector<HTMLButtonElement>("[data-frame-settings]")!.click());diff --git a/src/components/WindowFrameBar.tsx b/src/components/WindowFrameBar.tsxindex 803d513f52..21ca75120c 100644--- a/src/components/WindowFrameBar.tsx+++ b/src/components/WindowFrameBar.tsx@@ -1,5 +1,8 @@import { Settings } from "lucide-react";+import { useEffect } from "react";++import { sayFrameDrawn } from "@/lib/chrome-rail";import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";import { useStore } from "@/state/store";@@ -18,8 +21,9 @@ export const FRAME_BAR_BUTTON = "flex size-[22px] shrink-0 items-center justify-export function WindowFrameBar() {const { capabilities } = useDesktopCapabilities();const { dispatch } = useStore();- const chrome = capabilities.windowChrome;- if (!windowFramed(chrome)) return null;+ const chrome = capabilities.windowChrome, framed = windowFramed(chrome);+ useEffect(() => { if (framed) sayFrameDrawn(); }, [framed]);+ if (!framed) return null;const { dragProps } = captionChrome(chrome);return (<divdiff --git a/src/lib/chrome-rail.ts b/src/lib/chrome-rail.tsindex 2e900fe9ff..48d1b984f9 100644--- a/src/lib/chrome-rail.ts+++ b/src/lib/chrome-rail.ts@@ -33,6 +33,19 @@ export function useChromeRail(): ChromeRailState | null {return state;}+/** On the rail's own page: whether the page beside it draws the window's frame, as main hears from each of its documents.+ * The window opens framed. */+export function useBesideFramed(): boolean {+ const [framed, setFramed] = useState(true);+ useEffect(() => bridge()?.onFramed?.(setFramed), []);+ return framed;+}++/** The page beside the rail draws the window's frame: main puts the traffic lights in its top bar. */+export function sayFrameDrawn(): void {+ void bridge()?.drawsFrame?.()?.catch(() => {});+}+/** From the person's click: main hides or shows the rail, and this desktop keeps the choice. */export function setChromeRailHidden(hidden: boolean): void {const rail = bridge(), before = current;