fix: add WASM init error handling to index page
This commit is contained in:
@@ -85,33 +85,39 @@ async function checkAuth() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function initApp() {
|
async function initApp() {
|
||||||
await init();
|
const el = document.getElementById('content');
|
||||||
|
try {
|
||||||
// Parse module list
|
await init();
|
||||||
modules = JSON.parse(module_list());
|
el.innerHTML = '<p>WASM initialized. Loading modules...</p>';
|
||||||
const listEl = document.getElementById('module-list');
|
|
||||||
modules.forEach(([name, cn, en]) => {
|
// Parse module list
|
||||||
const a = document.createElement('a');
|
modules = JSON.parse(module_list());
|
||||||
a.className = 'module-link';
|
const listEl = document.getElementById('module-list');
|
||||||
a.dataset.module = name;
|
modules.forEach(([name, cn, en]) => {
|
||||||
a.textContent = `${cn} - ${en}`;
|
const a = document.createElement('a');
|
||||||
a.onclick = (e) => { e.preventDefault(); loadDoc(name); };
|
a.className = 'module-link';
|
||||||
listEl.appendChild(a);
|
a.dataset.module = name;
|
||||||
});
|
a.textContent = `${cn} - ${en}`;
|
||||||
|
a.onclick = (e) => { e.preventDefault(); loadDoc(name); };
|
||||||
// Logout
|
listEl.appendChild(a);
|
||||||
document.getElementById('logout-btn').onclick = async (e) => {
|
});
|
||||||
e.preventDefault();
|
|
||||||
await fetch(`${API}/api/v1/auth/logout`, {method:'POST'});
|
// Logout
|
||||||
window.location.reload();
|
document.getElementById('logout-btn').onclick = async (e) => {
|
||||||
};
|
e.preventDefault();
|
||||||
|
await fetch(`${API}/api/v1/auth/logout`, {method:'POST'});
|
||||||
// Load initial module from hash or default
|
window.location.reload();
|
||||||
const hash = location.hash.slice(1);
|
};
|
||||||
if (hash) {
|
|
||||||
loadDoc(hash);
|
// Load initial module from hash or default
|
||||||
} else {
|
const hash = location.hash.slice(1);
|
||||||
loadDoc('01_auth');
|
if (hash) {
|
||||||
|
loadDoc(hash);
|
||||||
|
} else {
|
||||||
|
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>
|
||||||
|
|||||||
Reference in New Issue
Block a user