diff --git a/src/main/core/mihomoApi.ts b/src/main/core/mihomoApi.ts index 4db0d98..c5e925e 100644 --- a/src/main/core/mihomoApi.ts +++ b/src/main/core/mihomoApi.ts @@ -7,7 +7,7 @@ import WebSocket from 'ws' import { tray } from '../resolve/tray' import { calcTraffic } from '../utils/calc' import { getRuntimeConfig } from './factory' -import { dialog, nativeImage } from 'electron' +import { nativeImage } from 'electron' import parseSvg from '../utils/parseSvg' const icon = nativeImage.createFromPath(svgIcon) @@ -213,7 +213,7 @@ const mihomoTraffic = async (): Promise => { tray?.setImage(image) hasShowTraffic = true } catch (e) { - dialog.showErrorBox('Parse SVG Error', JSON.stringify(e)) + // ignore } finally { drawing = false } diff --git a/src/main/utils/parseSvg.ts b/src/main/utils/parseSvg.ts index 30801ff..7fd0499 100644 --- a/src/main/utils/parseSvg.ts +++ b/src/main/utils/parseSvg.ts @@ -4,6 +4,9 @@ export default function parseSvg(svgStr: string): Promise { return new Promise((resolve, reject) => { const worker = new Worker(workerString, { eval: true, + env: { + __dirname + }, workerData: svgStr }) worker.on('message', resolve) @@ -16,7 +19,8 @@ export default function parseSvg(svgStr: string): Promise { const workerString = ` const { parentPort, workerData } = require('worker_threads') -const svg2img = require('svg2img') +const path = require('path') +const svg2img = require(path.resolve(process.env.__dirname, '../../node_modules/svg2img')) const svgStr = workerData svg2img(svgStr, (err, buffer) => {