fix(modes): deep-linked mode scripts fail when body not yet parsed

ensureModeScript() used document.body.appendChild() to load lazy mode
scripts, but the preload for ?mode= query params runs in <head> before
<body> exists, causing all deep-linked modes to silently fail.

Also fix cross-mode handoffs (BT→BT Locate, WiFi→WiFi Locate,
Spy Stations→Waterfall) that assumed target module was already loaded.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Smittix
2026-03-12 20:49:08 +00:00
parent 7c425dbd99
commit ba631811a6
87 changed files with 9128 additions and 8368 deletions
+18 -17
View File
@@ -16,8 +16,9 @@ from typing import Generator
from flask import Blueprint, jsonify, request, Response
from utils.responses import api_success, api_error
from utils.logging import get_logger
from utils.sse import sse_stream_fanout
from utils.sse import sse_stream_fanout
from utils.meshtastic import (
get_meshtastic_client,
start_meshtastic,
@@ -453,8 +454,8 @@ def get_messages():
})
@meshtastic_bp.route('/stream')
def stream_messages():
@meshtastic_bp.route('/stream')
def stream_messages():
"""
SSE stream of Meshtastic messages.
@@ -469,18 +470,18 @@ def stream_messages():
Returns:
SSE stream (text/event-stream)
"""
response = Response(
sse_stream_fanout(
source_queue=_mesh_queue,
channel_key='meshtastic',
timeout=1.0,
keepalive_interval=30.0,
),
mimetype='text/event-stream',
)
response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive'
response = Response(
sse_stream_fanout(
source_queue=_mesh_queue,
channel_key='meshtastic',
timeout=1.0,
keepalive_interval=30.0,
),
mimetype='text/event-stream',
)
response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no'
response.headers['Connection'] = 'keep-alive'
return response
@@ -1050,11 +1051,11 @@ def request_store_forward():
def mesh_topology():
"""Return mesh network topology graph."""
if not is_meshtastic_available():
return jsonify({'status': 'error', 'message': 'Meshtastic SDK not installed'}), 400
return api_error('Meshtastic SDK not installed', 400)
client = get_meshtastic_client()
if not client or not client.is_running:
return jsonify({'status': 'error', 'message': 'Not connected'}), 400
return api_error('Not connected', 400)
return jsonify({
'status': 'success',