-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
026fed3
commit 6af6387
Showing
1 changed file
with
50 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,65 @@ | ||
import { register } from 'register-service-worker'; | ||
import { register } from "register-service-worker"; | ||
|
||
// The ready(), registered(), cached(), updatefound() and updated() | ||
// events passes a ServiceWorkerRegistration instance in their arguments. | ||
// ServiceWorkerRegistration: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration | ||
|
||
register(process.env.SERVICE_WORKER_FILE, { | ||
// The registrationOptions object will be passed as the second argument | ||
// to ServiceWorkerContainer.register() | ||
// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#Parameter | ||
// The registrationOptions object will be passed as the second argument | ||
// to ServiceWorkerContainer.register() | ||
// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#Parameter | ||
|
||
// registrationOptions: { scope: './' }, | ||
// registrationOptions: { scope: './' }, | ||
|
||
ready (/* registration */) { | ||
// console.log('Service worker is active.') | ||
}, | ||
ready(/* registration */) { | ||
// console.log('Service worker is active.') | ||
}, | ||
|
||
registered (/* registration */) { | ||
// console.log('Service worker has been registered.') | ||
}, | ||
registered(/* registration */) { | ||
// console.log('Service worker has been registered.') | ||
}, | ||
|
||
cached (/* registration */) { | ||
// console.log('Content has been cached for offline use.') | ||
}, | ||
cached(/* registration */) { | ||
// console.log('Content has been cached for offline use.') | ||
}, | ||
|
||
updatefound (registration) { | ||
try { | ||
registration.update() | ||
} catch (err) { | ||
console.err('SW update failed:', err) | ||
} | ||
} | ||
updatefound(registration) { | ||
try { | ||
registration.update(); | ||
} catch (err) { | ||
console.err("SW update failed:", err); | ||
} | ||
}, | ||
|
||
updated(registration) { | ||
// Cleares old cash so new content is downloaded | ||
caches.keys().then(function (names) { | ||
for (let name of names) { | ||
console.log("SW Updated. Delete cache", name); | ||
caches.delete(name); | ||
} | ||
}); | ||
|
||
updated (registration) { | ||
// Cleares old cash so new content is downloaded | ||
caches.keys().then(function(names) { | ||
for (let name of names) { | ||
console.log("SW Updated. Delete cache", name) | ||
caches.delete(name); | ||
} | ||
}); | ||
// Nofitify the user and let them download the new content | ||
// Notify.create({ | ||
// message: "New content available.", | ||
// type: "info", | ||
// icon: "fas fa-arrow-alt-to-bottom", | ||
// color: "neutral-7", | ||
// iconSize: "15px", | ||
// position: "top", | ||
// timeout: 0, | ||
// actions: [ | ||
// { label: 'Fetch', color: 'white', noCaps: true, size: "md", handler: () => { registration.waiting.postMessage({ type: "SKIP_WAITING" }); } }, | ||
// ] | ||
// }); | ||
}, | ||
|
||
// Nofitify the user and let them download the new content | ||
// Notify.create({ | ||
// message: "New content available.", | ||
// type: "info", | ||
// icon: "fas fa-arrow-alt-to-bottom", | ||
// color: "neutral-7", | ||
// iconSize: "15px", | ||
// position: "top", | ||
// timeout: 0, | ||
// actions: [ | ||
// { label: 'Fetch', color: 'white', noCaps: true, size: "md", handler: () => { registration.waiting.postMessage({ type: "SKIP_WAITING" }); } }, | ||
// ] | ||
// }); | ||
}, | ||
offline() { | ||
// console.log('No internet connection found. App is running in offline mode.') | ||
}, | ||
|
||
offline () { | ||
// console.log('No internet connection found. App is running in offline mode.') | ||
}, | ||
|
||
error (/* err */) { | ||
// console.error('Error during service worker registration:', err) | ||
} | ||
}); | ||
error(/* err */) { | ||
// console.error('Error during service worker registration:', err) | ||
}, | ||
}); |