Files
devdesk/web/src/notify.js
T
jaredandClaude Opus 5.5 a2edec966a
build-deb / Notify on failure (push) Successful in 4s
build-deb / Lint, test, package (push) Failing after 2m22s
build-deb / Deploy to CT 126 (push) Skipped
feat: v0.10.0 quieter Matrix, worktrees, usage pace, repo diffs, copy reply, turn timer, compact
- Matrix "needs you": ignore Claude's idle reminder (no red, no post); post
  only when no tab is in view, after 60 s, once per session per 10 min, and
  say what is asked. Closes #50
- devdesk new NAME PROJECT --worktree: own checkout on devdesk/NAME,
  cleaned up on end when clean/merged. Closes #44
- Usage meters: reset time, pace warning; Matrix ping past 90% when away.
  Closes #45
- Repo panel lists changed files; click opens the diff. Closes #46
- Copy Claude's last reply (--last-reply). Closes #47
- Turn timer in chip, title and cards. Closes #48
- Compact button at 80% context when idle. Closes #49

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WHRLCCdXYm41Qx5kNhehaP
2026-10-11 23:28:11 -04:00

87 lines
2.1 KiB
JavaScript

// Bell → attention: desktop notification, favicon badge and a title prefix while
// the tab is in the background. Claude rings the bell (preferredNotifChannel:
// terminal_bell) when it finishes a turn or needs input.
import { FAVICON, FAVICON_BADGE } from './icon.js';
let unread = 0;
let baseTitle = document.title;
let statusPrefix = '';
function attentive() {
return !document.hidden && document.hasFocus();
}
function render() {
document.title = `${unread ? `(${unread}) ` : ''}${statusPrefix}${baseTitle}`;
const link = document.getElementById('favicon');
if (link) link.href = unread ? FAVICON_BADGE : FAVICON;
}
export function setBaseTitle(title) {
baseTitle = title;
render();
}
// "⏳ 3m · " while Claude works on a turn in this tab's session (devdesk#48).
export function setStatusPrefix(prefix) {
if (prefix === statusPrefix) return;
statusPrefix = prefix;
render();
}
export function notificationsState() {
if (!('Notification' in window)) return 'unsupported';
return Notification.permission; // granted | denied | default
}
export async function requestNotifications() {
if (notificationsState() !== 'default') return notificationsState();
return Notification.requestPermission();
}
const MUTE_KEY = 'devdesk.notify.muted';
export function isMuted() {
try {
return localStorage.getItem(MUTE_KEY) === '1';
} catch {
return false;
}
}
export function setMuted(muted) {
try {
localStorage.setItem(MUTE_KEY, muted ? '1' : '0');
} catch {
// Private mode: the mute just won't persist.
}
}
export function ring(session, detail) {
if (attentive()) return;
unread += 1;
render();
if (notificationsState() === 'granted' && !isMuted()) {
const note = new Notification(`Claude · ${session || 'devdesk'}`, {
body: detail || 'Claude needs your attention',
tag: `devdesk-${session}`,
renotify: true,
icon: FAVICON,
});
note.onclick = () => {
window.focus();
note.close();
};
}
}
function clear() {
if (!unread || !attentive()) return;
unread = 0;
render();
}
window.addEventListener('focus', clear);
document.addEventListener('visibilitychange', clear);