-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.html
More file actions
87 lines (76 loc) · 2.86 KB
/
Copy pathindex.html
File metadata and controls
87 lines (76 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>kuview</title>
</head>
<body>
<script>
window.kuviewEventQueue = [];
// Temporary event handler to queue events before React is fully ready
// It will be replaced by the React event handler when React is fully ready
window.kuview = (event) => {
console.log("[Main] Queuing event via temp window.kuview:", event);
window.kuviewEventQueue.push(event);
};
const errorDiv = document.getElementById("error");
fetch("/kuview/available").
then((res) => {
console.log("[Main] Checking if KuView is available:", res);
if (res.status !== 200) {
throw new Error("KuView is not running");
}
}).then(() => {
console.log("[Main] Running in Server Mode");
const source = new EventSource("/kuview");
source.onmessage = (e) => {
const event = JSON.parse(e.data);
window.kuview(event);
};
source.onerror = (e) => {
console.error("[Main] Error from /kuview:", e);
errorDiv.innerHTML =
'<p style="color: red; font-family: sans-serif; padding: 20px;">' +
"Error from /kuview: " +
e.message +
"<br/>Please check the console for more details.</p>";
};
}).catch(() => {
console.log("[Main] Running in WASM Mode");
console.log("[Main] Initializing Web Worker for KuView WASM.");
const worker = new Worker("/static/worker.js");
worker.onmessage = (e) => {
if (e.data && e.data.type === "WORKER_ERROR") {
console.error("[Main] Received error from worker:", e.data.error);
errorDiv.innerHTML =
'<p style="color: red; font-family: sans-serif; padding: 20px;">' +
"Error initializing WebAssembly worker: " +
e.data.error +
"<br/>Please check the console for more details.</p>";
return;
}
for (const event of e.data) {
window.kuview(event);
}
};
worker.onerror = (error) => {
console.error("[Main] Error from worker:", JSON.stringify(error));
errorDiv.innerHTML =
'<p style="color: red; font-family: sans-serif; padding: 20px;">' +
"Critical error with WebAssembly worker: " +
error.message +
"<br/>Please check the console for more details and refresh the page.</p>";
};
worker.postMessage({
type: "INIT_WORKER",
host: `${location.protocol}//${location.host}`,
});
})
</script>
<div id="error"></div>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>