feat: notification sound and browser notifications on task completion
Add two new settings (both default off): - sound_enabled: plays a short tone via Web Audio API when assistant finishes a response or requests approval - notifications_enabled: shows a browser notification when a response completes while the tab is in the background Uses Web Audio API (oscillator) instead of bundled MP3 file — zero additional assets. Follows the standard 4-file settings pattern. Also skip test_valid_skill_accepted when hermes-agent not installed (skills endpoint returns 500 without the agent module). Inspired by #176 (DavidSchuchert) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -143,6 +143,8 @@ async function send(){
|
||||
const d=JSON.parse(e.data);
|
||||
d._session_id=activeSid;
|
||||
showApprovalCard(d);
|
||||
playNotificationSound();
|
||||
sendBrowserNotification('Approval required',d.description||'Tool approval needed');
|
||||
});
|
||||
|
||||
source.addEventListener('done',e=>{
|
||||
@@ -176,6 +178,8 @@ async function send(){
|
||||
syncTopbar();renderMessages();loadDir('.');
|
||||
}
|
||||
renderSessionList();setBusy(false);setStatus('');
|
||||
playNotificationSound();
|
||||
sendBrowserNotification('Response complete',assistantText?assistantText.slice(0,100):'Task finished');
|
||||
});
|
||||
|
||||
source.addEventListener('compressed',e=>{
|
||||
@@ -360,5 +364,36 @@ function startApprovalPolling(sid) {
|
||||
function stopApprovalPolling() {
|
||||
if (_approvalPollTimer) { clearInterval(_approvalPollTimer); _approvalPollTimer = null; }
|
||||
}
|
||||
|
||||
// ── Notifications and Sound ──────────────────────────────────────────────────
|
||||
|
||||
function playNotificationSound(){
|
||||
if(!window._soundEnabled) return;
|
||||
try{
|
||||
const ctx=new (window.AudioContext||window.webkitAudioContext)();
|
||||
const osc=ctx.createOscillator();
|
||||
const gain=ctx.createGain();
|
||||
osc.connect(gain);gain.connect(ctx.destination);
|
||||
osc.type='sine';osc.frequency.setValueAtTime(660,ctx.currentTime);
|
||||
osc.frequency.setValueAtTime(880,ctx.currentTime+0.1);
|
||||
gain.gain.setValueAtTime(0.3,ctx.currentTime);
|
||||
gain.gain.exponentialRampToValueAtTime(0.01,ctx.currentTime+0.3);
|
||||
osc.start(ctx.currentTime);osc.stop(ctx.currentTime+0.3);
|
||||
}catch(e){console.warn('Notification sound failed:',e);}
|
||||
}
|
||||
|
||||
function sendBrowserNotification(title,body){
|
||||
if(!window._notificationsEnabled||!document.hidden) return;
|
||||
if(!('Notification' in window)) return;
|
||||
const botName=window._botName||'Hermes';
|
||||
if(Notification.permission==='granted'){
|
||||
new Notification(title||botName,{body:body});
|
||||
}else if(Notification.permission!=='denied'){
|
||||
Notification.requestPermission().then(p=>{
|
||||
if(p==='granted') new Notification(title||botName,{body:body});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ── Panel navigation (Chat / Tasks / Skills / Memory) ──
|
||||
|
||||
|
||||
Reference in New Issue
Block a user