From 79d3be64f0a3e4552b08c80f1678649ccbff2a7c Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 11 Nov 2026 10:01:11 +0100 Subject: feat(windows): a new window brings the Windows tab forward When a window id appears that the last poll did not list, the tablet shows the Windows tab for [windows] peek seconds (default 8, 0 off) and then goes back to the tab it was on. A touch on the page or a tab change meanwhile keeps it there; another new window restarts the timer. The hook is generic: a panel's peek(state) returns seconds, app.js does the switching. The first poll only learns what is open, and an error state keeps what it knew, so neither triggers it. Co-Authored-By: Claude Opus 5.5 --- static/app.js | 23 ++++++++++++++++++++++- static/modules/windows.js | 10 ++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'static') diff --git a/static/app.js b/static/app.js index 79010bf..a15c2de 100644 --- a/static/app.js +++ b/static/app.js @@ -65,6 +65,7 @@ function sortTabs() { } function showTab(name) { + keep(); for (const [n, tab] of Object.entries(tabs)) { tab.section.hidden = n !== name; tab.button.classList.toggle("active", n === name); @@ -74,6 +75,21 @@ function showTab(name) { } catch {} } +// A panel's peek(state) gives seconds when something new turned up: its tab +// comes forward that long, then the page goes back, unless touched first. +let peek = null; // {back, timer} while a tab is shown on its own +function peekTab(name, seconds) { + const now = Object.keys(tabs).find((n) => !tabs[n].section.hidden); + if (now === name && !peek) return; // already there by choice + const back = peek?.back ?? now; + showTab(name); + peek = { back, timer: setTimeout(() => showTab(back), seconds * 1000) }; +} +function keep() { + if (peek) clearTimeout(peek.timer); + peek = null; +} + const dashboard = ensureTab("Dashboard"); dashboard.section.hidden = false; dashboard.button.classList.add("active"); @@ -102,7 +118,11 @@ function mountTab(name, panel, section) { wrap.className = "tab-content"; section.append(wrap); panel.mount?.(wrap); - poll(name, panel.interval ?? 1, (st) => panel.update?.(st, wrap)); + poll(name, panel.interval ?? 1, (st) => { + panel.update?.(st, wrap); + const seconds = panel.peek?.(st); + if (seconds > 0) peekTab(panel.tab, seconds); + }); } // Modules with no panel file: dashboard.js draws them. @@ -151,6 +171,7 @@ function stepTab(dir) { let swipe = null; let swallowClick = false; tabBody.addEventListener("pointerdown", (e) => { + keep(); if (e.pointerType === "mouse" && e.buttons !== 1) return; if (e.target.closest("input, select, textarea")) { swipe = null; diff --git a/static/modules/windows.js b/static/modules/windows.js index 7e2a184..d9f388e 100644 --- a/static/modules/windows.js +++ b/static/modules/windows.js @@ -165,6 +165,16 @@ export default { `; }, + // A window that was not there on the last poll brings the tab forward for + // [windows] peek seconds. + peek(st) { + if (!st.windows) return false; + const ids = new Set(st.windows.map((w) => w.id)); + const fresh = this._ids != null && [...ids].some((id) => !this._ids.has(id)); + this._ids = ids; + return fresh ? st.peek ?? 8 : 0; + }, + update(st, el) { // Polled every second: rebuilding unchanged rows reloads every icon // through its fallbacks, which flickers, so only a change re-renders. -- cgit v1.2.3