pinafore/routes/_store/observers/notificationObservers.js

20 lines
593 B
JavaScript
Raw Normal View History

2018-03-03 23:15:50 +01:00
import { setFavicon } from '../../_utils/setFavicon'
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
2018-02-16 17:59:44 +01:00
2018-02-21 06:29:59 +01:00
let currentFaviconHasNotifications = false
2018-02-16 17:59:44 +01:00
export function notificationObservers (store) {
store.observe('hasNotifications', hasNotifications => {
if (!process.browser) {
return
}
scheduleIdleTask(() => {
2018-04-19 18:34:56 +02:00
if (currentFaviconHasNotifications === hasNotifications) {
return
}
2018-02-21 06:29:59 +01:00
setFavicon(hasNotifications ? '/favicon-alert.png' : '/favicon.png')
currentFaviconHasNotifications = !currentFaviconHasNotifications
2018-02-16 17:59:44 +01:00
})
})
2018-02-16 18:01:03 +01:00
}