-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (32 loc) · 1.05 KB
/
index.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
37
38
39
import { landing } from './landing.js';
import { options } from './options.js';
export function launchApp() {
if (!localStorage.getItem('user')) {
return options();
} else {
landing();
}
}
function registerServiceWorker() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
.then(registration => {
console.log('Service Worker registered with scope:', registration.scope);
})
.catch(error => {
console.error('Service Worker registration failed:', error);
});
} else {
console.log('Service Workers not supported in this browser.');
}
}
// Listen for an updatefound event
navigator.serviceWorker.addEventListener('controllerchange', () => {
if (confirm('A new version of the app is available. Would you like to update now?')) {
window.location.reload();
}
});
document.addEventListener('DOMContentLoaded', () => {
registerServiceWorker();
launchApp();
});