From 3891d9b61d77969b7623a1fd485542f9e5c8c70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dejan=20Ro=C5=BEi=C4=8D?= Date: Tue, 21 Apr 2026 09:07:28 +0200 Subject: [PATCH] the page uses server-side stale detection first, so another PC with wrong clock should not falsely blur the UI --- static/index.html | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/static/index.html b/static/index.html index e541781..0b6c411 100644 --- a/static/index.html +++ b/static/index.html @@ -810,7 +810,6 @@ ctx.fillText((Number(knValue) || 0).toFixed(1) + ' ' + UNIT_FORCE, cx, cy + 58); } - // FIX: update digital display HTML elements (only visible when show_gauge_digital: true) function updateDigitalDisplay(side, percent, kn) { if (!SHOW_GAUGE_DIGITAL) return; const el = document.getElementById('digital-' + side); @@ -1132,6 +1131,20 @@ } catch (err) { console.warn('UI revision check error:', err); } } + function computeStaleFromPayload(d, connected) { + if (!connected) return false; + if (typeof d.stale === 'boolean') return d.stale; + if (!d.last_update) return false; + + const lastTs = new Date(d.last_update).getTime(); + if (isNaN(lastTs)) return false; + + const serverNowTs = d.server_time ? new Date(d.server_time).getTime() : Date.now(); + if (isNaN(serverNowTs)) return false; + + return (serverNowTs - lastTs) > STALE_MS; + } + async function fetchLiveData() { try { const res = await fetch('/api/data', { cache: 'no-store' }); @@ -1148,12 +1161,7 @@ const bias = Number(d.bias_percent) || 0; const leftKN = Number(d.sila_l_kn) || 0; const rightKN = Number(d.sila_r_kn) || 0; - - let stale = false; - if (connected && d.last_update) { - const lastTs = new Date(d.last_update).getTime(); - if (!isNaN(lastTs)) stale = (Date.now() - lastTs) > STALE_MS; - } + const stale = computeStaleFromPayload(d, connected); setConnectionIndicator(connected, stale); setProcessVisualState(connected && !stale); @@ -1171,8 +1179,6 @@ applyChannelState('l', leftPercent); applyChannelState('r', rightPercent); - - // FIX: update digital HTML displays (was missing in original) updateDigitalDisplay('l', leftPercent, leftKN); updateDigitalDisplay('r', rightPercent, rightKN); @@ -1188,7 +1194,6 @@ updateSummaryBar(false, false, 0, 0, 0); updateMachineVerdict(false, false, 0, 0, 0); updateAlarmBanner(0, 0, 0, false, false); - // FIX: reset digital displays on error updateDigitalDisplay('l', 0, 0); updateDigitalDisplay('r', 0, 0); } @@ -1426,4 +1431,4 @@ }; - \ No newline at end of file +