-
Notifications
You must be signed in to change notification settings - Fork 73
/
service-worker-driver.js
36 lines (36 loc) · 1.37 KB
/
service-worker-driver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
window.isUpdateAvailable = new Promise(function(resolve, reject) {
if ('serviceWorker' in navigator && ['localhost', '127.0.0.1'].indexOf(location.hostname) === -1) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('service-worker.js').then((registration) => {
console.log('ServiceWorker registered with scope: ', registration.scope);
registration.onupdatefound = () => {
const installingWorker = registration.installing;
installingWorker.onstatechange = () => {
switch (installingWorker.state) {
case 'installed':
if (navigator.serviceWorker.controller) {
// new update available
return Promise.resolve(true);
} else {
// no update available
return Promise.resolve(false);
}
break;
}
};
};
}).catch(function(err) {
console.log('ServiceWorker registration failed: ', err);
});
});
}
});
window['isUpdateAvailable']
.then((isAvailable) => {
if (isAvailable) {
document.addEventListener('backend-ai-connected', (e) => {
document.querySelector('#webui-shell').showUpdateNotifier();
});
console.log('New Web UI is available. Please reload to update.');
}
});