async function load() { try { const response = await fetch(`/api/state?${windowQuery()}`, {cache: "no-store"}); if (!response.ok) { throw new Error(String(response.status)); } const next = await response.json(); const previous = state.now; state = next; ui.offline = false; if (JSON.stringify(state.settings) !== settingsSig) { adoptSettings(state.settings); } tuneMusic(FADE / 1000); drawSky(); announce(); render(false); drawTime(); drawAgent(); drawStream(); if (motion.current.size === 0 || ui.asOf !== motion.asOf) { const first = motion.current.size === 0; motion.asOf = ui.asOf; relayout(first ? 0 : ui.playing ? 450 : MOVE); } pulses(state.radio.filter((row) => row.ts > previous)); } catch { ui.offline = true; tick(); } } const SELECTION_HOLD = 20000; let selectedSince = 0; function refresh() { const selected = String(window.getSelection()).length > 0; selectedSince = selected ? selectedSince || Date.now() : 0; if (!ui.busy && !ui.playing && !document.hidden && (!selected || Date.now() - selectedSince >= SELECTION_HOLD)) { load(); } } function follow() { if (ui.screen === "stream" && live() && !document.hidden) { fetchEvents(); } }