mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
fix worker
This commit is contained in:
parent
6abba81187
commit
857a21ab34
@ -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<void> => {
|
||||
tray?.setImage(image)
|
||||
hasShowTraffic = true
|
||||
} catch (e) {
|
||||
dialog.showErrorBox('Parse SVG Error', JSON.stringify(e))
|
||||
// ignore
|
||||
} finally {
|
||||
drawing = false
|
||||
}
|
||||
|
||||
@ -4,6 +4,9 @@ export default function parseSvg(svgStr: string): Promise<Buffer> {
|
||||
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<Buffer> {
|
||||
|
||||
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) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user