Repository navigation
Commit c77fae6
authored
feat(device): Add add-device flow with manual-IP pairing and Tailscale support (#232)
* feat(device): add add-device page for pairing Apple TV and iPhone
Add a dedicated add-device page that replaces the pairable-device card on
the home sidebar with a persistent "Add New Device" entry.
The page offers two tabs:
- Apple TV (default, left): pick a discovered pairable Apple TV from a
combobox and start the existing pairing flow; no port or pairing file.
- iPhone: pick an iPhone from a combobox and upload a pairing file, reusing
the existing lab import flow.
Both device lists use a shared combobox (typing an IP is supported) with a
refresh button; the Apple TV list keeps its spinner up for at least one
second so the fast endpoint still gives visible feedback. Lists are filtered
to Apple TV / iPhone devices (unknown classes kept) and refreshed on tab
entry. Add the /add-device route, sidebar icons, and locale strings for all
bundled languages. Hide the service-status card on phones.
* style(ui): improve combobox dropdown layout on phones
Stack the Anisette server presets (URL above name and default badge) and
let device names wrap instead of being clipped, with 44px tap targets and a
scrollable list under 767px. Desktop layout is unchanged.
* feat(pair): support manual-IP pairing with port discovery
Allow pairing an Apple TV entered by IP (e.g. over Tailscale) whose
pairing port is unknown. The pair page now discovers the manual-pairing
port first: the start button stays disabled until a port is found, shows
a progress panel (mDNS lookup, TCP scan percentage, service probe) and
offers a rediscover button.
Backend:
- Add RPPairing port discovery (handshake + unicast DNS-SD fast path +
two-stage TCP scan) in internal/manager/pairing_port_discovery.go.
- Add Device.Manual; pass --manual to `plumesign pair` for manual IPs.
- Extend the pair websocket with t=3 (discover) and t=4 (start with ip+port);
discovery streams JSON progress lines on the same socket.
Frontend:
- Pair page manual mode driven by ?ip= / the pair-manual route.
- add-device routes a typed IP that matches no discovered device into the
manual pairing flow instead of erroring.
Includes Go unit tests (frame/parse/mock-server/scan) and a frontend test
for the discovery messages and start payload.
* feat(pair): manual-IP iPhone connect via tunnel port discovery
Let the add-device iPhone tab connect an iPhone typed by IP whose
_remotepairing tunnel port is unknown.
Backend:
- Generalize port discovery with a shared predicate-based scanner and add
DiscoverManualTunnelPort (unicast _remotepairing._tcp + TCP scan picking
allowsIncomingTunnelConnections).
- Pass --manual through ImportPairingFile (manager/service/router) so
`plumesign check pairing` knows the IP was entered manually.
- Add GET /api/pair/tunnel-port?ip= returning the discovered tunnel port
(IPv4-only).
Frontend:
- api.discoverTunnelPort; iPhone startConnect uses a discovered device's
port when present, otherwise probes the tunnel port and imports with
manual=true. Button spinner covers probe+import; failures show a toast.
- Rewrite the iPhone no_device text to tunnel-service semantics (5 locales).
Tests: tunnel discovery (picks tunnel, ignores pair-setup), pairingCheckArgs
--manual, and a frontend test for the discovered/manual/failure branches.
* feat(device): show manual (pairing-file) devices on home
Manual / Tailscale devices do not broadcast mDNS, so they never reached the
device list. Read them directly from the pairing files instead of adding a
new store: the .json peer record already carries manual, remotepairing_ip,
name, model and udid.
Backend:
- RemoteDevice gains Manual and RemotePairingIP.
- DeviceManager keeps a separate manualDevices map loaded from
<pairing_files>/*.json (manual=true + remotepairing_ip) and merges it into
GetDevices, deduped by UDID with mDNS entries winning. ReloadDevices
refreshes it; Scan() leaves it intact.
- DeleteManualDevice removes both <udid>.json and <udid>.plist and the
in-memory entry; POST /api/devices/:id/manual/delete exposes it.
Frontend:
- Manual devices show status "已添加" (added) and an "IP" badge on the icon's
top-right corner (brand blue) instead of the online dot; IP stays after the
name. A "忘记" action with click-to-confirm deletes the pairing files.
Tests: manual device loading/skip, dedupe with discovered, file deletion.
Port probing for install is deferred to a later step.
* fix(device): unclip IP badge and refine forget action
- Move the "IP" badge onto .avatar instead of .avatar > div, which daisyUI
clips with overflow:hidden, so the badge is no longer cut off.
- Float the forget button to the far right of the row and show it only on
row hover (or keyboard focus / armed state); on phones (<=767px) it stays
always visible and the row wraps so it never overlaps the device text.
* style(device): absolutely position the manual-device forget button
Take the forget button out of the row's flex flow (position: absolute at the
right edge) so the device title keeps the full width and never reflows to make
room for it. Hidden until row hover on desktop; always visible on phones with
reserved right padding so it does not cover the text.
* style(device): inline forget icon on status line, tooltip "删除设备"
- Move the manual-device forget button inline right after the status text
("已添加 · RPPairing") instead of floating at the row's right edge, so it
never competes with the title for space.
- Change the forget/delete tooltip to "删除设备" (Delete device) across
locales.
* style(device): manual-device delete as dotted hover-only text link
Replace the delete icon with an underlined "删除" text link on the status
line, prefixed by a "·" separator that only appears on row hover. The link
defaults to the danger color; the underline lives on an inner label so the
separator dot stays clean. Always visible on phones.
* feat(install): resolve manual-device tunnel port before install/refresh
Manual (pairing-file/Tailscale) devices carry no tunnel port, so every flow
that reached them over RSD failed. Resolve the dynamic _remotepairing port on
demand (60s cache, per-UDID mutex, no automatic retry) and inject it before
use.
- manager.PrepareManualDevice / ManualPortNeedsResolve: probe the tunnel port
for manual devices only, cache it on the in-memory device (PortResolvedAt),
preserve it across pairing-file reloads, and serialize concurrent probes.
- Install: prepare before the queue (task.runInternal), interactive websocket
(runInstallMessage) and external-certificate (runExternalInstall) paths; the
install log shows "Resolving tunnel port for manual device...".
- Refresh: manager.CheckAfcServiceStatus prepares the port first, covering the
cron schedule, device-triggered refresh and /api refresh. Manual devices rely
on the cron schedule (no mDNS connect event).
- Mount/screenshot: prepare the port before RSD commands.
Tests: port resolution, no-op for discovered devices, TTL reuse/expiry, error
keeps port 0, and concurrent single-probe.
* feat(device): mark stale mDNS devices so manual records take over
A device that leaves the network without an mDNS goodbye stayed in the
discovery map forever and shadowed its manual (pairing-file) record. Add a
background liveness loop for devices that have BOTH an mDNS entry and a manual
record:
- Every minute, TCP-dial the tunnel port of dual-source remote devices that
have not been probed in the last minute; a fresh mDNS announcement counts as
a probe. Lockdown/USB, pairable and port-less entries are never probed.
- After 5 consecutive failures the device is marked stale (hidden from
GetDevices) so the manual entry surfaces; a later successful probe or a new
announcement clears the flag and mDNS wins again.
- Stale is a flag, not a delete, so avahi never needs to re-announce for the
device to come back.
Constants (interval, min age, fail threshold, dial timeout) are grouped at the
top of device_probe.go for easy tuning. Adds unit tests for targeting,
min-age skip, threshold/recovery and announcement reset.
* fix(add-device): avoid duplicate toast when iPhone tunnel probe fails
discoverTunnelPort now sends silent:true so the request interceptor does not
toast the API error, leaving only the page's own "tunnel service not found"
message. The response interceptor's network-error branch also honours
silent so a timeout cannot double-toast either.
* feat(ui): keep error toasts visible for 6 seconds
Error toasts used the global 3s autoClose and were easy to miss. Wrap
toast.error once at startup so error toasts default to 6s while success and
other toasts keep the global 3s; an explicit autoClose in a call still wins.
Drop the request interceptor's own 5s override so API errors use the same
default.
* fix(add-device): load tab device list only on first switch
Switching tabs reuses the cached device list instead of reloading
every time; a failed load still retries on the next switch. The
combobox refresh button keeps reloading on demand.
* build(deps): vendor bom into pkg/ and switch lzfse to purego for no-cgo build
Move the bitxeno/bom fork (pinned at 0e05147) into pkg/bom as a nested
module and swap its cgo github.com/blacktop/lzfse-cgo dependency for
bitxeno/lzfse-go, which calls the native lzfse through purego from an
embedded shared library. Decoded pixels are verified identical to the
cgo version on a real Assets.car.
With the last hard cgo dependency gone the whole service builds with
CGO_ENABLED=0, which the release and nightly xgo workflows already set.
* chore(docker): bump plumesign to v2.7.1-patch.5
* fix(device): raise manual tunnel port scan dial timeout to 600ms
At 250ms the dial budget matched the Tailscale relay RTT, so the open
service ports that need a full handshake were often missed under the
1024-concurrent scan, making tunnel discovery fail intermittently with
"manual tunnel port not found". 600ms leaves room for the measured
100-250ms relay latencies, as the design doc already recommended for
full port lists.
* perf(device): pipelined port scan with early exit and tailnet mDNS skip
Ports are dialled in ascending order and probed as soon as each dial succeeds; the first matching RPPairing service cancels the rest of the scan. Darwin allocates ephemeral ports ascending, so the tunnel port sits near 49152 in practice and is found without sweeping the full range: ~0.9s vs ~5s to a real device over Tailscale.
Unicast mDNS is skipped for 100.x.x.x addresses (Tailscale CGNAT range): the query can never cross the overlay tunnel and only cost its 1.5s timeout.
Two scan stalls surfaced by this change are also fixed: silent local listeners (rapportd, the app's own HTTP server) accept the probe and answer nothing, so the handshake response deadline is now 800ms separate from the 2s dial timeout, and the probe pool is widened to 32 slots so a handful of such listeners cannot starve the real service.
* refactor(pair): reuse pipelined scan for Apple TV pairing discovery
DiscoverManualPairingPort now shares the pipelined ascending scan and the 100.x.x.x mDNS skip with the tunnel discovery, instead of its own full-range collect-all scan. The tunnel port it reported was never consumed by the pair page, so the field and the collect-all variant are removed.
Scan concurrency rises to 1536 (doc-proven stable) because Apple devices silently drop SYNs to closed ports, making a full sweep timeout-bound: a paired Apple TV outside pairing mode is found in ~4.3s instead of ~8.7s on LAN, while the Tailscale tunnel path stays at ~0.9-1.6s.
* fix(ui): keep combobox list open until option click in WebKit
WebKit moves focus on mousedown, so clicking an option blurred the
input and closed the dropdown before the click could land on the
button: the click retargeted to the enclosing form and the selection
was lost (Safari and the desktop webview). Prevent the default on
mousedown in both comboboxes — DeviceComboBox and the settings
anisette server list — so the input keeps focus until pick runs.
Verified in headless WebKit and Chromium with real click sequences.
* fix(device): stop scan bursts from saturating the Tailscale relay
Full-range probes from the Docker deployment failed most of the time against a Tailscale device: a burst of 1536 concurrent SYNs saturates the relay queue, and the open service port itself starts exceeding the dial timeout. In-container measurements showed 2 of 3 scans missing the port entirely, while a single unthrottled dial always succeeded (0.3-1.1s RTT).
The scan now dials 128 ports per 1.5s wave: closed ports answer RST fast, every sweep found the service (5/5 in-container runs, 1.6-1.8s for the common low-port case), and the ascending order with early exit keeps high ports reachable on later waves.
PrepareManualDevice additionally re-probes the remembered port with a single handshake before falling back to the scan, since the tunnel port only changes when the device restarts its services: repeated installs hit a 3.25us cache path or one 2s dial instead of a full sweep.
* feat(add-device): use monochrome tab icons that turn white when selected
Replace the Apple TV and iPhone tab glyphs on the add-device page with
outline icons sourced from Icon=appletv.svg and Icon=ipad.and.iphone.svg.
Both are drawn with fill="currentColor", so they follow the button text
colour and turn white when the tab is selected (btn-primary).
The iPhone glyph keeps the iPad knockout behind the phone via an SVG
mask instead of the original white fill, so the overlap stays clean on
both the light and the selected blue background.
* fix(home): deepen add-device icon badge on row hover
The badge used --atv-accent-soft, which is nearly the same shade as the
row hover tint (--atv-surface-hover), so the icon all but disappeared
when the add-device row was hovered.
Add an --atv-accent-soft-hover token for light and dark themes and apply
it to the badge while its row is hovered, with a short transition.
* feat(add-device): warn when connecting to an iPhone over Tailscale
Connecting to an iPhone via a 100.x.x.x (Tailscale) address only works
while the iPhone is on Wi-Fi. Show a confirmation dialog with Cancel and
Continue before starting the connect flow when a Tailscale IP is entered.
- Detect 100.x.x.x addresses and gate the connect flow on a reminder dialog
- Split startConnect into the reminder gate and connectIPhone worker
- Add tailscale_wifi strings to all bundled locales
- Cover the reminder, confirm and cancel paths in tests
* fix(device): harden manual (Tailscale) device port discovery
- Restrict manual device addresses to private LAN and CGNAT
(100.64.0.0/10) so a manual entry can no longer trigger a full-range
scan of arbitrary public hosts.
- Warm the tunnel port in the background after pairing completes, so the
first install skips the full-range scan.
- Re-check a remembered port with the full dial budget as its handshake
deadline and retry a few times, so one slow relay round trip no longer
turns a healthy device into a multi-second full-range scan.
- Raise the scan handshake response deadline to 1.2s and the tunnel-port
API budget to 30s to cover relay RTT.
- Drop the Tailscale Wi-Fi reminder dialog and fold the Wi-Fi root cause
into the tunnel-port error and the no_device copy (all locales).1 parent 95bfb43 commit c77fae6
68 files changed
Lines changed: 6882 additions & 98 deletions
File tree
- doc/misc
- internal
- ipa
- manager
- model
- service
- task
- locales
- pkg/bom
- pkg
- asset
- bom
- test_data
- helper
- mreader
- reader
- web
- static
- src
- api
- assets/icons
- components
- page
- add-device
- home
- pair
- settings
- router
- utils
- test
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
15 | 21 | | |
16 | 22 | | |
17 | | - | |
| 23 | + | |
18 | 24 | | |
19 | 25 | | |
20 | | - | |
| 26 | + | |
21 | 27 | | |
22 | 28 | | |
23 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
0 commit comments