-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
97 lines (81 loc) · 3.04 KB
/
index.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="My site, made with PWA Easy">
<meta name="theme-color" content="#ffffff">
<title>My site!</title>
<style id="styles-temporary">
html {
background: #f0f0f0;
}
body {
margin: 0;
}
body * {
display: none;
}
#app-loading {
display: initial;
background: url("img/loading.svg") no-repeat center center;
margin: auto;
width: 50vh;
height: 50vh;
}
#app-dom {
width: 100%;
height: 100vh;
display: flex;
}
noscript {
display: initial;
}
</style>
<script src="./utils/global.js"></script>
</head>
<body>
<noscript>
Please enable JavaScript to access this site.
</noscript>
<div id="app-dom" style="display: none">
<div id="app-loading"></div>
</div>
<script type="text/x-template" id="app-template"></script>
<script type="module">
document.getElementById('app-dom').removeAttribute('style');
import './config/globals.js';
import {StartupUtils} from "./utils/startup.js";
StartupUtils.addHeaders();
utils.polyfillSafari();
(async () => {
const startApp = async () => {
let {default: ControllerIndex} = await import('./controllers/index.js');
await ControllerIndex.initialize();
};
if ('serviceWorker' in window.navigator) {
const Workbox = config.isLocalhost
? (await import('./external/js/global/workbox/workbox-window.dev.mjs')).Workbox
: (await import('./external/js/global/workbox/workbox-window.prod.mjs')).Workbox;
const wb = new Workbox(`${config.rootURL.pathname}service-worker.js`, {updateViaCache: 'none'});
wb.addEventListener('installed', event => { if (event.isUpdate) app?.showUpdateSnackbar(); });
wb.addEventListener('externalactivated', () => { app?.showUpdateSnackbar(); });
await wb.register();
// Workaround for the lack of a consistent 'activated' event. The app requires the ServiceWorker when there
// is no internet access. The ServiceWorker also performs various URL rewrites to reduce the network usage.
// https://github.com/w3c/ServiceWorker/issues/1222
// https://github.com/w3c/ServiceWorker/issues/1247
const swr = await window.navigator.serviceWorker.ready;
if (swr.active.state === 'activated') await startApp();
else {
const activatedHandler = async () => {
wb.removeEventListener('activated', activatedHandler);
await startApp();
};
wb.addEventListener('activated', activatedHandler);
}
} else await startApp(); // fall back to online-only mode
})();
</script>
</body>
</html>