feat: show active session name in browser tab title

Updates document.title dynamically to show the current session label
(e.g. 'main — PinchChat'). Integrates with the existing notification
system so unread badges still work correctly (e.g. '(3) main — PinchChat').
Resets to plain 'PinchChat' when no session is selected.
This commit is contained in:
Nicolas Varrot
2026-02-12 09:17:15 +00:00
parent b5eafdeed8
commit e53ef36715
2 changed files with 21 additions and 4 deletions

View File

@@ -1,7 +1,17 @@
import { useState, useEffect, useCallback, useRef } from 'react';
import { playNotificationSound } from '../lib/notificationSound';
const ORIGINAL_TITLE = document.title;
const APP_NAME = 'PinchChat';
let baseTitle = APP_NAME;
/** Update the base title (e.g. with active session name). Called by App. */
export function setBaseTitle(sessionLabel?: string) {
baseTitle = sessionLabel ? `${sessionLabel}${APP_NAME}` : APP_NAME;
// Refresh document.title if tab is visible (no unread badge)
if (!document.hidden) {
document.title = baseTitle;
}
}
const SOUND_KEY = 'pinchchat-notification-sound';
const hasNotificationAPI = typeof Notification !== 'undefined';
@@ -25,7 +35,7 @@ export function useNotifications() {
if (!document.hidden) {
// Reset unread when tab becomes visible
setUnreadCount(0);
document.title = ORIGINAL_TITLE;
document.title = baseTitle;
}
};
document.addEventListener('visibilitychange', handleVisibility);
@@ -35,7 +45,7 @@ export function useNotifications() {
// Update tab title when unread count changes
useEffect(() => {
if (unreadCount > 0) {
document.title = `(${unreadCount}) ${ORIGINAL_TITLE}`;
document.title = `(${unreadCount}) ${baseTitle}`;
}
}, [unreadCount]);