Notifications: Fix multiple sounds when waking up from background mode (#2085)
This commit is contained in:
parent
f5d70de000
commit
4dbd91c026
@ -96,18 +96,17 @@ const expirationTime = 12 * 60 * 60 * 1000; // 12 hours
|
|||||||
// Notification id is removed from soundPlayed cache after 3 seconds
|
// Notification id is removed from soundPlayed cache after 3 seconds
|
||||||
const soundPlayedDelay = 3 * 1000;
|
const soundPlayedDelay = 3 * 1000;
|
||||||
const soundPlayedIds = new Set<string>();
|
const soundPlayedIds = new Set<string>();
|
||||||
|
const notificationSound = new Audio('./notification.mp3');
|
||||||
|
notificationSound.setAttribute('mozaudiochannel', 'notification');
|
||||||
|
|
||||||
export async function playNotifySound(id?: string, volume?: number) {
|
export async function playNotifySound(id?: string, volume?: number) {
|
||||||
if (id !== undefined && soundPlayedIds.has(id)) return;
|
if (id !== undefined && soundPlayedIds.has(id)) return;
|
||||||
const { notificationSoundVolume } = selectNotifySettings(getGlobal());
|
const { notificationSoundVolume } = selectNotifySettings(getGlobal());
|
||||||
const currentVolume = volume ? volume / 10 : notificationSoundVolume / 10;
|
const currentVolume = volume ? volume / 10 : notificationSoundVolume / 10;
|
||||||
if (currentVolume === 0) return;
|
if (currentVolume === 0) return;
|
||||||
|
notificationSound.volume = currentVolume;
|
||||||
const audio = new Audio('./notification.mp3');
|
|
||||||
audio.volume = currentVolume;
|
|
||||||
audio.setAttribute('mozaudiochannel', 'notification');
|
|
||||||
if (id !== undefined) {
|
if (id !== undefined) {
|
||||||
audio.addEventListener('ended', () => {
|
notificationSound.addEventListener('ended', () => {
|
||||||
soundPlayedIds.add(id);
|
soundPlayedIds.add(id);
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
|
|
||||||
@ -117,7 +116,7 @@ export async function playNotifySound(id?: string, volume?: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await audio.play();
|
await notificationSound.play();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user