From b9364119daa01f3a9e091f75d70ad1e14233b248 Mon Sep 17 00:00:00 2001 From: oOHiyoriOo Date: Sat, 13 Jun 2026 18:20:55 +0200 Subject: [PATCH] fix: serverInfo page shows data immediately on load Eliminated redundant serverinfo RCON polling from the serverInfo page. It now subscribes to the header's serverinfo-update CustomEvent instead. Key changes: - app.js: cache last serverinfo in window._lastServerInfo and dispatch serverinfo-update event so pages can pick up data immediately - serverInfo.js: replaced setInterval-based polling with event listener plus immediate _lastServerInfo cache check, eliminating the initial blank page state and duplicate RCON requests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- js/app.js | 4 ++++ js/pages/serverInfo.js | 25 ++++++------------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/js/app.js b/js/app.js index 4dc34c8..65e5a83 100644 --- a/js/app.js +++ b/js/app.js @@ -46,6 +46,10 @@ document.getElementById('header-players').innerHTML = ' ' + formatNumber(data.Players) + '/' + formatNumber(data.MaxPlayers); document.getElementById('header-fps').innerHTML = ' ' + formatNumber(data.Framerate) + 'fps'; document.getElementById('header-entities').innerHTML = ' ' + formatNumber(data.EntityCount); + + // Cache for late-arriving pages (e.g. serverInfo) and broadcast to listeners + window._lastServerInfo = data; + document.dispatchEvent(new CustomEvent('serverinfo-update', { detail: data })); }); } diff --git a/js/pages/serverInfo.js b/js/pages/serverInfo.js index a8d98d8..68dc0cf 100644 --- a/js/pages/serverInfo.js +++ b/js/pages/serverInfo.js @@ -45,13 +45,6 @@ function ServerInfoPage(params, container) { ''; container.innerHTML = html; - // Start data polling immediately — charts will render when ready - if (Rcon.isConnected()) startPolling(); - else { - var _c = function () { startPolling(); Rcon.off('connected', _c); }; - Rcon.on('connected', _c); - } - // ---- NVD3 Charts ---- nv.addGraph(function () { var perfChart = nv.models.multiChart() @@ -109,13 +102,12 @@ function ServerInfoPage(params, container) { }); // ---- Data polling ---- - var pollTimer = null; + // Subscribe to header's serverinfo updates (no redundant RCON request) + function onServerInfo(e) { updateData(e.detail); } + document.addEventListener('serverinfo-update', onServerInfo); - function refresh() { - Rcon.request('serverinfo', function (msg) { - updateData(JSON.parse(msg.Message)); - }); - } + // If header already has cached data, use it immediately + if (window._lastServerInfo) updateData(window._lastServerInfo); function updateData(data) { // Guard: element may be gone if navigated away @@ -185,13 +177,8 @@ function ServerInfoPage(params, container) { } } - function startPolling() { - refresh(); - pollTimer = setInterval(refresh, 1000); - } - return function cleanup() { - if (pollTimer) clearInterval(pollTimer); + document.removeEventListener('serverinfo-update', onServerInfo); window._perfChart = null; window._netChart = null; window._playersChart = null;