Dismiss WiFi boot prompt when mobile session opens
This commit is contained in:
@@ -870,6 +870,7 @@ def create_app(
|
||||
apply_resolved_content, effective_default_content, set_default_content,
|
||||
read_device_status, storage_monitor.get_status, library_order=library_order)
|
||||
mobile_sessions = SessionManager(mobile.dispatch, mobile.identity,
|
||||
on_session_open=network.dismiss_for_boot,
|
||||
wifi_address=lambda: network.get_cached_status().get("active", {}).get("ipv4_address")
|
||||
if network.get_cached_status().get("active", {}).get("connected") else None)
|
||||
mobile_runtime = BluezRuntime(mobile_sessions, enabled=os.environ.get("MATRIX_BLE_ENABLED") == "1")
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
|
||||
from .protocol import Handshake, ProtocolError, Reassembler
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RpcError(Exception):
|
||||
def __init__(self, code, message):
|
||||
@@ -23,10 +26,12 @@ def checked_name(value):
|
||||
|
||||
|
||||
class SessionManager:
|
||||
def __init__(self, dispatch, identity, *, clock=time.monotonic, wifi_address=lambda: None):
|
||||
def __init__(self, dispatch, identity, *, clock=time.monotonic, wifi_address=lambda: None,
|
||||
on_session_open=None):
|
||||
self.dispatch = dispatch
|
||||
self.identity = identity
|
||||
self.clock = clock
|
||||
self.on_session_open = on_session_open
|
||||
self.lock = threading.RLock()
|
||||
self.owner = None
|
||||
self.receiver = None
|
||||
@@ -116,6 +121,13 @@ class SessionManager:
|
||||
self.client_name = name
|
||||
self.opened = True
|
||||
self.generation += 1
|
||||
if self.on_session_open is not None:
|
||||
try:
|
||||
self.on_session_open()
|
||||
except Exception:
|
||||
# A failed display notification must not invalidate
|
||||
# an already established encrypted session.
|
||||
logger.exception("Mobile session-open notification failed")
|
||||
elif method == "session.ping":
|
||||
result = dict(alive=True)
|
||||
elif method == "session.rename":
|
||||
|
||||
@@ -112,6 +112,7 @@ class WifiNetworkService:
|
||||
self.monotonic = monotonic
|
||||
self.poll_seconds = poll_seconds
|
||||
self._lock = threading.RLock()
|
||||
self._indicator_lock = threading.RLock()
|
||||
self.configuration_lock = self._lock
|
||||
self.settings_revision = str(uuid4())
|
||||
self._stop = threading.Event()
|
||||
@@ -156,13 +157,14 @@ class WifiNetworkService:
|
||||
self.display.dismiss_wifi_indicator()
|
||||
|
||||
def dismiss_for_boot(self) -> None:
|
||||
try:
|
||||
changed = self.store.dismiss_for_boot()
|
||||
except Exception:
|
||||
logger.exception("Failed to persist WiFi indicator dismissal")
|
||||
changed = True
|
||||
if changed or self.display.get_status()["state"].get("wifi_indicator_active"):
|
||||
self.display.dismiss_wifi_indicator()
|
||||
with self._indicator_lock:
|
||||
try:
|
||||
changed = self.store.dismiss_for_boot()
|
||||
except Exception:
|
||||
logger.exception("Failed to persist WiFi indicator dismissal")
|
||||
changed = True
|
||||
if changed or self.display.get_status()["state"].get("wifi_indicator_active"):
|
||||
self.display.dismiss_wifi_indicator()
|
||||
|
||||
def get_status(self, *, include_secret: bool = False) -> dict[str, Any]:
|
||||
managed_uuid = self.store.config["managed_connection_uuid"]
|
||||
@@ -342,6 +344,8 @@ class WifiNetworkService:
|
||||
self._stop.wait(self.poll_seconds)
|
||||
|
||||
def _refresh_indicator(self) -> None:
|
||||
if self.store.session["dismissed"]:
|
||||
return
|
||||
managed_uuid = self.store.config["managed_connection_uuid"]
|
||||
try:
|
||||
active = self.backend.read_active()
|
||||
@@ -350,7 +354,7 @@ class WifiNetworkService:
|
||||
f"SSID: {active['ssid']} "
|
||||
f"IP: http://{active['ipv4_address']}:8080/"
|
||||
)
|
||||
self.display.show_wifi_indicator(connected=True, message=message)
|
||||
self._show_indicator_unless_dismissed(connected=True, message=message)
|
||||
return
|
||||
|
||||
if managed_uuid:
|
||||
@@ -359,6 +363,13 @@ class WifiNetworkService:
|
||||
message = f"SSID: {saved.get('ssid') or '未配置'} 密码: {password}"
|
||||
else:
|
||||
message = "尚未配置 WiFi"
|
||||
self.display.show_wifi_indicator(connected=False, message=message)
|
||||
self._show_indicator_unless_dismissed(connected=False, message=message)
|
||||
except NetworkManagerError:
|
||||
self.display.show_wifi_indicator(connected=False, message="WiFi 状态不可用")
|
||||
self._show_indicator_unless_dismissed(connected=False, message="WiFi 状态不可用")
|
||||
|
||||
def _show_indicator_unless_dismissed(self, *, connected: bool, message: str) -> None:
|
||||
# NetworkManager reads happen outside this lock so opening a mobile
|
||||
# session never waits for them. Recheck at the actual submission point.
|
||||
with self._indicator_lock:
|
||||
if not self.store.session["dismissed"]:
|
||||
self.display.show_wifi_indicator(connected=connected, message=message)
|
||||
|
||||
@@ -3628,7 +3628,7 @@
|
||||
},
|
||||
"scope": "global",
|
||||
"source": "index.html::#topbar-mobile::text[0]",
|
||||
"text": "手机未连接"
|
||||
"text": "连接设备:未连接"
|
||||
},
|
||||
"copy.9a395662799ecd7a": {
|
||||
"kind": "html_text",
|
||||
|
||||
Reference in New Issue
Block a user