2018-04-17 18:38:48 -05:00
|
|
|
|
|
|
|
function trackInstall(worker, cb) {
|
2018-07-15 17:02:19 -05:00
|
|
|
// worker.addEventListener('statechange', function() {
|
|
|
|
// //If the worker is now installed, let the user know that there is an update ready
|
|
|
|
// if (worker.state == 'installed') {
|
|
|
|
// cb();
|
|
|
|
// }
|
|
|
|
// });
|
2018-04-17 18:38:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function swUpdate() {
|
2018-07-15 17:02:19 -05:00
|
|
|
// navigator.serviceWorker.getRegistration().then(reg => {
|
|
|
|
// if (reg && reg.waiting) {
|
|
|
|
// reg.waiting.postMessage("skipWaiting");
|
|
|
|
// window.location.reload(true);
|
|
|
|
// }
|
|
|
|
// });
|
2018-04-17 18:38:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function swInit(store) {
|
|
|
|
|
|
|
|
if ('serviceWorker' in navigator) {
|
2018-07-15 17:02:19 -05:00
|
|
|
window.addEventListener('load', () => {
|
|
|
|
navigator.serviceWorker.register('/packs/sw.js').then(registration => {
|
|
|
|
console.log('SW registered: ', registration);
|
|
|
|
}).catch(registrationError => {
|
|
|
|
console.log('SW registration failed: ', registrationError);
|
2018-04-17 18:38:48 -05:00
|
|
|
});
|
2018-07-15 17:02:19 -05:00
|
|
|
});
|
2018-04-17 18:38:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-15 17:02:19 -05:00
|
|
|
// const updateReady = () => store.commit("setUpdateAvailable", true);
|
|
|
|
//
|
|
|
|
// if ('serviceWorker' in navigator) {
|
|
|
|
// navigator.serviceWorker.register('/sw.js')
|
|
|
|
// .then(function (reg) {
|
|
|
|
// console.log('Registration succeeded. Scope is ' + reg.scope);
|
|
|
|
//
|
|
|
|
// if (reg.waiting) {
|
|
|
|
// updateReady();
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // If there's an updated worker installing, track its progress. If it becomes "installed", call
|
|
|
|
// // indexController._updateReady()
|
|
|
|
// if (reg.installing) {
|
|
|
|
// trackInstall(reg.installing, updateReady);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// reg.addEventListener('updatefound', function () {
|
|
|
|
// trackInstall(reg.installing, updateReady);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// }).catch(function (error) {
|
|
|
|
// console.log('Registration failed with ' + error);
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
2018-04-17 18:38:48 -05:00
|
|
|
}
|