Skip to content

Commit 4bc32b9

Browse files
committed
Show loading percentage
1 parent 3c0d1df commit 4bc32b9

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/index.html

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Complex Plotter</title>
8-
<style>
8+
<style>
99
body, html {
1010
margin: 0;
1111
padding: 0;
@@ -27,7 +27,7 @@
2727
}
2828
#loading-overlay {
2929
position: absolute;
30-
width:100%;
30+
width: 100%;
3131
height: 100%;
3232
inset: 0;
3333
background-color: #1e1e1e;
@@ -56,12 +56,14 @@
5656

5757
<div id="loading-overlay">
5858
<div class="spinner"></div>
59-
<h2>Loading...</h2>
59+
<h2 id="progress-text">Loading...</h2>
6060
</div>
6161

6262
<canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex="-1"></canvas>
6363
<script type="text/javascript">
6464
const canvas = document.getElementById('canvas');
65+
const progressText = document.getElementById('progress-text');
66+
6567
canvas.addEventListener("webglcontextlost", (e) => {
6668
alert('Error with WebGL. Please reload the page');
6769
e.preventDefault();
@@ -77,11 +79,35 @@ <h2>Loading...</h2>
7779
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
7880
console.error(text);
7981
},
82+
83+
setStatus: function(text) {
84+
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
85+
if (text === Module.setStatus.last.text) return;
86+
87+
const m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
88+
if (m) {
89+
const loaded = parseInt(m[2]);
90+
const total = parseInt(m[4]);
91+
const progress = Math.round((loaded / total) * 100);
92+
progressText.innerText = `Loading... ${progress}%`;
93+
} else {
94+
if (text) progressText.innerText = text;
95+
}
96+
},
97+
98+
totalDependencies: 0,
99+
monitorRunDependencies: function(left) {
100+
this.totalDependencies = Math.max(this.totalDependencies, left);
101+
Module.setStatus(left ? `Preparing... (${this.totalDependencies - left}/${this.totalDependencies})` : 'All downloads complete.');
102+
},
103+
80104
onRuntimeInitialized: function() {
81105
document.getElementById('loading-overlay').style.display = 'none';
82106
canvas.focus();
83107
}
84-
};
108+
};
109+
110+
Module.setStatus('Downloading...');
85111
</script>
86112
<textarea id="clipping" style="position:absolute; width:0; height:0; border:0; opacity:0; pointer-events:none;" aria-hidden="true"></textarea>
87113

0 commit comments

Comments
 (0)