Tyler Hallada
eebae85a65
WorkerPool speeds up processing of plugins by using more cores on separate threads. It terminates and recreates a worker after it finishes a task since web assembly seems to slow down a ton when a worker is reused (maybe memory becomes to large / unfragmented, idk). I switched to the deprecated input tag with webkitdirectory since it is the only way to load a folder under the program files folder. Drag and drop might be another alternative, but I'd rather have a picker.
31 lines
1020 B
TypeScript
31 lines
1020 B
TypeScript
import { hash_plugin, parse_plugin } from "skyrim-cell-dump-wasm";
|
|
|
|
self.postMessage("ready");
|
|
|
|
self.addEventListener('message', async (event: MessageEvent<{ skipParsing?: boolean; filename: string; lastModified: number; contents: Uint8Array }>) => {
|
|
const { skipParsing, filename, lastModified, contents } = event.data;
|
|
let parsed = undefined;
|
|
let parseError = undefined;
|
|
try {
|
|
if (!skipParsing) {
|
|
try {
|
|
parsed = parse_plugin(contents);
|
|
} catch (e) {
|
|
if (e instanceof Error) {
|
|
parseError = e.message;
|
|
} else {
|
|
parseError = "unknown error";
|
|
}
|
|
}
|
|
}
|
|
const hash = hash_plugin(contents).toString(36);
|
|
self.postMessage({ filename, lastModified, parsed, hash, parseError, enabled: parsed && !parseError, timeHashEnd: Date.now() });
|
|
} catch (error) {
|
|
console.error(error);
|
|
self.postMessage(error);
|
|
}
|
|
});
|
|
|
|
//! To avoid isolatedModules error
|
|
// eslint-disable-next-line import/no-anonymous-default-export
|
|
export default {}; |