add install progress bar
This commit is contained in:
parent
c64337f3c4
commit
a001089f0f
2 changed files with 34 additions and 4 deletions
|
|
@ -18,6 +18,20 @@
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
#progress {
|
||||||
|
margin-top: 20px;
|
||||||
|
width: 300px;
|
||||||
|
height: 20px;
|
||||||
|
border: 1px solid black;
|
||||||
|
border-radius: 10px;
|
||||||
|
background-color: white;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
#bar {
|
||||||
|
background-color: #555;
|
||||||
|
height: 20px;
|
||||||
|
width: 0%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { version } from '/lib/moto/license.js';
|
import { version } from '/lib/moto/license.js';
|
||||||
|
|
@ -49,10 +63,19 @@
|
||||||
version: map.version || version
|
version: map.version || version
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const bar = document.getElementById('bar');
|
||||||
|
|
||||||
navigator.serviceWorker.addEventListener('message', e => {
|
navigator.serviceWorker.addEventListener('message', e => {
|
||||||
console.log('[SM]', e.data);
|
let { data } = e;
|
||||||
setTimeout(() => {
|
if (data.progress) {
|
||||||
if (map.mesh) {
|
bar.style.width = `${(data.progress * 100)|0}%`;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
console.log('[SM]', data);
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
bar.style.width = `100%`;
|
||||||
|
if (map.mesh) {
|
||||||
location.replace('/mesh/index.html');
|
location.replace('/mesh/index.html');
|
||||||
} else {
|
} else {
|
||||||
location.replace('/kiri/index.html');
|
location.replace('/kiri/index.html');
|
||||||
|
|
@ -63,6 +86,11 @@
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>Booting Grid.Space</body>
|
<body>
|
||||||
|
<div>Installing Grid.Space</div>
|
||||||
|
<div id="progress">
|
||||||
|
<div id="bar"></div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -193,8 +193,10 @@ async function preloadBundle() {
|
||||||
const res = await fetch(BUNDLE_URL, { cache: 'no-store' });
|
const res = await fetch(BUNDLE_URL, { cache: 'no-store' });
|
||||||
const buf = await res.arrayBuffer();
|
const buf = await res.arrayBuffer();
|
||||||
const files = await unpackBundle(buf);
|
const files = await unpackBundle(buf);
|
||||||
|
const total = Object.keys(files).length;
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Object.entries(files).map(([path, blob]) => {
|
Object.entries(files).map(([path, blob]) => {
|
||||||
|
broadcast({ progress: loaded/total });
|
||||||
const ext = path.split('.').pop();
|
const ext = path.split('.').pop();
|
||||||
const type =
|
const type =
|
||||||
ext === 'html' ? 'text/html' :
|
ext === 'html' ? 'text/html' :
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue