mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +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,
|
SOUND_EVENTS,
|
||||||
clearCustomSound,
|
clearCustomSound,
|
||||||
loadCustomSound,
|
loadCustomSound,
|
||||||
|
loadEventSoundEnabled,
|
||||||
loadSoundsEnabled,
|
loadSoundsEnabled,
|
||||||
loadSoundsVolume,
|
loadSoundsVolume,
|
||||||
playSound,
|
playSound,
|
||||||
saveCustomSound,
|
saveCustomSound,
|
||||||
|
saveEventSoundEnabled,
|
||||||
saveSoundsEnabled,
|
saveSoundsEnabled,
|
||||||
saveSoundsVolume,
|
saveSoundsVolume,
|
||||||
setSoundsOutputDevice,
|
setSoundsOutputDevice,
|
||||||
@@ -1048,6 +1050,9 @@ function SoundsPanel() {
|
|||||||
const [enabled, setEnabled] = useState(() => loadSoundsEnabled());
|
const [enabled, setEnabled] = useState(() => loadSoundsEnabled());
|
||||||
const [volume, setVolume] = useState(() => loadSoundsVolume());
|
const [volume, setVolume] = useState(() => loadSoundsVolume());
|
||||||
const [customNames, setCustomNames] = useState<Partial<Record<SoundEventId, string>>>({});
|
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 fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||||
const uploadTargetRef = useRef<SoundEventId | null>(null);
|
const uploadTargetRef = useRef<SoundEventId | null>(null);
|
||||||
|
|
||||||
@@ -1078,6 +1083,12 @@ function SoundsPanel() {
|
|||||||
saveSoundsVolume(v);
|
saveSoundsVolume(v);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleToggleEventEnabled = (event: SoundEventId) => {
|
||||||
|
const next = !eventEnabled[event];
|
||||||
|
setEventEnabled((prev) => ({ ...prev, [event]: next }));
|
||||||
|
saveEventSoundEnabled(event, next);
|
||||||
|
};
|
||||||
|
|
||||||
const handleUploadClick = (event: SoundEventId) => {
|
const handleUploadClick = (event: SoundEventId) => {
|
||||||
uploadTargetRef.current = event;
|
uploadTargetRef.current = event;
|
||||||
fileInputRef.current?.click();
|
fileInputRef.current?.click();
|
||||||
@@ -1125,6 +1136,14 @@ function SoundsPanel() {
|
|||||||
<tbody>
|
<tbody>
|
||||||
{SOUND_EVENTS.map((eventId) => (
|
{SOUND_EVENTS.map((eventId) => (
|
||||||
<tr key={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>{t(`sounds.event.${eventId}`)}</td>
|
||||||
<td className="ts-options-sounds-source">
|
<td className="ts-options-sounds-source">
|
||||||
{customNames[eventId] ? t("sounds.custom", { name: customNames[eventId]! }) : t("sounds.default")}
|
{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.subtitle": "Sound-Benachrichtigungen für Ereignisse festlegen",
|
||||||
"sounds.enable": "Sounds aktivieren",
|
"sounds.enable": "Sounds aktivieren",
|
||||||
"sounds.volume": "Lautstärke",
|
"sounds.volume": "Lautstärke",
|
||||||
|
"sounds.eventEnable": "Diesen Sound aktivieren",
|
||||||
"sounds.event.connect": "Verbunden",
|
"sounds.event.connect": "Verbunden",
|
||||||
"sounds.event.disconnect": "Getrennt",
|
"sounds.event.disconnect": "Getrennt",
|
||||||
"sounds.event.clientJoin": "Client kommt",
|
"sounds.event.clientJoin": "Client kommt",
|
||||||
@@ -408,6 +409,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"sounds.subtitle": "Configure sound notifications for events",
|
"sounds.subtitle": "Configure sound notifications for events",
|
||||||
"sounds.enable": "Enable sounds",
|
"sounds.enable": "Enable sounds",
|
||||||
"sounds.volume": "Volume",
|
"sounds.volume": "Volume",
|
||||||
|
"sounds.eventEnable": "Enable this sound",
|
||||||
"sounds.event.connect": "Connected",
|
"sounds.event.connect": "Connected",
|
||||||
"sounds.event.disconnect": "Disconnected",
|
"sounds.event.disconnect": "Disconnected",
|
||||||
"sounds.event.clientJoin": "Client joins",
|
"sounds.event.clientJoin": "Client joins",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export const SOUND_EVENTS: SoundEventId[] = ["connect", "disconnect", "clientJoi
|
|||||||
|
|
||||||
const ENABLED_KEY = "webspeak3:sounds-enabled";
|
const ENABLED_KEY = "webspeak3:sounds-enabled";
|
||||||
const VOLUME_KEY = "webspeak3:sounds-volume";
|
const VOLUME_KEY = "webspeak3:sounds-volume";
|
||||||
|
const EVENT_ENABLED_KEY_PREFIX = "webspeak3:sounds-enabled:";
|
||||||
const DB_NAME = "webspeak3-sounds";
|
const DB_NAME = "webspeak3-sounds";
|
||||||
const STORE_NAME = "custom";
|
const STORE_NAME = "custom";
|
||||||
|
|
||||||
@@ -66,6 +67,15 @@ export function saveSoundsEnabled(enabled: boolean): void {
|
|||||||
localStorage.setItem(ENABLED_KEY, String(enabled));
|
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 {
|
export function loadSoundsVolume(): number {
|
||||||
const raw = localStorage.getItem(VOLUME_KEY);
|
const raw = localStorage.getItem(VOLUME_KEY);
|
||||||
const n = raw ? Number(raw) : 0.5;
|
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> {
|
export async function playSound(event: SoundEventId): Promise<void> {
|
||||||
if (!loadSoundsEnabled()) return;
|
if (!loadSoundsEnabled()) return;
|
||||||
|
if (!loadEventSoundEnabled(event)) return;
|
||||||
const volume = loadSoundsVolume();
|
const volume = loadSoundsVolume();
|
||||||
const custom = await loadCustomSound(event).catch(() => undefined);
|
const custom = await loadCustomSound(event).catch(() => undefined);
|
||||||
if (custom) {
|
if (custom) {
|
||||||
|
|||||||
Reference in new issue
Block a user