Skip to content

Commit d60d982

Browse files
committed
ecere/gui/drivers/Emscripten: Setting title based on app name
- extras/utils: Including wasm-shell.html to be included in Global Settings / Compilers / WASM / Options / Additional linker flags as: [$(CF_WASM_LINK_FLAGS)] [$(CF_WASM_MORE_LINK_FLAGS)] [--shell-file] [$(ECERE_SDK_SRC)/extras/utils/wasm-shell.html]
1 parent 440ae52 commit d60d982

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

ecere/src/gui/drivers/EmscriptenInterface.ec

+3
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,9 @@ class EmscriptenInterface : Interface
816816
printf("BBB EmscriptenInterface::Initialize -- is it working?\n");
817817
emscripten_run_script("statusElement.innerHTML = 'this is a test'; statusElement.hidden = false;");
818818
#endif
819+
820+
if(guiApp.desktop)
821+
emscripten_set_window_title(guiApp.desktop.caption);
819822
return true;
820823
}
821824

extras/utils/wasm-shell.html

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<!doctype html>
2+
<html lang="en-us">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<title>WebAssembly Application</title>
7+
<style>
8+
html { height:100%; }
9+
body {
10+
font-family: arial;
11+
margin: 0;
12+
background: gray;
13+
padding: none;
14+
height: 100%;
15+
}
16+
17+
.emscripten { padding-right: 0; padding-bottom: 0; margin-bottom: 0; margin-left: auto; margin-right: auto; display: block; }
18+
/* div.emscripten { text-align: center; } */
19+
div.emscripten_border { border: 0px none; width: 100%; height: 100%; }
20+
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
21+
canvas.emscripten { border: 0px none; padding: 0px; background-color: black; width: 100%; height: 100%; }
22+
23+
div.status { position: absolute; left: 32px; top: 132px; padding: 4px; color: white; font-weight: bold; }
24+
div.progress { position: absolute; left: 32px; top: 148px; padding: 4px; border: 2px; width: 100%; background-color: yellow }
25+
</style>
26+
</head>
27+
<body>
28+
29+
<!--
30+
<div class="spinner" id="spinner" hidden=1></div>
31+
-->
32+
33+
<div class="status" id="status"></div>
34+
<div class="progress" hidden=1>
35+
<progress value="0" max="100" id="progress"></progress>
36+
</div>
37+
38+
<div class="emscripten_border">
39+
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
40+
</div>
41+
42+
<script type='text/javascript'>
43+
var statusElement = document.getElementById('status');
44+
var progressElement = document.getElementById('progress');
45+
// var spinnerElement = document.getElementById('spinner');
46+
47+
var Module = {
48+
preRun: [],
49+
postRun: [],
50+
print: (function() {
51+
var element = document.getElementById('output');
52+
if (element) element.value = ''; // clear browser cache
53+
return function(text) {
54+
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
55+
// These replacements are necessary if you render to raw HTML
56+
//text = text.replace(/&/g, "&amp;");
57+
//text = text.replace(/</g, "&lt;");
58+
//text = text.replace(/>/g, "&gt;");
59+
//text = text.replace('\n', '<br>', 'g');
60+
console.log(text);
61+
if (element) {
62+
element.value += text + "\n";
63+
element.scrollTop = element.scrollHeight; // focus on bottom
64+
}
65+
};
66+
})(),
67+
printErr: function(text) {
68+
text = Array.prototype.slice.call(arguments).join(' ');
69+
if (0) { // XXX disabled for safety typeof dump == 'function') {
70+
dump(text + '\n'); // fast, straight to the real console
71+
} else {
72+
console.error(text);
73+
}
74+
},
75+
canvas: (function() {
76+
var canvas = document.getElementById('canvas');
77+
78+
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
79+
// application robust, you may want to override this behavior before shipping!
80+
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
81+
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
82+
83+
return canvas;
84+
})(),
85+
setStatus: function(text) {
86+
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
87+
if (text === Module.setStatus.last.text) return;
88+
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
89+
var now = Date.now();
90+
if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon
91+
Module.setStatus.last.time = now;
92+
Module.setStatus.last.text = text;
93+
// console.log(Module.setStatus.last.time + " " + text);
94+
if (m) {
95+
text = m[1];
96+
progressElement.value = parseInt(m[2])*100;
97+
progressElement.max = parseInt(m[4])*100;
98+
progressElement.hidden = false;
99+
// spinnerElement.hidden = false;
100+
} else {
101+
progressElement.value = null;
102+
progressElement.max = null;
103+
progressElement.hidden = true;
104+
// if (!text) spinnerElement.hidden = true;
105+
if (!text) statusElement.hidden = true;
106+
}
107+
statusElement.innerHTML = text;
108+
},
109+
totalDependencies: 0,
110+
monitorRunDependencies: function(left) {
111+
this.totalDependencies = Math.max(this.totalDependencies, left);
112+
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
113+
}
114+
};
115+
Module.setStatus('Downloading...');
116+
window.onerror = function() {
117+
Module.setStatus('Exception thrown, see JavaScript console');
118+
spinnerElement.style.display = 'none';
119+
Module.setStatus = function(text) {
120+
if (text) Module.printErr('[post-exception status] ' + text);
121+
};
122+
};
123+
</script>
124+
125+
{{{ SCRIPT }}}
126+
127+
</body>
128+
</html>

0 commit comments

Comments
 (0)