fix(PWA): avoid repeated notification of SW update
This commit is contained in:
parent
ac1731d123
commit
20caace68a
1 changed files with 7 additions and 5 deletions
|
@ -18,13 +18,10 @@ if ('serviceWorker' in navigator) {
|
||||||
.then(registration => {
|
.then(registration => {
|
||||||
if (registration) {
|
if (registration) {
|
||||||
registration.addEventListener('updatefound', () => {
|
registration.addEventListener('updatefound', () => {
|
||||||
/* console.log('updatefound'); */
|
|
||||||
let serviceWorker = registration.installing;
|
let serviceWorker = registration.installing;
|
||||||
|
|
||||||
serviceWorker.addEventListener('statechange', () => {
|
serviceWorker.addEventListener('statechange', () => {
|
||||||
/* console.log(`statechange -> ${serviceWorker.state}`); */
|
|
||||||
if (serviceWorker.state === 'installed') {
|
if (serviceWorker.state === 'installed') {
|
||||||
/* console.log('installed'); */
|
|
||||||
if (navigator.serviceWorker.controller) {
|
if (navigator.serviceWorker.controller) {
|
||||||
$notification.toast('show');
|
$notification.toast('show');
|
||||||
/* in case the user ignores the notification */
|
/* in case the user ignores the notification */
|
||||||
|
@ -39,9 +36,14 @@ if ('serviceWorker' in navigator) {
|
||||||
$notification.toast('hide');
|
$notification.toast('hide');
|
||||||
});
|
});
|
||||||
|
|
||||||
/* there's a new Service Worker waiting to be activated */
|
|
||||||
if (localStorage.getItem(keyWaiting)) {
|
if (localStorage.getItem(keyWaiting)) {
|
||||||
|
if (registration.waiting) {
|
||||||
|
/* there's a new Service Worker waiting to be activated */
|
||||||
$notification.toast('show');
|
$notification.toast('show');
|
||||||
|
} else {
|
||||||
|
/* closed all open pages after receiving notification */
|
||||||
|
localStorage.removeItem(keyWaiting);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue