mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
7a69d8602c
commit
234feb4d55
3 files changed
+32
No files matched your search
@@ -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<Partial<Record<SoundEventId, string>>>({});
|
||||
const [eventEnabled, setEventEnabled] = useState<Record<SoundEventId, boolean>>(() =>
|
||||
Object.fromEntries(SOUND_EVENTS.map((id) => [id, loadEventSoundEnabled(id)])) as Record<SoundEventId, boolean>
|
||||
);
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const uploadTargetRef = useRef<SoundEventId | null>(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() {
|
||||
<tbody>
|
||||
{SOUND_EVENTS.map((eventId) => (
|
||||
<tr key={eventId}>
|
||||
<td>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={eventEnabled[eventId]}
|
||||
onChange={() => handleToggleEventEnabled(eventId)}
|
||||
title={t("sounds.eventEnable")}
|
||||
/>
|
||||
</td>
|
||||
<td>{t(`sounds.event.${eventId}`)}</td>
|
||||
<td className="ts-options-sounds-source">
|
||||
{customNames[eventId] ? t("sounds.custom", { name: customNames[eventId]! }) : t("sounds.default")}
|
||||
|
||||
@@ -203,6 +203,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"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<Lang, Record<string, string>> = {
|
||||
"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",
|
||||
|
||||
@@ -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<void> {
|
||||
if (!loadSoundsEnabled()) return;
|
||||
if (!loadEventSoundEnabled(event)) return;
|
||||
const volume = loadSoundsVolume();
|
||||
const custom = await loadCustomSound(event).catch(() => undefined);
|
||||
if (custom) {
|
||||
|
||||
Reference in new issue
Block a user