49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
(function(){
|
|
// Bootstrap mínimo do painel.
|
|
// Regra (.agent): a lógica fica no WASM; aqui apenas garantimos que o WASM
|
|
// esteja carregado/executando.
|
|
//
|
|
// Este arquivo existe para evitar JS inline no HTML do painel.
|
|
|
|
async function carregarWasmPainel(){
|
|
try{
|
|
if(window.__eli_nps_wasm_ready) return true;
|
|
if(window.__eli_nps_wasm_loading) return window.__eli_nps_wasm_loading;
|
|
|
|
window.__eli_nps_wasm_loading = (async function(){
|
|
try{
|
|
if(!window.Go){
|
|
// wasm_exec.js deve ter sido carregado pelo HTML.
|
|
return false;
|
|
}
|
|
const go = new Go();
|
|
const res = await fetch('/static/e-li.nps.wasm', {cache: 'no-cache'});
|
|
if(!res.ok) return false;
|
|
const bytes = await res.arrayBuffer();
|
|
const {instance} = await WebAssembly.instantiate(bytes, go.importObject);
|
|
go.run(instance);
|
|
return !!window.__eli_nps_wasm_ready;
|
|
}catch(e){
|
|
return false;
|
|
}
|
|
})();
|
|
|
|
return window.__eli_nps_wasm_loading;
|
|
}catch(e){
|
|
return false;
|
|
}
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function(){
|
|
carregarWasmPainel().then(function(ok){
|
|
if(!ok) return;
|
|
// Executa o init do painel no WASM (best-effort).
|
|
try{
|
|
if(typeof window.__eli_nps_wasm_painel_init === 'function'){
|
|
window.__eli_nps_wasm_painel_init();
|
|
}
|
|
}catch(e){}
|
|
});
|
|
});
|
|
})();
|
|
|