Mark all notifications as seen syncs all tabs

This commit is contained in:
2018-03-20 18:27:57 +01:00
parent d6efc2b861
commit 24b0036617
3 changed files with 61 additions and 40 deletions

View File

@ -30,7 +30,16 @@ export async function markNotificationsAsSeen(arn: AnimeNotifier) {
})
// Update notification counter
arn.notificationManager.update()
if(!("serviceWorker" in navigator)) {
// If there is no service worker, update the counter on this tab
arn.notificationManager.update()
} else {
// If we have service worker support, broadcast the "notifications marked as seen" message to all open tabs
arn.serviceWorkerManager.postMessage({
type: "broadcast",
realType: "notifications marked as seen"
})
}
// Update notifications
arn.reloadContent()

View File

@ -11,12 +11,10 @@ export class ServiceWorkerManager {
register() {
if(!("serviceWorker" in navigator)) {
console.log("service worker not supported, skipping registration")
console.warn("service worker not supported, skipping registration")
return
}
console.log("register service worker")
navigator.serviceWorker.register(this.uri).then(registration => {
// registration.update()
})
@ -74,6 +72,7 @@ export class ServiceWorkerManager {
switch(message.type) {
case "new notification":
case "notifications marked as seen":
this.arn.notificationManager.update()
break