Skip to content

feat(remote): remote controls, quick actions and the access dialog in the app - #84

Merged
teo-goulois merged 8 commits into
mainfrom
feat/remote-controls-ui
Nov 9, 2026
Merged

teo-goulois merged 8 commits into
mainfrom
feat/remote-controls-ui

Conversation

@teo-goulois

@teo-goulois teo-goulois commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

PR 4d of docs/remote-machines.md: the app's buttons for remote controls, the quick actions, and the access dialog.

What changed

Controls in the remote chip. Start/Stop and the menu's Restart call remote_control with the snapshot's expect (runId and configRev, plus legacyId for a relaunch). While it runs, a toast shows the progress ("Starting in the app on B…", or "…in the background…" when B's app is closed), unknown as "Outcome unknown. Checking B…", then the result. Refusals use the "Errors" wording through remoteErrorMessage. Each service has one control at a time. Leaving the machine's view closes its control streams and dismisses their toasts; events that arrive later, and streams whose opening resolves after that, are dropped or closed at once. No control is sent while the session is down: the button is disabled and says why ("Connecting to B…", "B: Offline", …).

It follows the remote_control stream as #83 now has it:

  • Without an open session, the stream is a single refused result with the connection state. not_connected, connecting and not_responding have their own messages ("Not connected to B.", "Still connecting to B. Try again once it is connected.", "B isn't responding right now."); peer_offline, not_paired and key_mismatch keep theirs, and unavailable shows the daemon's message ("The relay dropped a frame; try again in 3 s.").
  • A control never sent ends with that refused result, so its toast ends with the reason.
  • busy says "Something else is starting or stopping it on B. Try again in a moment." The control result carries no retryAfter, so the wait isn't given. too_many says "This Mac sent B too many controls lately. Try again later."
  • lost is read by its code: not_shared says "B stopped sharing before it said what happened."; not_paired / key_mismatch add the pairing message; anything else says "B didn't say what happened. The list shows its current state."
  • unknown keeps the toast on "Outcome unknown. Checking B…" until the result or lost, which the daemon now always sends. A result of unknown would end the toast with the lost text rather than "Checking B…".

Quick actions. A control that isn't allowed stays clickable and opens a card under the chip:

  • control_disabled / background_disabled on protocol 2: Ask B over the remote_access stream. With control off, an action that would run in the background on B asks for backgroundStarts, which turns control on too, in one request: a start while B's app is absent (machine.app == "absent"), or a restart (or relaunch) of a background run. Asking for control first would get background_disabled next, and a second request within 10 minutes gets too_many. The card's command follows the same choice (localify machines settings --control on --background-starts on). The contract's "Quick actions" says so now. It shows "Waiting for an answer on B…" with Cancel, then the outcome, including errors with retryAfter ("Try again in 9 min."). The card always shows "Or run this on B:" with the command and a copy button. On protocol 1, only the command shows, under "Update Localify on B to ask from here."
  • A legacy run with a legacyId on protocol 2 (refused legacy_run, its Restart, or Output's "Relaunch to share") gets Relaunch on B, after the contract's confirmation. With controls off, the card also shows "Or run this on B:" with the command, and the relaunch asks for access first, in a toast with Cancel. When that request ends without access (nobody, declined, an error), the toast stays, with the reason, "Or run this on B:", the command and Copy, until it is closed. Once access is granted, it relaunches only if the next snapshot still shows the same legacyId and configRev; otherwise it shows the confirmation again.
  • Any other code shows its message, with no action.

Access dialog on the target. The app subscribes to remote_events with access: true and shows the dialog in the contract's words:

  • The asker is named from the pin, with the first 8 characters of its fingerprint.
  • The question states the machine-wide scope, with the extra line for background starts.
  • The buttons are Allow / Don't allow, with "Don't ask again from X".

It answers with remote_access_answer and shows one request at a time (others wait in a queue). The dialog stays, with its buttons and checkbox off, until the answer is through or access_closed arrives. When the answer can't be sent, the error shows in the dialog and the request can be answered again, as long as it still waits; one closed meanwhile stays gone. Escape and clicks outside don't answer it. Focus lands on the dialog itself, not on a button, so someone typing in a terminal tab can't answer it by pressing Enter. A system notification is sent when the window isn't focused. The app never takes focus.

Settings → Remote access. The control and background-start switches now work. Control needs sharing, and background starts need control. Suppressed machines are listed with Allow requests again (remote_access_suppressed / remote_access_restore).

Leaving a machine's view closes a relaunch's "Waiting for an answer on B…" toast. Before, its stream was closed and its events dropped, so nothing closed the toast.

Removed. The "comes in a later version" texts, the disabled-only ControlButton and SwitchRow paths, and the "until PR 4d" notes in the DTOs, dto.rs and the contract.

Notification plugin. The notification is the one Rust change: tauri-plugin-notification ~2.3 (crate and JS, pinned so the JS side keeps @tauri-apps/api 2.10) and, in the capability, only the three permissions the plugin's window.Notification shim calls: notification:allow-is-permission-granted, notification:allow-request-permission and notification:allow-notify. The stream validator also gained the control kind. Without it, tauriClient would have rejected every control.

Pure logic is in desktop-ui/src/lib/util.remote-controls.ts: which quick action for which code, proto and app presence, building expect, message mapping, the relaunch re-confirm rule, the fingerprint label, and the access dialog's pending, answering and failed states. desktop-ui/src/lib/util.stream-registry.ts holds the control streams that are closed together.

How it was tested

  • pnpm run typecheck, pnpm desktop:test (54 tests: 20 in util.remote-controls.test.ts, including one that runs a built control through the stream validator, one for the backgroundStarts choice, one for the refusal and lost messages, and four for the access dialog's states; 5 in util.stream-registry.test.ts, for closing on leave, late openings, streams that ended by themselves, and a newer stream of the same service), and oxlint on desktop-ui/src.
  • After the review fixes (f38e4fd): those three again, and cargo clippy --locked --manifest-path src-tauri/Cargo.toml -- -D warnings with a sidecar copied in and removed afterwards. A bogus notification: permission fails that build, so the three names are checked.
  • cargo fmt --check for both crates. cargo clippy --locked -- -D warnings and cargo test --locked for the root crate. cargo clippy --locked --manifest-path src-tauri/Cargo.toml -- -D warnings and cargo test there, with a sidecar copied in and removed afterwards.
  • pnpm desktop:build.
  • After merging 74e7bc1, only pnpm run typecheck, pnpm desktop:test and oxlint were run again. The update changes no Rust, and the merge was clean: on the Rust side, feat(remote): remote controls, quick actions and the access dialog in the app #84 touches dto.rs comments and the plugin in src-tauri/src/lib.rs, and 74e7bc1 touches src-tauri/src/commands.rs. The cargo checks above were not repeated on the merged tree.

Not seen in a running app

None of this was run in the app or on two machines. The contract's gate for 4d (the access dialog end to end, on two machines) is still to do. Not seen:

  • the chip's card popover: where it sits, and whether it stays open when the menu's Restart opens it;
  • the toasts during a real control;
  • the access dialog and its focus behaviour, including a failed answer's error and the buttons coming back;
  • leaving a machine's view during a control, and coming back;
  • the relaunch's persistent toast with the command and Copy, and how its command box looks on the error toast's colours;
  • the macOS notification, including the permission prompt (dev builds may not show it);
  • the Settings switches against a daemon.

…ntrols

A paired machine can now start, stop and restart a service on a target
that allows it (PR 4c-2 of docs/remote-machines.md), through whoever owns
the service there.

Target: `control` and `control.status` in the remote actor. Checks 1 to 3
(pin and hello, share and control, a fresh lease) run in the actor; the
executor in infrastructure/remote/control.rs runs 4 to 9 off it: request
entries in services/requests/<peer>/<requestId>.json, published before
anything changes and kept 24 h, with request_mismatch for another
fingerprint; expiry, ids and profile, one control per service (busy), the
state and configRev, then the owner. Who acts follows the contract's table:
the app's bridge, a detached `localify dev ... --detach` started from the
daemon's own canonical executable with the shell environment, or a
refusal. A launch is followed to its record (dispatched, started, settled
within 90 s); an unanswered bridge launch waits for its expiry and is
reported from the record, never started again elsewhere.

Legacy relaunch: the inventory names a proven legacy run of the app or of
`dev --detach` with `legacyId`, and a restart with `expect.legacyId`
relaunches it through its owner. `localify dev --replace-legacy` refuses
under the run lock unless the record still names that legacy run, and the
app bridge passes `replacesLegacy` on instead of refusing it.

The inventory's controls now follow the switches and the app's presence,
so a granted access request shows in the next snapshot.

Viewer: `remote_control` streams sent, progress and the result, waits
120 s, and after a lost session reports unknown and asks control.status
on a new session, never resending. The desktop DTO and its TypeScript
mirror carry the stream; no screen uses it until PR 4d.
… the app

The app now starts, stops and restarts services on another machine, and
answers access requests on this one (PR 4d of docs/remote-machines.md).

Viewer: the remote chip's Start/Stop and the menu's Restart call
`remote_control` with the snapshot's expect values (runId, configRev, and
legacyId for a relaunch). A toast shows the progress ("Starting in the app
on B…"), `unknown` as "Outcome unknown. Checking B…", then the result.
One control per service at a time, and none while the session is down:
the button is disabled with the connection state.

Quick actions: a control that isn't allowed stays clickable and opens a
card. control_disabled and background_disabled offer `Ask B` on protocol
2 (the `remote_access` stream, with Cancel, the outcomes and retryAfter)
and always the command to run there; protocol 1 gets only the command.
A legacy run with a legacyId, its Restart and Output's "Relaunch to
share" go to `Relaunch on B` after the contract's confirmation; with
controls off it asks for access first, then relaunches only if the
snapshot still shows the same legacyId and configRev, and otherwise asks
again. Other codes show their message.

Target: the app subscribes to `remote_events` with `access: true` and
shows the access dialog in the contract's words, one request at a time,
with a system notification while the window isn't focused
(tauri-plugin-notification). Focus lands on the dialog, not a button.

Settings → Remote access: the control and background switches work, and
suppressed machines are listed with `Allow requests again`.

The "comes in a later version" texts and the disabled-only paths are
gone. Pure logic is in lib/util.remote-controls.ts, with node tests.
A control's answer no longer leaves once `share` is off, and status
queries read nothing then. A control not dispatched yet is cancelled by
an unpairing or a new key, and the pin is checked again right before
dispatch. The daemon spawns a detached start's executor itself, so an
executor stalled before its admission is killed with its session at
expiry and its lock freed.

Controls and status queries are admitted within a per-viewer and a
global bound before any work, request entries are rate-limited per peer,
and stale entries are swept periodically instead of on every
publication. A launch's own record now decides readiness over the port,
a restart interrupted after its stop reports `failed`, and failure
output is cut to fit a session message.

On the viewer, a control goes only over an open session and is never
queued, and `unknown` is asked again every 2 s for up to 2 minutes
instead of ending the stream. The app's "Reload shell environment" now
also reloads the daemon's copy, through `remote_reload_shell_environment`.

The convergence gate now runs through a real daemon watch against real
`localify dev` and `localify stop` processes.
…ground starts

- Map the connection-state refusals (`not_connected`, `connecting`,
  `not_responding`), `busy` and `too_many` to their messages, and `lost`
  by its code, `not_shared` included. A result never says "Checking B…".
- With `control` off, a start while B's app is absent, or a restart of a
  background run, asks for `backgroundStarts` in one request, and the
  card's command turns on both switches.
- Close a relaunch's access toast when the machine's view goes away.
# Conflicts:
#	desktop-ui/src/types/localify.ts
#	docs/remote-machines.md
#	src/daemon/remote/actor.rs
#	src/daemon/remote/actor/control.rs
#	src/daemon/remote/actor/viewer.rs
#	src/daemon/remote/fake_relay.rs
#	src/daemon/remote/local.rs
#	src/daemon/remote/tests/control.rs
#	src/daemon/remote/tests/convergence.rs
#	src/daemon/remote/viewing.rs
#	src/desktop/dto.rs
#	src/infrastructure/remote/control.rs
#	src/infrastructure/remote/requests.rs
@teo-goulois
teo-goulois marked this pull request as ready for review November 9, 2026 15:53
…ntil answered

- Control streams are kept in a registry and closed when the machine leaves the
  screen, with their toasts dismissed. Late events, and streams whose opening
  resolves afterwards, are dropped or closed at once.
- The access dialog stays, with its buttons off, until the answer is through or
  access_closed arrives. A failed answer shows its error in the dialog and lets
  the request be answered again while it still waits.
- A relaunch whose access request ends without access keeps its reason on
  screen with "Or run this on B:" and the command. The relaunch card shows the
  command too.
- The notification capability grants only is-permission-granted,
  request-permission and notify.
The daemon can send a control's last event, then keep the stream open
while it fetches a fresh snapshot. Settling only forgot the stream, so
leaving the machine in that window left its reader running until EOF.
Settling now closes the transport too; closing one already ended does
nothing.
@teo-goulois
teo-goulois merged commit dd74814 into main Nov 9, 2026
5 checks passed
@teo-goulois
teo-goulois deleted the feat/remote-controls-ui branch November 9, 2026 16:18
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.

1 participant