mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
catch error
This commit is contained in:
parent
4104b15a64
commit
6abba81187
@ -7,7 +7,7 @@ import WebSocket from 'ws'
|
|||||||
import { tray } from '../resolve/tray'
|
import { tray } from '../resolve/tray'
|
||||||
import { calcTraffic } from '../utils/calc'
|
import { calcTraffic } from '../utils/calc'
|
||||||
import { getRuntimeConfig } from './factory'
|
import { getRuntimeConfig } from './factory'
|
||||||
import { nativeImage } from 'electron'
|
import { dialog, nativeImage } from 'electron'
|
||||||
import parseSvg from '../utils/parseSvg'
|
import parseSvg from '../utils/parseSvg'
|
||||||
|
|
||||||
const icon = nativeImage.createFromPath(svgIcon)
|
const icon = nativeImage.createFromPath(svgIcon)
|
||||||
@ -192,6 +192,8 @@ const mihomoTraffic = async (): Promise<void> => {
|
|||||||
mihomoTrafficWs.onmessage = async (e): Promise<void> => {
|
mihomoTrafficWs.onmessage = async (e): Promise<void> => {
|
||||||
const data = e.data as string
|
const data = e.data as string
|
||||||
const json = JSON.parse(data) as IMihomoTrafficInfo
|
const json = JSON.parse(data) as IMihomoTrafficInfo
|
||||||
|
trafficRetry = 10
|
||||||
|
mainWindow?.webContents.send('mihomoTraffic', json)
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
if (showTraffic) {
|
if (showTraffic) {
|
||||||
if (drawing) return
|
if (drawing) return
|
||||||
@ -204,12 +206,17 @@ const mihomoTraffic = async (): Promise<void> => {
|
|||||||
<text x='156' y='15' font-size='18' font-family="PingFang SC" font-weight='bold' text-anchor='end'>${calcTraffic(json.up)}/s</text>
|
<text x='156' y='15' font-size='18' font-family="PingFang SC" font-weight='bold' text-anchor='end'>${calcTraffic(json.up)}/s</text>
|
||||||
<text x='156' y='34' font-size='18' font-family="PingFang SC" font-weight='bold' text-anchor='end'>${calcTraffic(json.down)}/s</text>
|
<text x='156' y='34' font-size='18' font-family="PingFang SC" font-weight='bold' text-anchor='end'>${calcTraffic(json.down)}/s</text>
|
||||||
</svg>`
|
</svg>`
|
||||||
|
try {
|
||||||
const buffer = await parseSvg(svgContent)
|
const buffer = await parseSvg(svgContent)
|
||||||
const image = nativeImage.createFromBuffer(buffer).resize({ height: 16 })
|
const image = nativeImage.createFromBuffer(buffer).resize({ height: 16 })
|
||||||
image.setTemplateImage(true)
|
image.setTemplateImage(true)
|
||||||
tray?.setImage(image)
|
tray?.setImage(image)
|
||||||
drawing = false
|
|
||||||
hasShowTraffic = true
|
hasShowTraffic = true
|
||||||
|
} catch (e) {
|
||||||
|
dialog.showErrorBox('Parse SVG Error', JSON.stringify(e))
|
||||||
|
} finally {
|
||||||
|
drawing = false
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (hasShowTraffic) {
|
if (hasShowTraffic) {
|
||||||
const icon = nativeImage.createFromPath(templateIcon)
|
const icon = nativeImage.createFromPath(templateIcon)
|
||||||
@ -227,9 +234,6 @@ const mihomoTraffic = async (): Promise<void> => {
|
|||||||
`${calcTraffic(json.down)}/s`.padStart(9)
|
`${calcTraffic(json.down)}/s`.padStart(9)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
trafficRetry = 10
|
|
||||||
mainWindow?.webContents.send('mihomoTraffic', json)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mihomoTrafficWs.onclose = (): void => {
|
mihomoTrafficWs.onclose = (): void => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user