Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,30 @@ terminalStopBtn.addEventListener('click', () => {


// --- Poll for active PTY sessions ---
// Adaptive cadence: poll fast (3s) only while PTYs are running; when idle, back
// off to 30s. Every renderer path that starts a session (launchNewSession,
// openSession, launchTerminalSession, onSessionDetected/Forked) calls
// pollActiveSessions() explicitly, which re-arms the fast cadence immediately.
// The 30s idle floor still catches sessions started outside the renderer
// (scheduler-spawned PTYs, other windows) within at most 30s.
const POLL_FAST_MS = 3000;
const POLL_IDLE_MS = 30000;
let pollTimer = null;

function scheduleActiveSessionsPoll() {
if (pollTimer) clearTimeout(pollTimer);
const delay = activePtyIds.size > 0 ? POLL_FAST_MS : POLL_IDLE_MS;
pollTimer = setTimeout(pollActiveSessions, delay);
}

async function pollActiveSessions() {
try {
const ids = await window.api.getActiveSessions();
activePtyIds = new Set(ids);
updateRunningIndicators();
updateTerminalHeader();
} catch {}
scheduleActiveSessionsPoll();
}

function updateRunningIndicators() {
Expand Down Expand Up @@ -592,10 +609,11 @@ function updatePtyTitle() {
terminalHeaderPtyTitle.style.display = title ? '' : 'none';
}

setInterval(pollActiveSessions, 3000);
scheduleActiveSessionsPoll();

// Refresh sidebar timeago labels every 30s so "just now" ticks forward
setInterval(() => {
if (lastActivityTime.size === 0) return;
for (const [sessionId, time] of lastActivityTime) {
const item = document.getElementById('si-' + sessionId);
if (!item) continue;
Expand Down