Repository navigation
Conversation
local-gateway:get/set answered any window, and a connection window to another machine shares the preload that exposes them, so a page served by a remote gateway could switch off this machine's own gateway for the next launch. Both channels now take assertMainWindowDashboard, the check the close-action and tray rows already use, which keeps the row working on a main window connected to a remote host. The settings hook hides the switch when the read is refused and puts it back when a write is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Motivation
Goal: Only the desktop app's main window can read or change whether this machine runs a local gateway; a connection window to another machine cannot.
local-gateway:getandlocal-gateway:setinwebsite/electron/ipc-registrar.jsanswer any sender. They back the "Run a local gateway" switch in Settings > Developer, a next-launch choice stored in the app's own config.preload.jsexposeswindow.localGatewayAPIto every window, including connection windows pointed at another machine's gateway. So a page that gateway serves can calllocalGatewayAPI.set(false)and stop this machine's gateway from starting at the next launch. #37764 gated the theme listeners and named this channel as left for a separate change.Why it matters
The choice is about this computer, and a remote page should not be able to make it. Every other machine-level bridge is withheld from remote-gateway windows. The three comparable preference rows (close action, tray icon, minimize to tray) already take
assertMainWindowDashboard. This one row has no gate, and a flip only shows up at the next launch, when the local gateway silently does not start.Not a goal
localGatewayAPIfrom remote-gateway windows inpreload.js. A main window connected to a remote host must keep the switch, and that is where a person turns the local gateway off. The registrar gate keeps that case; a preloadREMOTE_GATEWAYcut would not.ipcMainlisteners that do not write this machine's settings.What changed (motivation → approach → change)
Details:
ipc-registrar.js: both handlers are nowasyncand callassertMainWindowDashboard(event, "local-gateway:get|set")first. The gate requires the main window's top frame on its own dashboard origin, local or remote. A refusal is logged throughlogGateRejectionand rejects with "... is restricted to the main window's dashboard".website/src/hooks/useLocalGateway.ts: a refused read hides the switch, since this window cannot know or change the value. A refused write puts the switch back instead of leaving it showing the requested value.Backwards compatibility
Compatible for the main window: the switch reads and writes as before, including when the main window is connected to a configured remote host.
Removes: a connection window's ability to read or write the choice.
Reader: website/src/pages/settings/DeveloperPanel.tsx:DeveloperPanel -- crew page -- in the main window it keeps working (
local-gateway channels answer the main window's dashboard, including on a remote gateway); in a connection window the switch is hidden (hides the switch when main.js refuses the read)Reader: website/src/hooks/useLocalGateway.ts:useLocalGateway -- crew page -- the only caller of the bridge; it handles both refusals (
useLocalGateway.test.ts)Tests
website/electron/test/ipc-registrar.test.js:local-gateway:getandlocal-gateway:setjoinMAIN_WINDOW_SETTING_CHANNELS. The four refusal sweeps now prove that both channels refuse another window, no window, a subframe, and a main window navigated off its dashboard.assertCloseActionRefusedalso checks that a refused sender never writesrunLocalGateway.local-gateway channels answer the main window's dashboard, including on a remote gateway.website/src/test/useLocalGateway.test.ts:hides the switch when main.js refuses the read, as it does for a connection windowandputs the switch back when main.js refuses the write. These replace the oldsurvives a rejecting bridge without losing its current value, which pinned the switch staying at the requested value after a refused write.Proof: not provable -- frontend test (prove.py runs Python only)
Negative control by hand on fix commit
6b1bbeeebd69:ipc-registrar.jsanduseLocalGateway.ts, 4 refusal sweeps fail ("main-window setting channels refuse every sender that is not the main window", "... a subframe ...", "... navigated off its dashboard", "... when there is no main window"), and so do both new hook tests.Locally (Windows 11):
node --test electron/test/ipc-registrar.test.js: 57 of 59 pass. The 2 failures aredashboard:open-file ...symlink tests that fail with EPERM on this unprivileged host, as on main.npx vitest run src/test/useLocalGateway.test.ts src/test/DeveloperPanel.test.tsx src/test/electronBridgeContract.test.ts: 19 passed.npx tsc --noEmit -p tsconfig.app.json: clean.Manual verification
Not done in a packaged desktop build. The registrar's own harness covers every sender shape the gate distinguishes: main window local, main window on a remote host, another window, no window, a subframe, and a navigated-away origin.
Real-machine verification
N/A -- I have no desktop build on this machine. The before/after above is the registrar harness on my own computer (Windows 11, Node), not a launched Electron app. A maintainer can confirm it in a connection window's devtools: on main,
await window.localGatewayAPI.set(false)resolves; on this head it rejects with "local-gateway:set is restricted to the main window's dashboard".Screenshots / video
Why no screenshot: the main window renders exactly as before, since its read and write still succeed. The one change is in a connection window, where the Developer switch is now hidden instead of offered. That window exists only in a packaged desktop build, which I do not have here.
useLocalGateway.test.tspins both outcomes.Related Issues
Fixes #39406
Sibling sweep
Swept: grep -n "ipcMain.handle("[a-z-]*:set"" website/electron/ipc-registrar.js
Sibling: website/electron/ipc-registrar.js -- changed here: local-gateway:set and local-gateway:get
Sibling: website/electron/preload.js -- not affected -- the bridge stays exposed so a main window on a remote host keeps the switch; the gate lives in main
Pattern harvest
Rule candidate: review-prompt
Pattern: "an ipcMain handler that writes this machine's app config without assertMainWindowDashboard or assertLocalDashboard"
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
🤖 Generated with Claude Code