From 234feb4d552e73393e1b1d764c485d3ff8850b13 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Thu, 30 Jul 2026 23:10:19 +0200 Subject: [PATCH] Add per-event checkbox to mute individual sound notifications Lets users disable e.g. join/leave chimes while keeping others on, without touching the master sounds toggle. Co-Authored-By: Claude Sonnet 5 --- web/src/App.tsx | 19 +++++++++++++++++++ web/src/i18n.tsx | 2 ++ web/src/sounds.ts | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/web/src/App.tsx b/web/src/App.tsx index f71496f..1fcd65d 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -14,10 +14,12 @@ import { SOUND_EVENTS, clearCustomSound, loadCustomSound, + loadEventSoundEnabled, loadSoundsEnabled, loadSoundsVolume, playSound, saveCustomSound, + saveEventSoundEnabled, saveSoundsEnabled, saveSoundsVolume, setSoundsOutputDevice, @@ -1048,6 +1050,9 @@ function SoundsPanel() { const [enabled, setEnabled] = useState(() => loadSoundsEnabled()); const [volume, setVolume] = useState(() => loadSoundsVolume()); const [customNames, setCustomNames] = useState>>({}); + const [eventEnabled, setEventEnabled] = useState>(() => + Object.fromEntries(SOUND_EVENTS.map((id) => [id, loadEventSoundEnabled(id)])) as Record + ); const fileInputRef = useRef(null); const uploadTargetRef = useRef(null); @@ -1078,6 +1083,12 @@ function SoundsPanel() { saveSoundsVolume(v); }; + const handleToggleEventEnabled = (event: SoundEventId) => { + const next = !eventEnabled[event]; + setEventEnabled((prev) => ({ ...prev, [event]: next })); + saveEventSoundEnabled(event, next); + }; + const handleUploadClick = (event: SoundEventId) => { uploadTargetRef.current = event; fileInputRef.current?.click(); @@ -1125,6 +1136,14 @@ function SoundsPanel() { {SOUND_EVENTS.map((eventId) => ( + + handleToggleEventEnabled(eventId)} + title={t("sounds.eventEnable")} + /> + {t(`sounds.event.${eventId}`)} {customNames[eventId] ? t("sounds.custom", { name: customNames[eventId]! }) : t("sounds.default")} diff --git a/web/src/i18n.tsx b/web/src/i18n.tsx index c436420..ac5a8de 100644 --- a/web/src/i18n.tsx +++ b/web/src/i18n.tsx @@ -203,6 +203,7 @@ const translations: Record> = { "sounds.subtitle": "Sound-Benachrichtigungen für Ereignisse festlegen", "sounds.enable": "Sounds aktivieren", "sounds.volume": "Lautstärke", + "sounds.eventEnable": "Diesen Sound aktivieren", "sounds.event.connect": "Verbunden", "sounds.event.disconnect": "Getrennt", "sounds.event.clientJoin": "Client kommt", @@ -408,6 +409,7 @@ const translations: Record> = { "sounds.subtitle": "Configure sound notifications for events", "sounds.enable": "Enable sounds", "sounds.volume": "Volume", + "sounds.eventEnable": "Enable this sound", "sounds.event.connect": "Connected", "sounds.event.disconnect": "Disconnected", "sounds.event.clientJoin": "Client joins", diff --git a/web/src/sounds.ts b/web/src/sounds.ts index 717aa1a..12fac94 100644 --- a/web/src/sounds.ts +++ b/web/src/sounds.ts @@ -4,6 +4,7 @@ export const SOUND_EVENTS: SoundEventId[] = ["connect", "disconnect", "clientJoi const ENABLED_KEY = "webspeak3:sounds-enabled"; const VOLUME_KEY = "webspeak3:sounds-volume"; +const EVENT_ENABLED_KEY_PREFIX = "webspeak3:sounds-enabled:"; const DB_NAME = "webspeak3-sounds"; const STORE_NAME = "custom"; @@ -66,6 +67,15 @@ export function saveSoundsEnabled(enabled: boolean): void { localStorage.setItem(ENABLED_KEY, String(enabled)); } +export function loadEventSoundEnabled(event: SoundEventId): boolean { + const raw = localStorage.getItem(EVENT_ENABLED_KEY_PREFIX + event); + return raw === null ? true : raw === "true"; +} + +export function saveEventSoundEnabled(event: SoundEventId, enabled: boolean): void { + localStorage.setItem(EVENT_ENABLED_KEY_PREFIX + event, String(enabled)); +} + export function loadSoundsVolume(): number { const raw = localStorage.getItem(VOLUME_KEY); const n = raw ? Number(raw) : 0.5; @@ -196,6 +206,7 @@ export function setSoundsOutputDevice(deviceId: string): void { export async function playSound(event: SoundEventId): Promise { if (!loadSoundsEnabled()) return; + if (!loadEventSoundEnabled(event)) return; const volume = loadSoundsVolume(); const custom = await loadCustomSound(event).catch(() => undefined); if (custom) {