diff --git a/client/client.js b/client/client.js index f0ef8ed9..6f5e2c0b 100644 --- a/client/client.js +++ b/client/client.js @@ -612,7 +612,7 @@ function CloudCmdProto(Util, DOM) { }); }; - function serviceWorker() { + async function serviceWorker() { if (!navigator.serviceWorker) return; @@ -622,7 +622,20 @@ function CloudCmdProto(Util, DOM) { if (!isHTTPS && !isLocalhost) return; - runtime.register(); + const req = await runtime.register(); + + req.onupdatefound = () => { + const installingWorker = req.installing; + installingWorker.onstatechange = () => { + if (installingWorker.state !== 'installed' || !navigator.serviceWorker.controller) + return; + + const reload = location.reload.bind(location); + DOM.Dialog.confirm(TITLE, 'Update available. Do you want to realod page?', { + cancel: true + }).then(reload); + }; + }; } }