diff --git a/config/defaults.js b/config/defaults.js index b0c4ccc9..52efa495 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -49,6 +49,8 @@ const defaults = { default_party_pause_enabled: true, default_auto_host_enabled: false, + default_are_notification_enabled: false, + default_are_sound_notification_enabled: false, force_slplayer: false, diff --git a/src/store/modules/synclounge/actions.js b/src/store/modules/synclounge/actions.js index 3256138f..d35ff91d 100644 --- a/src/store/modules/synclounge/actions.js +++ b/src/store/modules/synclounge/actions.js @@ -420,6 +420,13 @@ export default { } if (getters.ARE_NOTIFICATIONS_ENABLED) { + if (Notification.permission !== 'granted') { + const permission = await Notification.requestPermission(); + if (permission !== 'granted') { + return; + } + } + const { username, thumb } = getters.GET_MESSAGES_USER_CACHE_USER(msg.senderId); // TODO: notifications don't work when on http. Maybe make alternative popup thing? diff --git a/src/store/modules/synclounge/getters.js b/src/store/modules/synclounge/getters.js index e28afb86..b22ff28e 100644 --- a/src/store/modules/synclounge/getters.js +++ b/src/store/modules/synclounge/getters.js @@ -84,7 +84,11 @@ export default { GET_UP_NEXT_TRIGGERED: (state) => state.upNextTriggered, - ARE_NOTIFICATIONS_ENABLED: (state) => state.areNotificationsEnabled, + ARE_NOTIFICATIONS_ENABLED: (state, getters, rootState, rootGetters) => state + .areNotificationsEnabled + ?? rootGetters.GET_CONFIG?.default_are_notification_enabled, - ARE_SOUND_NOTIFICATIONS_ENABLED: (state) => state.areSoundNotificationsEnabled, + ARE_SOUND_NOTIFICATIONS_ENABLED: (state, getters, rootState, rootGetters) => state + .areSoundNotificationsEnabled + ?? rootGetters.GET_CONFIG?.default_are_sound_notification_enabled, }; diff --git a/src/store/modules/synclounge/state.js b/src/store/modules/synclounge/state.js index 1615d814..8534c778 100644 --- a/src/store/modules/synclounge/state.js +++ b/src/store/modules/synclounge/state.js @@ -18,8 +18,8 @@ const state = () => ({ // This tracks whether the upnext screen was triggered for this playback already. // It is reset to false when the player gets out of the upNext time zone (at the end of episode) upNextTriggered: false, - areNotificationsEnabled: false, - areSoundNotificationsEnabled: false, + areNotificationsEnabled: null, + areSoundNotificationsEnabled: null, }); export default state;