From b1d1ad16537283bbe391e6742c360c588323c5f8 Mon Sep 17 00:00:00 2001 From: vapormusic Date: Sun, 21 Aug 2022 10:23:27 +0700 Subject: [PATCH] fix el 20 worker --- src/main/base/browserwindow.ts | 2 +- src/main/plugins/raop.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index c5bf0133..42f48b1e 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -333,7 +333,7 @@ export class BrowserWindow { contextIsolation: false, webviewTag: true, plugins: true, - nodeIntegrationInWorker: false, + nodeIntegrationInWorker: true, webSecurity: false, preload: join(utils.getPath("srcPath"), "./preload/cider-preload.js"), }, diff --git a/src/main/plugins/raop.ts b/src/main/plugins/raop.ts index 19c57cd3..61089af5 100644 --- a/src/main/plugins/raop.ts +++ b/src/main/plugins/raop.ts @@ -34,7 +34,9 @@ export default class RAOP { private worker: any = null; private processNode = ` - import {parentPort, workerData} from "worker_threads"; + const { + Worker, isMainThread, parentPort, workerData + } = require('node:worker_threads'); function getAudioConv (buffers) { function interleave16(leftChannel, rightChannel) { @@ -264,10 +266,10 @@ export default class RAOP { if (this.airtunes != null) { if (this.worker == null) { try { - const toDataUrl = (js: any) => new URL(`data:text/javascript,${encodeURIComponent(js)}`); + // const toDataUrl = (js: any) => new URL(`data:text/javascript,${encodeURIComponent(js)}`); // let blob = new Blob([this.processNode], { type: 'application/javascript' }); //Create new worker - this.worker = new Worker(toDataUrl(this.processNode)); + this.worker = new Worker(this.processNode, { eval: true }); //Listen for a message from worker this.worker.on("message", (result: any) => { @@ -279,7 +281,7 @@ export default class RAOP { }); this.worker.on("error", (error: any) => { - console.log("bruh", error); + console.log("worker err", error); }); this.worker.postMessage({ buffer: [leftbuffer, rightbuffer] }); } catch (e) { @@ -392,4 +394,4 @@ export default class RAOP { this.uploadImageAirplay(artworkURL.replace("{w}", "1024").replace("{h}", "1024")); } } -} +} \ No newline at end of file