Commit 1a56db90 authored by Michał "rysiek" Woźniak's avatar Michał "rysiek" Woźniak
Browse files

Merge branch 'serviceworker-enabled' into 'master'

check if system supports service workers before we do anything else

See merge request libre/samizdat!10
parents 82ed7bca ebbc40c3
......@@ -46,10 +46,11 @@ let listLocalResources = () => {
|* === Service worker setup === *|
\* ========================================================================= */
if (navigator.serviceWorker.controller) {
if ('serviceWorker' in navigator) {
if (navigator.serviceWorker.controller) {
// Service worker already registered.
console.log('(COMMIT_UNKNOWN) Service Worker already registered.')
} else {
} else {
var scriptPath = document.currentScript.src
var scriptFolder = scriptPath.substr(0, scriptPath.lastIndexOf( '/' )+1 )
var serviceWorkerPath = scriptFolder + 'service-worker.js'
......@@ -60,14 +61,15 @@ if (navigator.serviceWorker.controller) {
var siStore = new idbKeyval.Store('samizdat', 'info')
idbKeyval.clear(siStore)
// once the SamizdatInfo stuff is cleared... we can set-up the service worker
.then((ret)=>{
.then((ret)=>{
navigator.serviceWorker.register(serviceWorkerPath, {
scope: './'
scope: './'
}).then(function(reg) {
// Success.
console.log('(COMMIT_UNKNOWN) Service Worker registered.')
// Success.
console.log('(COMMIT_UNKNOWN) Service Worker registered.')
}).catch(error => {
console.log("(COMMIT_UNKNOWN) Error while registering a service worker: ", error)
console.log("(COMMIT_UNKNOWN) Error while registering a service worker: ", error)
})
})
})
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment