55 lines
No EOL
1.7 KiB
HTML
55 lines
No EOL
1.7 KiB
HTML
<!doctype html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>{[app_name]s}</title>
|
|
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
|
</head>
|
|
|
|
<body>
|
|
<script type="module">
|
|
import {{mach}} from "./mach.js";
|
|
import {{sysjs}} from "./mach-sysjs.js";
|
|
import setupWasmserve from "./wasmserve.js";
|
|
|
|
setupWasmserve();
|
|
|
|
let imports = {{
|
|
mach,
|
|
sysjs,
|
|
}};
|
|
|
|
fetch("{[wasm_path]s}")
|
|
.then(response => response.arrayBuffer())
|
|
.then(buffer => WebAssembly.instantiate(buffer, imports))
|
|
.then(results => results.instance)
|
|
.then(instance => {{
|
|
sysjs.init(instance);
|
|
mach.init(instance);
|
|
instance.exports.wasmInit();
|
|
|
|
let frame = true;
|
|
let last_update_time = performance.now();
|
|
let update = function () {{
|
|
if (!frame) {{
|
|
instance.exports.wasmDeinit();
|
|
return;
|
|
}}
|
|
if (mach.machHasEvent() ||
|
|
last_update_time + mach.wait_timeout * 1000 <= performance.now()) {{
|
|
if (instance.exports.wasmUpdate()) {{
|
|
instance.exports.wasmDeinit();
|
|
return;
|
|
}}
|
|
last_update_time = performance.now();
|
|
}}
|
|
window.requestAnimationFrame(update);
|
|
}};
|
|
window.requestAnimationFrame(update);
|
|
}})
|
|
.catch(err => console.error(err));
|
|
</script>
|
|
</body>
|
|
|
|
</html> |