Skip to content

Commit a001089

Browse files
committed
add install progress bar
1 parent c64337f commit a001089

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

web/boot/index.html

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@
1818
font-family: sans-serif;
1919
font-weight: bold;
2020
}
21+
#progress {
22+
margin-top: 20px;
23+
width: 300px;
24+
height: 20px;
25+
border: 1px solid black;
26+
border-radius: 10px;
27+
background-color: white;
28+
overflow: hidden;
29+
}
30+
#bar {
31+
background-color: #555;
32+
height: 20px;
33+
width: 0%;
34+
}
2135
</style>
2236
<script type="module">
2337
import { version } from '/lib/moto/license.js';
@@ -49,10 +63,19 @@
4963
version: map.version || version
5064
});
5165

66+
const bar = document.getElementById('bar');
67+
5268
navigator.serviceWorker.addEventListener('message', e => {
53-
console.log('[SM]', e.data);
54-
setTimeout(() => {
55-
if (map.mesh) {
69+
let { data } = e;
70+
if (data.progress) {
71+
bar.style.width = `${(data.progress * 100)|0}%`;
72+
return;
73+
} else {
74+
console.log('[SM]', data);
75+
}
76+
setTimeout(() => {
77+
bar.style.width = `100%`;
78+
if (map.mesh) {
5679
location.replace('/mesh/index.html');
5780
} else {
5881
location.replace('/kiri/index.html');
@@ -63,6 +86,11 @@
6386
</script>
6487
</head>
6588

66-
<body>Booting Grid.Space</body>
89+
<body>
90+
<div>Installing Grid.Space</div>
91+
<div id="progress">
92+
<div id="bar"></div>
93+
</div>
94+
</body>
6795

6896
</html>

web/boot/service.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ async function preloadBundle() {
193193
const res = await fetch(BUNDLE_URL, { cache: 'no-store' });
194194
const buf = await res.arrayBuffer();
195195
const files = await unpackBundle(buf);
196+
const total = Object.keys(files).length;
196197
await Promise.all(
197198
Object.entries(files).map(([path, blob]) => {
199+
broadcast({ progress: loaded/total });
198200
const ext = path.split('.').pop();
199201
const type =
200202
ext === 'html' ? 'text/html' :

0 commit comments

Comments
 (0)