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, mihomoRules,
mihomoVersion, mihomoVersion,
patchMihomoConfig patchMihomoConfig
} from './mihomo-api' } from './mihomoApi'
import { checkAutoRun, disableAutoRun, enableAutoRun } from './autoRun' import { checkAutoRun, disableAutoRun, enableAutoRun } from './autoRun'
import { import {
getAppConfig, getAppConfig,

View File

@ -6,7 +6,7 @@ import { registerIpcMainHandlers } from './cmds'
import { initConfig, appConfig } from './config' import { initConfig, appConfig } from './config'
import { stopCore, startCore } from './manager' import { stopCore, startCore } from './manager'
import { initDirs } from './dirs' import { initDirs } from './dirs'
import { mihomoTraffic } from './mihomo-api' import { mihomoTraffic } from './mihomoApi'
import { createTray } from './tray' import { createTray } from './tray'
export let window: BrowserWindow | null = null 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 = new WebSocket(`ws://${server}/traffic?secret=${secret}`)
mihomoTrafficWs.onmessage = (e: { data: string }): void => { mihomoTrafficWs.onmessage = (e): void => {
window?.webContents.send('mihomoTraffic', JSON.parse(e.data) as IMihomoTrafficInfo) const data = e.data as string
window?.webContents.send('mihomoTraffic', JSON.parse(data) as IMihomoTrafficInfo)
}
mihomoTrafficWs.onclose = (): void => {
mihomoTraffic()
} }
mihomoTrafficWs.onerror = (): void => { mihomoTrafficWs.onerror = (): void => {
console.error('Traffic ws error') if (mihomoTrafficWs) {
mihomoConfig() mihomoTrafficWs.close()
mihomoTrafficWs = null!
}
} }
} }

View File

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

View File

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

View File

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