fix(scripts): skip the portal probe on niri in inject-probe

The injector never offers the RemoteDesktop portal on niri, but inject-probe
ran the portal probe unguarded and reported portal_available: true there.
The probe now reuses the injector's _is_niri_session guard: on niri it skips
the portal and reports portal_skip_reason "niri" with portal_available false.
Off niri the probe runs and reports its answer as before.

Fixes #46
This commit is contained in:
2026-11-06 23:50:46 +05:30
parent a4a831c3c6
commit 3776c4de6e
3 changed files with 114 additions and 14 deletions
+18 -10
View File
@@ -433,8 +433,11 @@ def cmd_inject_probe(args: argparse.Namespace) -> int:
Never emits keystrokes: end-to-end key-to-screen latency would type
into the live desktop, so it stays a hardware-checklist item (#32).
On niri the portal is skipped with the injector's own niri guard: the
injector never offers the portal there, so the report must not claim it.
"""
from vocalinux.text_injection.text_injector import TextInjector
from vocalinux.text_injection.text_injector import TextInjector, _is_niri_session
probe_text = "the quick brown fox jumps over the lazy dog 0123456789"
started = time.monotonic()
@@ -462,16 +465,20 @@ def cmd_inject_probe(args: argparse.Namespace) -> int:
env=host_env(),
)
wtype_roundtrips.append(time.monotonic() - begin)
try:
from vocalinux.text_injection.remote_desktop_portal import RemoteDesktopPortal
portal_available = False
portal_seconds = None
portal_skip_reason = "niri" if _is_niri_session() else None
if portal_skip_reason is None:
try:
from vocalinux.text_injection.remote_desktop_portal import RemoteDesktopPortal
portal_started = time.monotonic()
portal_available = RemoteDesktopPortal().probe()
portal_seconds = time.monotonic() - portal_started
except Exception as exc: # noqa: BLE001 - probe must never fail the pass
portal_available = False
portal_seconds = None
print(f"portal probe raised: {exc}", file=sys.stderr)
portal_started = time.monotonic()
portal_available = RemoteDesktopPortal().probe()
portal_seconds = time.monotonic() - portal_started
except Exception as exc: # noqa: BLE001 - probe must never fail the pass
portal_available = False
portal_seconds = None
print(f"portal probe raised: {exc}", file=sys.stderr)
print(
json.dumps(
{
@@ -481,6 +488,7 @@ def cmd_inject_probe(args: argparse.Namespace) -> int:
"wtype_empty_roundtrip_stats": describe(wtype_roundtrips),
"portal_available": portal_available,
"portal_probe_seconds": portal_seconds,
"portal_skip_reason": portal_skip_reason,
},
indent=2,
sort_keys=True,