fix: initOnEvents not removed [CW-3594] (#10200)

The `initOnEvents` was used to get the notification sound file and
trigger the 30 second loop, but since the function was replaced to using
class syntax, the removeEvent listener was not working. This PR fixes it
by reverting to the old syntax but moving it inside the constructor
instead and also adding a `once: true` to ensure it is always removed
automatically
This commit is contained in:
Shivam Mishra
2024-10-03 15:03:44 +05:30
committed by GitHub
parent 578dce81a1
commit f14edd5242

View File

@@ -22,6 +22,21 @@ class DashboardAudioNotificationHelper {
this.currentUser = null;
this.currentUserId = null;
this.audioAlertTone = 'ding';
this.onAudioListenEvent = async () => {
try {
await getAlertAudio('', {
type: 'dashboard',
alertTone: this.audioAlertTone,
});
initOnEvents.forEach(event => {
document.removeEventListener(event, this.onAudioListenEvent, false);
});
this.playAudioEvery30Seconds();
} catch (error) {
// Ignore audio fetch errors
}
};
}
setInstanceValues({
@@ -38,26 +53,13 @@ class DashboardAudioNotificationHelper {
this.currentUserId = currentUser.id;
this.audioAlertTone = audioAlertTone;
initOnEvents.forEach(e => {
document.addEventListener(e, this.onAudioListenEvent, false);
document.addEventListener(e, this.onAudioListenEvent, {
once: true,
});
});
initFaviconSwitcher();
}
async onAudioListenEvent() {
try {
await getAlertAudio('', {
type: 'dashboard',
alertTone: this.audioAlertTone,
});
initOnEvents.forEach(event => {
document.removeEventListener(event, this.onAudioListenEvent, false);
});
this.playAudioEvery30Seconds();
} catch (error) {
// Ignore audio fetch errors
}
}
executeRecurringNotification() {
if (!window.WOOT_STORE) {
this.clearSetTimeout();