23ccec45d0
Part of the way to improving #390. Before this fix, if you recieved a notification while Pinafore was in a background tab, nothing would happen, because most browsers (Edge, Firefox, Chrome) don't run rAF in background tabs. Furthermore, Chrome doesn't run rIC. In this PR we detect if we're in a background tab and then avoid rAF/rIC in that case.
20 lines
608 B
JavaScript
20 lines
608 B
JavaScript
import { setFavicon } from '../../_utils/setFavicon'
|
|
import { runMediumPriorityTask } from '../../_utils/runMediumPriorityTask'
|
|
|
|
let currentFaviconHasNotifications = false
|
|
|
|
export function notificationObservers (store) {
|
|
store.observe('hasNotifications', hasNotifications => {
|
|
if (!process.browser) {
|
|
return
|
|
}
|
|
runMediumPriorityTask(() => {
|
|
if (currentFaviconHasNotifications === hasNotifications) {
|
|
return
|
|
}
|
|
setFavicon(hasNotifications ? '/favicon-alert.png' : '/favicon.png')
|
|
currentFaviconHasNotifications = !currentFaviconHasNotifications
|
|
})
|
|
})
|
|
}
|