Channels: offer to add the standard Public channel when absent
An add-action restores MeshCore's built-in fixed-key Public channel on the next free slot, shown only while no slot already carries the well-known secret. Leads with the 🌐 globe to distinguish it from the name-derived # Public channel row. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
22f85e3d51
commit
c3d712eff5
2 files changed
+57
-8
No files matched your search
+30
-8
@@ -45,6 +45,7 @@ from rich.text import Text
|
||||
from ..core.channels import (
|
||||
CHANNEL_SLOT_EMPTY_RUN,
|
||||
CHANNEL_SLOT_PROBE_CAP,
|
||||
DEFAULT_PUBLIC_SECRET,
|
||||
MAX_CHANNELS,
|
||||
channel_hash,
|
||||
channel_identity,
|
||||
@@ -73,6 +74,7 @@ if TYPE_CHECKING:
|
||||
# Top-menu action sentinels (distinct from a plain slot index, which selects that channel).
|
||||
_CREATE = "__create__"
|
||||
_PUBLIC = "__public__"
|
||||
_DEFAULT_PUBLIC = "__default_public__"
|
||||
_JOIN = "__join__"
|
||||
_IMPORT = "__import__"
|
||||
_REORDER = "__reorder__"
|
||||
@@ -181,6 +183,8 @@ async def manage_channels(ctx: "AppContext") -> int:
|
||||
before = changes
|
||||
if choice == _CREATE:
|
||||
changes += await _create_private(ctx, device, slots, capacity)
|
||||
elif choice == _DEFAULT_PUBLIC:
|
||||
changes += await _add_default_public(ctx, device, slots, capacity)
|
||||
elif choice == _PUBLIC:
|
||||
changes += await _add_public(ctx, device, slots, capacity)
|
||||
elif choice == _JOIN:
|
||||
@@ -546,16 +550,22 @@ def _menu_items(
|
||||
items.append(Choice(title="↕ Reorder channels", value=_REORDER))
|
||||
|
||||
items.append(section_heading("Add a channel"))
|
||||
items.extend(
|
||||
menu_rows(
|
||||
[
|
||||
("+ New private channel…", "A fresh random key", _CREATE),
|
||||
("# Public channel…", "Key derived from its name", _PUBLIC),
|
||||
("🔑 Join with a key…", "Paste a channel's 32-hex key", _JOIN),
|
||||
("🔗 Import a link…", "Paste a meshcore:// share link", _IMPORT),
|
||||
]
|
||||
rows = []
|
||||
# The firmware's built-in fixed-key Public channel has one well-known secret, so it's the
|
||||
# same channel on every slot — offer to restore it only while no slot already holds it.
|
||||
if not any(s.secret == DEFAULT_PUBLIC_SECRET for s in slots):
|
||||
rows.append(
|
||||
("🌐 Standard Public channel", "MeshCore's built-in meshwide channel", _DEFAULT_PUBLIC)
|
||||
)
|
||||
rows.extend(
|
||||
[
|
||||
("+ New private channel…", "A fresh random key", _CREATE),
|
||||
("# Public channel…", "Key derived from its name", _PUBLIC),
|
||||
("🔑 Join with a key…", "Paste a channel's 32-hex key", _JOIN),
|
||||
("🔗 Import a link…", "Paste a meshcore:// share link", _IMPORT),
|
||||
]
|
||||
)
|
||||
items.extend(menu_rows(rows))
|
||||
items.extend(back_rows(_BACK))
|
||||
|
||||
return f"Channels — {len(slots)}/{capacity} slots", items
|
||||
@@ -693,6 +703,18 @@ async def _create_private(
|
||||
return 1
|
||||
|
||||
|
||||
async def _add_default_public(
|
||||
ctx: "AppContext", device: Device, slots: list[ChannelSlot], capacity: int
|
||||
) -> int:
|
||||
"""Add MeshCore's built-in fixed-key ``Public`` channel on the next free slot."""
|
||||
idx = await _pick_free_slot(ctx, slots, capacity)
|
||||
if idx is None:
|
||||
return 0
|
||||
await device.set_channel(idx, "Public", DEFAULT_PUBLIC_SECRET)
|
||||
ctx.ui.note("[ok]✓[/ok] added the standard [brand]Public[/brand] channel")
|
||||
return 1
|
||||
|
||||
|
||||
async def _add_public(
|
||||
ctx: "AppContext", device: Device, slots: list[ChannelSlot], capacity: int
|
||||
) -> int:
|
||||
|
||||
@@ -563,6 +563,33 @@ async def test_channel_rows_carry_stats_unread_and_lanes(ctx: AppContext) -> Non
|
||||
assert label.spans[-1].style == "ok" # …and its newest cell reads as live traffic
|
||||
|
||||
|
||||
async def test_standard_public_row_appears_only_while_it_is_absent(ctx: AppContext) -> None:
|
||||
"""The 'Standard Public channel' add-action shows until a slot holds the fixed-key default."""
|
||||
from meshterm.core.channels import DEFAULT_PUBLIC_SECRET
|
||||
from meshterm.ui.channels import _DEFAULT_PUBLIC, _add_default_public, _LiveStats, _menu_items
|
||||
from meshterm.ui.tui import Choice
|
||||
|
||||
device = await ctx.device()
|
||||
|
||||
def has_default_row(slots: list) -> bool:
|
||||
_, items = _menu_items(ctx, slots, 8, _LiveStats(ctx))
|
||||
return any(isinstance(it, Choice) and it.value == _DEFAULT_PUBLIC for it in items)
|
||||
|
||||
# Absent on an empty table and while an unrelated channel occupies a slot.
|
||||
assert has_default_row([])
|
||||
await device.set_channel(1, "Ops", bytes(range(16)))
|
||||
slots = await read_channel_slots(device)
|
||||
assert has_default_row(slots)
|
||||
|
||||
# Adding it lands the well-known secret on the next free slot and retires the offer.
|
||||
added = await _add_default_public(ctx, device, slots, 8)
|
||||
assert added == 1
|
||||
slots = await read_channel_slots(device)
|
||||
public = next(s for s in slots if s.secret == DEFAULT_PUBLIC_SECRET)
|
||||
assert public.name == "Public" and public.is_public
|
||||
assert not has_default_row(slots)
|
||||
|
||||
|
||||
async def test_clearing_a_channel_reads_off_its_unread(ctx: AppContext) -> None:
|
||||
"""Clearing a channel drops its unread from the global total, not just the slot."""
|
||||
from meshterm.ui.channels import _clear
|
||||
|
||||
Reference in new issue
Block a user