fix: add WASM init error handling to index page

This commit is contained in:
Accusys
2026-05-18 10:14:44 +08:00
parent 97e29dc2cf
commit 10f0538b0b

View File

@@ -85,33 +85,39 @@ async function checkAuth() {
} }
async function initApp() { async function initApp() {
await init(); const el = document.getElementById('content');
try {
await init();
el.innerHTML = '<p>WASM initialized. Loading modules...</p>';
// Parse module list // Parse module list
modules = JSON.parse(module_list()); modules = JSON.parse(module_list());
const listEl = document.getElementById('module-list'); const listEl = document.getElementById('module-list');
modules.forEach(([name, cn, en]) => { modules.forEach(([name, cn, en]) => {
const a = document.createElement('a'); const a = document.createElement('a');
a.className = 'module-link'; a.className = 'module-link';
a.dataset.module = name; a.dataset.module = name;
a.textContent = `${cn} - ${en}`; a.textContent = `${cn} - ${en}`;
a.onclick = (e) => { e.preventDefault(); loadDoc(name); }; a.onclick = (e) => { e.preventDefault(); loadDoc(name); };
listEl.appendChild(a); listEl.appendChild(a);
}); });
// Logout // Logout
document.getElementById('logout-btn').onclick = async (e) => { document.getElementById('logout-btn').onclick = async (e) => {
e.preventDefault(); e.preventDefault();
await fetch(`${API}/api/v1/auth/logout`, {method:'POST'}); await fetch(`${API}/api/v1/auth/logout`, {method:'POST'});
window.location.reload(); window.location.reload();
}; };
// Load initial module from hash or default // Load initial module from hash or default
const hash = location.hash.slice(1); const hash = location.hash.slice(1);
if (hash) { if (hash) {
loadDoc(hash); loadDoc(hash);
} else { } else {
loadDoc('01_auth'); loadDoc('01_auth');
}
} catch(e) {
el.innerHTML = `<p style="color:red">WASM init error: ${e.message}</p><pre>${e.stack}</pre>`;
} }
} }
@@ -121,6 +127,7 @@ window.onpopstate = () => {
if (hash) loadDoc(hash); if (hash) loadDoc(hash);
}; };
document.getElementById('content').innerHTML = '<p>Starting WASM...</p>';
initApp(); initApp();
</script> </script>
</body> </body>