[fix](trx-frontend-http): make /status respect per-tab rig selection

pollFreshSnapshot() fetches GET /status on every SSE connect/reconnect,
but /status always returned the global selected rig's state, overwriting
the per-tab display with whichever rig was last switched to globally.

Now pollFreshSnapshot passes rig_id as a query param and the /status
endpoint uses the per-rig watch channel when provided, matching the
/events behavior for true per-tab rig isolation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
2026-03-22 00:14:43 +01:00
parent 0836c815e4
commit f3d8d349b1
2 changed files with 19 additions and 2 deletions
@@ -3163,7 +3163,10 @@ function scheduleReconnect(delayMs = 1000) {
async function pollFreshSnapshot() { async function pollFreshSnapshot() {
try { try {
const resp = await fetch("/status", { cache: "no-store" }); const statusUrl = lastActiveRigId
? `/status?rig_id=${encodeURIComponent(lastActiveRigId)}`
: "/status";
const resp = await fetch(statusUrl, { cache: "no-store" });
if (!resp.ok) return; if (!resp.ok) return;
const data = await resp.json(); const data = await resp.json();
render(data); render(data);
@@ -135,13 +135,27 @@ impl SessionRigManager {
pub type SharedSessionRigManager = Arc<SessionRigManager>; pub type SharedSessionRigManager = Arc<SessionRigManager>;
#[derive(serde::Deserialize)]
pub struct StatusQuery {
pub rig_id: Option<String>,
}
#[get("/status")] #[get("/status")]
pub async fn status_api( pub async fn status_api(
query: web::Query<StatusQuery>,
state: web::Data<watch::Receiver<RigState>>, state: web::Data<watch::Receiver<RigState>>,
clients: web::Data<Arc<AtomicUsize>>, clients: web::Data<Arc<AtomicUsize>>,
context: web::Data<Arc<FrontendRuntimeContext>>, context: web::Data<Arc<FrontendRuntimeContext>>,
) -> Result<impl Responder, Error> { ) -> Result<impl Responder, Error> {
let state = wait_for_view(state.get_ref().clone()).await?; // Prefer the per-rig watch channel when a rig_id is specified,
// falling back to the global state watch.
let rx = query
.rig_id
.as_deref()
.filter(|s| !s.is_empty())
.and_then(|rid| context.rig_state_rx(rid))
.unwrap_or_else(|| state.get_ref().clone());
let state = wait_for_view(rx).await?;
let json = serde_json::to_string(&state).map_err(actix_web::error::ErrorInternalServerError)?; let json = serde_json::to_string(&state).map_err(actix_web::error::ErrorInternalServerError)?;
let json = inject_frontend_meta( let json = inject_frontend_meta(
&json, &json,