Skip to content

feat(webui): the user menu can stop the local server - #13

Merged
UncleMoc merged 2 commits into
mainfrom
feat/user-menu-stops-the-local-server
Nov 10, 2026
Merged

UncleMoc merged 2 commits into
mainfrom
feat/user-menu-stops-the-local-server

Conversation

@stevenjj33

Copy link
Copy Markdown
Contributor

What it adds

The user menu gets a 关闭本地服务 item. It asks first — an alertdialog with 取消 / 关闭服务 — and the answer is what asks the service to stop. The launcher then ends the run the way Ctrl+C does: the same close() chain, the same exit.

Why it is shaped this way

The service owns its listener, not the process. The host that assembled the service owns the process (the npm launcher starts the service in the same process and owns the exit), so the shutdown route is a request: it answers, and then asks the host to stop. A host that has no such answer — the service embedded in the desktop app, whose process is not the server's to end — refuses the route with 404 rather than pretending, and the dialog says the WebUI does not support stopping.

The credential is required even on loopback. Every other route drops the credential on loopback in development mode, but this one ends the process: "any local process can stop the server" is not a privilege the ordinary routes hand out. The page presents the credential it was served with — the same one the transfer routes use.

The answer goes out before the host stops. The route answers 200 {"ok":true,"closing":true} and stops the host a moment later. A request refused by a closed listener reads as a crash to the page that asked.

The parts

  • packages/webui/src/server/http/shutdown.ts — the route.
  • packages/webui/src/server/http/router.ts — the route, and the host's answer in the router context.
  • packages/webui/src/server/service.ts — the host's answer as a service option.
  • release/webui-npm/bin/mcode-webui.mjs — the launcher hands its own close() down.
  • packages/webui/src/client/platform/webui-shutdown.ts — the browser IO.
  • packages/webui/src/client/bindings/use-webui-shutdown.ts — the React edge to it: a feature's presentation does not call an IO port, so the binding is the door between the two.
  • packages/webui/src/client/features/account/ui/UserMenu.tsx — the item and the confirmation.
  • packages/webui/test/browser/user-menu-shutdown.spec.mjs — the confirmation, end to end against the built client.

Known limitation

The item is shown wherever the menu is shown. A host without the route answers 404 and the dialog says the WebUI does not support stopping. Hiding the item instead would need the served page to say what its host supports, which is a capability flag this change does not add.

@UncleMoc UncleMoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permission probe

@UncleMoc

Copy link
Copy Markdown
Collaborator

(Automated permission probe — please ignore. A review comment reading "permission probe" was posted while checking whether this account can review. It carries no review of the change; no approve or request-changes was intended.)

@stevenjj33
stevenjj33 force-pushed the feat/user-menu-stops-the-local-server branch from 38241f6 to 65e92d3 Compare November 10, 2026 04:43
The user menu gets a item that asks first and then asks the service to stop.
The service owns its listener, not the process, so the route is a request: it
answers and then asks the host to stop. A host with no such answer refuses
the route instead of pretending, and the credential is required even on
loopback because ending the process is not a privilege the ordinary routes
hand out.
The shutdown feature adds three source paths and changes the account menu's rendered vocabulary, so the frozen path metadata, the presentation coverage review and the public source inventory all have to say so before the gates accept the change.
@stevenjj33
stevenjj33 force-pushed the feat/user-menu-stops-the-local-server branch from 66a3030 to 183203b Compare November 10, 2026 05:57
@UncleMoc
UncleMoc merged commit 30f359f into main Nov 10, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants