mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
feature(client) serviceWorker: add ability to reload page on cache update
This commit is contained in:
parent
2fc08a1c6c
commit
8e9f16f884
1 changed files with 15 additions and 2 deletions
|
|
@ -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);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue