fix websicket

This commit is contained in:
pompurin404 2024-08-01 19:04:30 +08:00
parent 4f335bddd5
commit 536ae67e29
No known key found for this signature in database
6 changed files with 19 additions and 10 deletions

View File

@ -5,7 +5,7 @@ import {
mihomoRules,
mihomoVersion,
patchMihomoConfig
} from './mihomo-api'
} from './mihomoApi'
import { checkAutoRun, disableAutoRun, enableAutoRun } from './autoRun'
import {
getAppConfig,

View File

@ -6,7 +6,7 @@ import { registerIpcMainHandlers } from './cmds'
import { initConfig, appConfig } from './config'
import { stopCore, startCore } from './manager'
import { initDirs } from './dirs'
import { mihomoTraffic } from './mihomo-api'
import { mihomoTraffic } from './mihomoApi'
import { createTray } from './tray'
export let window: BrowserWindow | null = null

View File

@ -55,12 +55,17 @@ export const mihomoTraffic = (): void => {
mihomoTrafficWs = new WebSocket(`ws://${server}/traffic?secret=${secret}`)
mihomoTrafficWs.onmessage = (e: { data: string }): void => {
window?.webContents.send('mihomoTraffic', JSON.parse(e.data) as IMihomoTrafficInfo)
mihomoTrafficWs.onmessage = (e): void => {
const data = e.data as string
window?.webContents.send('mihomoTraffic', JSON.parse(data) as IMihomoTrafficInfo)
}
mihomoTrafficWs.onclose = (): void => {
mihomoTraffic()
}
mihomoTrafficWs.onerror = (): void => {
console.error('Traffic ws error')
mihomoConfig()
if (mihomoTrafficWs) {
mihomoTrafficWs.close()
mihomoTrafficWs = null!
}
}
}

View File

@ -1,7 +1,7 @@
import { controledMihomoConfig, setControledMihomoConfig } from './config'
import icoIcon from '../../resources/icon.ico?asset'
import pngIcon from '../../resources/icon.png?asset'
import { patchMihomoConfig } from './mihomo-api'
import { patchMihomoConfig } from './mihomoApi'
import { window } from '.'
import { app, ipcMain, Menu, Tray } from 'electron'

View File

@ -26,7 +26,9 @@ const SysproxySwitcher: React.FC = () => {
<AiOutlineGlobal color="default" className="text-[24px]" />
</Button>
<Switch
classNames={{ wrapper: `${match && enable ? 'border-2' : ''}` }}
classNames={{
wrapper: `${match && enable ? 'border-2' : ''}`
}}
size="sm"
isSelected={enable}
onValueChange={setEnable}

View File

@ -26,7 +26,9 @@ const TunSwitcher: React.FC = () => {
<TbDeviceIpadHorizontalBolt color="default" className="text-[24px] font-bold" />
</Button>
<Switch
classNames={{ wrapper: `${match && enable ? 'border-2' : ''}` }}
classNames={{
wrapper: `${match && enable ? 'border-2' : ''}`
}}
size="sm"
isSelected={enable}
onValueChange={setEnable}