Take account of new settings

This commit is contained in:
Pierre HUBERT 2021-04-11 14:02:17 +02:00
parent 4d05913819
commit b5a942bf0c
2 changed files with 27 additions and 4 deletions

View File

@ -8,23 +8,43 @@ const NotificationsSong = {
/**
* Song element : null by default
*
* @type {HTMLAudioElement}
*/
songElem: null,
/**
* Check whether notifications song is enabled or not
*/
enableSong: false,
/**
* Play notification song once
*/
play: function(){
if (!NotificationsSong.enableSong)
return;
//Create song element if required
if(this.songElem == null){
this.songElem = new SongPlayer([
if(NotificationsSong.songElem == null){
NotificationsSong.songElem = new SongPlayer([
ComunicWeb.__config.assetsURL + "audio/notif_song.mp3",
ComunicWeb.__config.assetsURL + "audio/notif_song.ogg"
]);
}
//Play song
this.songElem.playOnce();
NotificationsSong.songElem.playOnce();
}
}
// Get notification settings as soon as the page is loaded
document.addEventListener("wsOpen", async () => {
try {
const settings = await SettingsInterface.getNotifications();
NotificationsSong.enableSong = settings.allow_notifications_sound;
} catch(e) {
console.error(e);
}
})

View File

@ -36,6 +36,9 @@ class NotificationsSettings {
await SettingsInterface.setNotifications(newSettings);
// Apply new settings immediatly
NotificationsSong.enableSong = newSettings.allow_notifications_sound;
notify(tr("Successfully updated settings!"), "success")
} catch(e) {