Node detail: Share contact card on the Info tab
The advert menu's own-node contact card generalises into show_contact_card (QR code over the raw meshcore://contact/add link, in one floating view); the Info tab gains a 📱 Share contact row that pops it for the page's node. Offered only when the full 32-byte key is known — a prefix-only heard node has nothing scannable to encode. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2d6e20ba2e
commit
25527356a4
3 files changed
+70
-11
No files matched your search
@@ -798,17 +798,26 @@ def contact_share_url(name: str, public_key: str, node_type: int = 1) -> str:
|
||||
)
|
||||
|
||||
|
||||
async def _show_contact_card(ctx: "AppContext", snapshot: dict) -> None:
|
||||
"""Show this node's contact card as a scannable QR code plus the raw URI."""
|
||||
async def show_contact_card(
|
||||
ctx: "AppContext", name: str, public_key: str, node_type: int = 1
|
||||
) -> None:
|
||||
"""Pop up a node's contact card: a scannable QR code over the raw share link.
|
||||
|
||||
THE share-a-contact popup, used both for our own node (the advert menu's
|
||||
``Share QR / URI``) and for any full-keyed contact (the node detail page's
|
||||
``Share contact``): a phone scans the code — or the link is passed along as text —
|
||||
and the companion app adds the node as a contact.
|
||||
|
||||
Args:
|
||||
ctx: Shared application context (provides the UI surface).
|
||||
name: The node's advertised name (the card's title and the link's name field).
|
||||
public_key: The node's full public key as hex (the link is useless without it).
|
||||
node_type: The MeshCore advert type byte (1 companion, 2 repeater, 3 room,
|
||||
4 sensor).
|
||||
"""
|
||||
from .qr import qr_text
|
||||
|
||||
public_key = str(snapshot.get("public_key") or "")
|
||||
if not public_key:
|
||||
ctx.ui.note("[err]the device did not report a public key — nothing to share[/err]")
|
||||
await ctx.ui.present(title="Share contact")
|
||||
return
|
||||
name = str(snapshot.get("name") or "this node")
|
||||
url = contact_share_url(name, public_key, int(snapshot.get("adv_type") or 1))
|
||||
url = contact_share_url(name, public_key, node_type)
|
||||
body = Group(
|
||||
Text("Scan to add this node as a contact:", style="muted"),
|
||||
Text(""),
|
||||
@@ -819,6 +828,17 @@ async def _show_contact_card(ctx: "AppContext", snapshot: dict) -> None:
|
||||
await ctx.ui.view(body, title=f"Share {name}", footer_hint="Esc close")
|
||||
|
||||
|
||||
async def _show_contact_card(ctx: "AppContext", snapshot: dict) -> None:
|
||||
"""Show our own node's contact card from its ``SELF_INFO`` snapshot."""
|
||||
public_key = str(snapshot.get("public_key") or "")
|
||||
if not public_key:
|
||||
ctx.ui.note("[err]the device did not report a public key — nothing to share[/err]")
|
||||
await ctx.ui.present(title="Share contact")
|
||||
return
|
||||
name = str(snapshot.get("name") or "this node")
|
||||
await show_contact_card(ctx, name, public_key, int(snapshot.get("adv_type") or 1))
|
||||
|
||||
|
||||
async def _reboot(ctx: "AppContext", device: "Device", snapshot: dict) -> bool:
|
||||
"""Confirm and reboot the device, handing off to the session's reconnect dialog.
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ the node itself, in full:
|
||||
static basemap preview (see :class:`~meshterm.ui.minimap.MiniMap`) centred on the node,
|
||||
grown to whatever rows the viewport spares. Its actions: ``Open full map`` (the full
|
||||
map opens centred here with its find filter seeded to this node, so it lights among
|
||||
the rest) and ``Time machine``.
|
||||
the rest), ``Time machine``, and ``Share contact`` — a popup contact card (QR code +
|
||||
``meshcore://`` link, see :func:`~meshterm.ui.config_editor.show_contact_card`),
|
||||
offered whenever the node's full key is known.
|
||||
* **Routes** — the routes we've actually heard the node arrive over, drawn on the shared
|
||||
route graph (:mod:`~meshterm.ui.pathgraph`) node→us (the inbound direction the packets
|
||||
travelled, contact on the left, us on the right). Beneath the graph sits the *route
|
||||
@@ -305,7 +307,8 @@ class NodeDetailScreen(Screen):
|
||||
routes: The Routes tab's route list + graph callbacks (or a muted note), or
|
||||
``None`` when there is no Routes tab (we never overhear our own node).
|
||||
info_actions: The Info tab's action rows (Open full map when there is a fix,
|
||||
Time machine when the recorder holds history).
|
||||
Time machine when the recorder holds history, Share contact when the full
|
||||
key is known).
|
||||
trace_action: The Routes tab's ``Trace — auto route …`` action, shown only when
|
||||
there are no routes to list (with routes listed, Enter on a route row is the
|
||||
trace entry point), or ``None``.
|
||||
@@ -790,6 +793,7 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
|
||||
)
|
||||
from ..services.topology import build_topology, _is_hex
|
||||
from ..tools.map import gather_markers
|
||||
from .config_editor import show_contact_card
|
||||
from .map_screen import basemap_source, open_map
|
||||
from .surface import TuiUi
|
||||
from .timemachine_screen import open_timemachine_node, open_timemachine_self
|
||||
@@ -969,6 +973,16 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
|
||||
info_actions.append(
|
||||
_Action("timemachine", "⏳", "", f"Time machine — {hn.count} receptions")
|
||||
)
|
||||
# The share card encodes the full 32-byte key; a prefix-only contact (heard but never
|
||||
# synced from the device) has nothing scannable to offer, so the row only shows when
|
||||
# the whole key is known.
|
||||
full_key = key.lower().removeprefix("0x")
|
||||
if len(full_key) == 64 and _is_hex(full_key):
|
||||
info_actions.append(_Action("share", "📱", "", "Share contact — QR / link"))
|
||||
try:
|
||||
adv_type = int(node_type) if node_type is not None else 1
|
||||
except (TypeError, ValueError):
|
||||
adv_type = 1
|
||||
# With routes listed, each route row is its own trace entry point (Enter arms it); the
|
||||
# dedicated action only stands in when there is no route evidence to list.
|
||||
trace_action: Optional[_Action] = None
|
||||
@@ -1009,6 +1023,8 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
|
||||
focus=(lat, lon),
|
||||
find=label if any(needle in m.label.casefold() for m in markers) else None,
|
||||
)
|
||||
elif action == "share":
|
||||
await show_contact_card(ctx, label, full_key, adv_type)
|
||||
elif action == "timemachine":
|
||||
if you:
|
||||
await open_timemachine_self(ctx)
|
||||
|
||||
@@ -71,6 +71,29 @@ def test_contact_share_url_defaults_to_companion_type() -> None:
|
||||
assert contact_share_url("n", "00" * 32).endswith("&type=1")
|
||||
|
||||
|
||||
async def test_show_contact_card_pops_the_qr_over_the_link() -> None:
|
||||
"""The share popup is one floating view: a scannable QR code over the raw
|
||||
``meshcore://`` link, titled with the node's name."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
from meshterm.ui.config_editor import show_contact_card
|
||||
|
||||
calls: list = []
|
||||
|
||||
class _Ui:
|
||||
async def view(self, renderable: Any, **kwargs: Any) -> None:
|
||||
calls.append((renderable, kwargs))
|
||||
|
||||
await show_contact_card(SimpleNamespace(ui=_Ui()), "Hub", "AB" * 32, node_type=2)
|
||||
((renderable, kwargs),) = calls
|
||||
assert kwargs["title"] == "Share Hub"
|
||||
console = Console(width=200, record=True) # wide enough that the link never wraps
|
||||
console.print(renderable)
|
||||
out = console.export_text()
|
||||
assert f"meshcore://contact/add?name=Hub&public_key={'ab' * 32}&type=2" in out
|
||||
assert "█" in out # the QR actually drew its modules
|
||||
|
||||
|
||||
# -- coordinate parsing ----------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user