mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
deregister sw when update is ready to go to force activating on iOS
This commit is contained in:
parent
6b15e7e3ba
commit
3354d601d1
18
index.html
18
index.html
@ -31,19 +31,19 @@
|
|||||||
</script>
|
</script>
|
||||||
<script id="service-worker" type="module">
|
<script id="service-worker" type="module">
|
||||||
if('serviceWorker' in navigator) {
|
if('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('sw.js')
|
navigator.serviceWorker.register('sw.js').then(function(registration) {
|
||||||
.then(function(registration) {
|
|
||||||
console.log("Service Worker registered");
|
console.log("Service Worker registered");
|
||||||
|
function tryActivateUpdate() {
|
||||||
|
if (registration.waiting && registration.active) {
|
||||||
|
registration.unregister();
|
||||||
|
console.log("Service Worker unregistered");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tryActivateUpdate();
|
||||||
registration.onupdatefound = function() {
|
registration.onupdatefound = function() {
|
||||||
const newWorker = registration.installing;
|
const newWorker = registration.installing;
|
||||||
alert("update found!");
|
|
||||||
newWorker.onstatechange = function() {
|
newWorker.onstatechange = function() {
|
||||||
if (newWorker.state === "installed") {
|
tryActivateUpdate();
|
||||||
alert("new worker is now on state " + newWorker.state);
|
|
||||||
// if (confirm("update installed! shall I skip waiting?")) {
|
|
||||||
// newWorker.skipWaiting();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user