web: add notification sound toggle and complete notifications module
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-03-08 22:51:39 +03:00
parent 7889c7a958
commit d7513d7caf
4 changed files with 40 additions and 2 deletions

View File

@@ -448,6 +448,9 @@ function maybeShowBrowserNotification(
const titleBase = chat?.display_title || chat?.title || "New message";
const title = isMention ? `@ Mention in ${titleBase}` : titleBase;
const preview = buildNotificationPreview(message, prefs.messagePreview);
if (prefs.notificationSound) {
playNotificationSound();
}
void (async () => {
const shownViaSw = await showNotificationViaServiceWorker({
@@ -492,3 +495,34 @@ function hasMentionForUser(text: string | null, username: string | null): boolea
}
}
}
function playNotificationSound(): void {
if (typeof window === "undefined") {
return;
}
const AudioContextCtor =
window.AudioContext ||
(window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
if (!AudioContextCtor) {
return;
}
try {
const context = new AudioContextCtor();
const oscillator = context.createOscillator();
const gain = context.createGain();
oscillator.type = "sine";
oscillator.frequency.setValueAtTime(880, context.currentTime);
gain.gain.setValueAtTime(0.0001, context.currentTime);
gain.gain.exponentialRampToValueAtTime(0.08, context.currentTime + 0.01);
gain.gain.exponentialRampToValueAtTime(0.0001, context.currentTime + 0.16);
oscillator.connect(gain);
gain.connect(context.destination);
oscillator.start();
oscillator.stop(context.currentTime + 0.17);
oscillator.onended = () => {
void context.close();
};
} catch {
return;
}
}