Last active
January 18, 2018 22:34
-
-
Save attilavago/10ed2ce6d1eb6979dd402f02015df837 to your computer and use it in GitHub Desktop.
partial app.js for R.O.A.S.
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
if('serviceWorker' in navigator){ | |
navigator.serviceWorker | |
.register('./service-worker.js') | |
.then(function(){ | |
window.isUpdateAvailable = new Promise(function (resolve, reject) { | |
if ('serviceWorker' in navigator && ['localhost', '127'].indexOf(location.hostname) === -1) { | |
navigator.serviceWorker.register('service-worker.js').then(function (reg) { | |
reg.onupdatefound = function () { | |
var installingWorker = reg.installing; | |
installingWorker.onstatechange = function () { | |
switch (installingWorker.state) { | |
case 'installed': | |
if (navigator.serviceWorker) { | |
resolve(true); | |
alert('There is an update available for this app, please reload.'); | |
} else { | |
// no update available | |
resolve(false); | |
} | |
break; | |
} | |
}; | |
}; | |
}).catch(function (err) { | |
return console.error('[SW ERROR]', err); | |
}); | |
} | |
}); | |
console.log('loaded service worker'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment