feat(webui): add completion notification sound preference

When a turn finishes while the user is watching the page there is no
audible cue; the existing browser notifications only cover the
background case. Add a `notificationSound` local preference (off by
default, next to `browserNotifications`) and play a short bundled
chime from the `turn_end` handler only while the page is visible, so
background tabs stay silent.

- webui/src/lib/notification-sound.ts: visibility- and preference-gated
  playback of the bundled /notification.wav, one reused Audio element
- Overview settings toggle with localized copy in all 10 locales
- Tests cover the default-off, visible, hidden, reuse and
  playback-rejection paths
This commit is contained in:
Li Fengmin authored and chengyongru committed 2026-09-24 17:34:33 +08:00
1 parent 3ecc3d3556
commit 7c2bf8949c
17 files changed
+156

No files matched your search

+3
View File
@@ -6,6 +6,7 @@ export interface LocalPreferences {
codeWrap: boolean;
brandLogos: boolean;
browserNotifications: boolean;
notificationSound: boolean;
fileEditDisplayMode: FileEditDisplayMode;
}
@@ -22,6 +23,7 @@ export const DEFAULT_LOCAL_PREFS: LocalPreferences = {
codeWrap: true,
brandLogos: true,
browserNotifications: false,
notificationSound: false,
fileEditDisplayMode: "summary",
};
@@ -41,6 +43,7 @@ export function readLocalPreferences(): LocalPreferences {
? parsed.brandLogos !== false
: true,
browserNotifications: parsed.browserNotifications === true,
notificationSound: parsed.notificationSound === true,
fileEditDisplayMode: normalizeFileEditDisplayMode(parsed.fileEditDisplayMode),
};
} catch {
+25
View File
@@ -0,0 +1,25 @@
// The short chime played when an agent turn completes while the page is
// visible (#5524). The asset ships with the WebUI's static files; playback is
// gated by the `notificationSound` local preference — off by default — and
// by page visibility: the chime is for someone actively watching the tab, so
// a background tab stays silent (browserNotifications covers that case).
import { readLocalPreferences } from "@/lib/local-preferences";
export const TURN_COMPLETE_SOUND_PATH = "/notification.wav";
let audio: HTMLAudioElement | null = null;
export function playTurnCompleteSound(): void {
try {
if (document.visibilityState !== "visible") return;
if (!readLocalPreferences().notificationSound) return;
if (audio === null) audio = new Audio(TURN_COMPLETE_SOUND_PATH);
audio.currentTime = 0;
void audio.play().catch(() => {
// Autoplay policies or a missing asset must never surface as an error.
});
} catch {
// A notification chime must never break the stream.
}
}