Move files around
This commit is contained in:
50
web/public/js/patch-worker.js
Normal file
50
web/public/js/patch-worker.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// Web Worker for running kobopatch WASM off the main thread.
|
||||
// Communicates with the main thread via postMessage.
|
||||
|
||||
importScripts('wasm_exec.js');
|
||||
|
||||
let wasmReady = false;
|
||||
|
||||
async function loadWasm() {
|
||||
if (wasmReady) return;
|
||||
|
||||
const go = new Go();
|
||||
const result = await WebAssembly.instantiateStreaming(
|
||||
fetch('../wasm/kobopatch.wasm?ts=1773690621'),
|
||||
go.importObject
|
||||
);
|
||||
go.run(result.instance);
|
||||
|
||||
if (typeof globalThis.patchFirmware !== 'function') {
|
||||
throw new Error('WASM module loaded but patchFirmware() not found');
|
||||
}
|
||||
wasmReady = true;
|
||||
}
|
||||
|
||||
self.onmessage = async function(e) {
|
||||
const { type, configYAML, firmwareZip, patchFiles } = e.data;
|
||||
|
||||
if (type !== 'patch') return;
|
||||
|
||||
try {
|
||||
self.postMessage({ type: 'progress', message: 'Loading WASM patcher...' });
|
||||
await loadWasm();
|
||||
self.postMessage({ type: 'progress', message: 'WASM module loaded' });
|
||||
|
||||
self.postMessage({ type: 'progress', message: 'Applying patches...' });
|
||||
|
||||
const result = await globalThis.patchFirmware(configYAML, firmwareZip, patchFiles, (msg) => {
|
||||
self.postMessage({ type: 'progress', message: msg });
|
||||
});
|
||||
|
||||
// Transfer the tgz buffer to avoid copying
|
||||
const tgzBuffer = result.tgz.buffer;
|
||||
self.postMessage({
|
||||
type: 'done',
|
||||
tgz: result.tgz,
|
||||
log: result.log,
|
||||
}, [tgzBuffer]);
|
||||
} catch (err) {
|
||||
self.postMessage({ type: 'error', message: err.message });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user