Skip to content

Commit 61d2def

Browse files
committed
unread indicator
1 parent 230814b commit 61d2def

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

renderer.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,28 @@ function addTab(sessionId: string, name: string) {
312312

313313
function markSessionAsUnread(sessionId: string) {
314314
const session = sessions.get(sessionId);
315-
if (!session) return;
315+
if (!session) {
316+
console.log(`[Unread] ERROR: Session ${sessionId} not found`);
317+
return;
318+
}
316319

320+
console.log(`[Unread] Setting hasUnreadActivity flag for session ${sessionId}`);
317321
session.hasUnreadActivity = true;
318322

319323
// Add unread indicator to tab
320324
const tab = document.getElementById(`tab-${sessionId}`);
321-
if (tab && !tab.classList.contains("unread")) {
322-
tab.classList.add("unread");
325+
console.log(`[Unread] Tab element for ${sessionId}:`, tab);
326+
if (tab) {
327+
console.log(`[Unread] Tab classes before:`, tab.className);
328+
if (!tab.classList.contains("unread")) {
329+
tab.classList.add("unread");
330+
console.log(`[Unread] ✓ Added 'unread' class to tab ${sessionId}`);
331+
console.log(`[Unread] Tab classes after:`, tab.className);
332+
} else {
333+
console.log(`[Unread] Tab ${sessionId} already has 'unread' class`);
334+
}
335+
} else {
336+
console.log(`[Unread] ERROR: No tab element found for session ${sessionId}`);
323337
}
324338
}
325339

@@ -442,15 +456,36 @@ function deleteSession(sessionId: string) {
442456
}
443457
}
444458

459+
// Track idle timers per session to detect when output stops (Claude is done)
460+
const sessionIdleTimers = new Map<string, NodeJS.Timeout>();
461+
const IDLE_DELAY_MS = 500; // 0.5 seconds of no output = Claude is done
462+
445463
// Handle session output
446464
ipcRenderer.on("session-output", (_event, sessionId: string, data: string) => {
447465
const session = sessions.get(sessionId);
448466
if (session && session.terminal) {
449467
session.terminal.write(data);
450468

451-
// Mark as unread if this is not the active session and there's output
469+
// Only mark as unread if this is not the active session
452470
if (activeSessionId !== sessionId && session.hasActivePty) {
453-
markSessionAsUnread(sessionId);
471+
console.log(`[Unread] Session ${sessionId} received output while inactive`);
472+
473+
// Clear any existing idle timer
474+
const existingTimer = sessionIdleTimers.get(sessionId);
475+
if (existingTimer) {
476+
console.log(`[Unread] Clearing existing idle timer for session ${sessionId}`);
477+
clearTimeout(existingTimer);
478+
}
479+
480+
// Set a new timer - if no output for IDLE_DELAY_MS, mark as unread
481+
const timer = setTimeout(() => {
482+
console.log(`[Unread] ✓ No output for ${IDLE_DELAY_MS}ms - Claude is done! Marking session ${sessionId} as unread`);
483+
markSessionAsUnread(sessionId);
484+
sessionIdleTimers.delete(sessionId);
485+
}, IDLE_DELAY_MS);
486+
487+
sessionIdleTimers.set(sessionId, timer);
488+
console.log(`[Unread] Set idle timer for session ${sessionId} - will trigger in ${IDLE_DELAY_MS}ms if no more output`);
454489
}
455490
}
456491
});

0 commit comments

Comments
 (0)