An easy-to-use platform for EEG experimentation in the classroom
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

initial cleanup

+34 -9
+1 -3
src/renderer/utils/webworker/index.ts
··· 36 36 37 37 export const loadCSV = async (worker: Worker, csvArray: Array<unknown>) => { 38 38 // TODO: Pass attached variable name as parameter to load_data 39 - // @ts-expect-error 40 - window.csvArray = csvArray; 41 - await worker.postMessage({ data: `raw = load_data()` }); 39 + await worker.postMessage({ data: `raw = load_data()`, csvArray }); 42 40 }; 43 41 44 42 // ---------------------------
+33 -6
src/renderer/utils/webworker/webworker.js
··· 25 25 26 26 import { loadPyodide } from 'pyodide'; 27 27 28 + /** 29 + * Derive the renderer root URL from the worker's own location. 30 + * 31 + * Dev (Vite HTTP server): self.location.href is an http:// URL — the root is 32 + * just the origin, so root-relative paths work as normal. 33 + * 34 + * Production (Electron file://): Vite bundles workers into assets/, so the 35 + * renderer root is one directory above the worker file. 36 + */ 37 + function getRendererBaseUrl() { 38 + const loc = self.location.href; 39 + if (loc.startsWith('http')) { 40 + return new URL('/', loc).href; 41 + } 42 + // file:// — go up from assets/webworker-[hash].js to the renderer root 43 + return new URL('../', loc).href; 44 + } 45 + 28 46 async function initPyodide() { 47 + const base = getRendererBaseUrl(); 48 + 29 49 // indexURL tells pyodide where to load pyodide-lock.json and binary wheels. 30 - // The publicDir (src/renderer/utils/webworker/src/) is served at the web root, 31 - // so /pyodide/ maps to src/renderer/utils/webworker/src/pyodide/. 32 - const pyodide = await loadPyodide({ indexURL: '/pyodide/' }); 50 + // Resolved from the renderer root so it works under both HTTP (dev) and 51 + // file:// (Electron production). 52 + const pyodide = await loadPyodide({ indexURL: new URL('pyodide/', base).href }); 33 53 34 54 // Load binary packages from locally served .whl files. 35 55 await pyodide.loadPackage(['numpy', 'scipy', 'matplotlib', 'pandas']); ··· 37 57 // Install MNE and its pure-Python deps from pre-downloaded wheels. 38 58 let manifest = {}; 39 59 try { 40 - const res = await fetch(new URL('/packages/manifest.json', self.location.href).href); 60 + const res = await fetch(new URL('packages/manifest.json', base).href); 41 61 if (res.ok) { 42 62 manifest = await res.json(); 43 63 } else { ··· 48 68 } 49 69 50 70 const wheelUrls = Object.values(manifest).map( 51 - (entry) => new URL(`/packages/${entry.filename}`, self.location.href).href 71 + (entry) => new URL(`packages/${entry.filename}`, base).href 52 72 ); 53 73 54 74 if (wheelUrls.length > 0) { ··· 66 86 const pyodideReadyPromise = initPyodide(); 67 87 68 88 self.onmessage = async (event) => { 69 - const pyodide = await pyodideReadyPromise; 89 + // Propagate init failures back to the main thread rather than hanging silently. 90 + let pyodide; 91 + try { 92 + pyodide = await pyodideReadyPromise; 93 + } catch (error) { 94 + self.postMessage({ error: `Pyodide init failed: ${error.message}` }); 95 + return; 96 + } 70 97 71 98 const { data, ...context } = event.data; 72 99