Offer Use now only where a reconnect goes, and keep newer edits and headsets apart

From the second independent review of this PR:

- Use now sends a plain reconnect, which picks the first-ranked address that
  answers, but it was offered on every tested address listed above the one in
  use. The devices list now carries each address's rank on the current network
  (frame_devices.order_addresses), and only the address a reconnect would pick
  gets the button.
- Saving one address, cancelling, then editing another: the first save's answer
  closed the second editor and lost what was typed. Each edit now has its own
  session, and a late answer leaves a newer one alone.
- Switching headsets with the dialog open drew the address offer from the
  previous headset's status before it was cleared, so Add could save its IP to
  the new headset. The dialog now renders after the old status is cleared.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
saphidandClaude Opus 5.5 committed 2026-10-01 21:03:13 +10:00
1 parent 0520082586
commit 22bb9c6469
4 files changed
+44 -14

No files matched your search

+8 -2
View File
@@ -1017,6 +1017,8 @@ def devices_view(link):
snap = link.reg.snapshot()
active = link.active_device()
names = {nid: link.reg.network_name(dict(n, id=nid)) for nid, n in snap["networks"].items()}
net = link.state["network"] or {}
tailscale_up = bool((net.get("tailscale") or {}).get("up"))
devices = []
bare = link.bare(link.session_alias) if link.session_alias and not link.reg.by_alias(link.session_alias) else None
for extra in ([active] if active.get("transient") and not active.get("none") else []) + \
@@ -1027,8 +1029,12 @@ def devices_view(link):
view = {k: v for k, v in d.items() if k not in ("config_host", "addresses")}
view["active"] = d["id"] == active["id"]
view["pinned"] = frame_devices.pinned(d["id"])
view["addresses"] = [dict(a, network_names=[names.get(n, "an unnamed network") for n in a["networks"]])
for a in d["addresses"]]
# rank: where the next connection on this network tries it (0 first), so the page can
# tell which address a reconnect would pick.
ranks = {a["host"]: i for i, (a, _) in
enumerate(frame_devices.order_addresses(d["addresses"], net.get("id"), tailscale_up))}
view["addresses"] = [dict(a, network_names=[names.get(n, "an unnamed network") for n in a["networks"]],
rank=ranks[a["host"]]) for a in d["addresses"]]
devices.append(view)
return {"devices": devices, "active": active["id"], "network": link.state["network"],
"networks": [dict(n, id=nid, display=names[nid]) for nid, n in snap["networks"].items()],