mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
always keep websocket
This commit is contained in:
parent
5438aef528
commit
4a067c4f51
@ -1,7 +1,7 @@
|
|||||||
import { controledMihomoConfigPath } from '../utils/dirs'
|
import { controledMihomoConfigPath } from '../utils/dirs'
|
||||||
import { readFile, writeFile } from 'fs/promises'
|
import { readFile, writeFile } from 'fs/promises'
|
||||||
import yaml from 'yaml'
|
import yaml from 'yaml'
|
||||||
import { getAxios, startMihomoMemory, startMihomoTraffic } from '../core/mihomoApi'
|
import { getAxios } from '../core/mihomoApi'
|
||||||
import { generateProfile } from '../core/factory'
|
import { generateProfile } from '../core/factory'
|
||||||
import { getAppConfig } from './app'
|
import { getAppConfig } from './app'
|
||||||
import { defaultControledMihomoConfig } from '../utils/template'
|
import { defaultControledMihomoConfig } from '../utils/template'
|
||||||
@ -50,8 +50,6 @@ export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>):
|
|||||||
|
|
||||||
if (patch['external-controller'] || patch.secret) {
|
if (patch['external-controller'] || patch.secret) {
|
||||||
await getAxios(true)
|
await getAxios(true)
|
||||||
await startMihomoMemory()
|
|
||||||
await startMihomoTraffic()
|
|
||||||
}
|
}
|
||||||
await generateProfile()
|
await generateProfile()
|
||||||
await writeFile(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig), 'utf-8')
|
await writeFile(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig), 'utf-8')
|
||||||
|
|||||||
@ -10,7 +10,12 @@ import {
|
|||||||
import { generateProfile } from './factory'
|
import { generateProfile } from './factory'
|
||||||
import { getAppConfig, getControledMihomoConfig, patchAppConfig } from '../config'
|
import { getAppConfig, getControledMihomoConfig, patchAppConfig } from '../config'
|
||||||
import { dialog, safeStorage } from 'electron'
|
import { dialog, safeStorage } from 'electron'
|
||||||
import { pauseWebsockets, startMihomoTraffic } from './mihomoApi'
|
import {
|
||||||
|
startMihomoTraffic,
|
||||||
|
startMihomoConnections,
|
||||||
|
startMihomoLogs,
|
||||||
|
startMihomoMemory
|
||||||
|
} from './mihomoApi'
|
||||||
import chokidar from 'chokidar'
|
import chokidar from 'chokidar'
|
||||||
import { writeFile } from 'fs/promises'
|
import { writeFile } from 'fs/promises'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
@ -96,6 +101,9 @@ export async function startCore(): Promise<Promise<void>[]> {
|
|||||||
})
|
})
|
||||||
])
|
])
|
||||||
await startMihomoTraffic()
|
await startMihomoTraffic()
|
||||||
|
await startMihomoConnections()
|
||||||
|
await startMihomoLogs()
|
||||||
|
await startMihomoMemory()
|
||||||
retry = 10
|
retry = 10
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -121,9 +129,7 @@ export async function stopCore(force = false): Promise<void> {
|
|||||||
|
|
||||||
export async function restartCore(): Promise<void> {
|
export async function restartCore(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const recover = pauseWebsockets()
|
|
||||||
await startCore()
|
await startCore()
|
||||||
recover()
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dialog.showErrorBox('内核启动出错', `${e}`)
|
dialog.showErrorBox('内核启动出错', `${e}`)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -347,24 +347,3 @@ const mihomoConnections = async (): Promise<void> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pauseWebsockets = () => {
|
|
||||||
const recoverList: (() => void)[] = []
|
|
||||||
// Traffic 内核启动时始终开启
|
|
||||||
stopMihomoTraffic()
|
|
||||||
if (mihomoMemoryWs) {
|
|
||||||
stopMihomoMemory()
|
|
||||||
recoverList.push(startMihomoMemory)
|
|
||||||
}
|
|
||||||
if (mihomoLogsWs) {
|
|
||||||
stopMihomoLogs()
|
|
||||||
recoverList.push(startMihomoLogs)
|
|
||||||
}
|
|
||||||
if (mihomoConnectionsWs) {
|
|
||||||
stopMihomoConnections()
|
|
||||||
recoverList.push(startMihomoConnections)
|
|
||||||
}
|
|
||||||
return (): void => {
|
|
||||||
recoverList.forEach((recover) => recover())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
|||||||
import { registerIpcMainHandlers } from './utils/ipc'
|
import { registerIpcMainHandlers } from './utils/ipc'
|
||||||
import windowStateKeeper from 'electron-window-state'
|
import windowStateKeeper from 'electron-window-state'
|
||||||
import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron'
|
import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron'
|
||||||
import { pauseWebsockets, startMihomoMemory, stopMihomoMemory } from './core/mihomoApi'
|
|
||||||
import { addProfileItem, getAppConfig } from './config'
|
import { addProfileItem, getAppConfig } from './config'
|
||||||
import { startCore, stopCore } from './core/manager'
|
import { startCore, stopCore } from './core/manager'
|
||||||
import { triggerSysProxy } from './sys/sysproxy'
|
import { triggerSysProxy } from './sys/sysproxy'
|
||||||
@ -73,7 +72,6 @@ app.on('window-all-closed', (e) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.on('before-quit', async () => {
|
app.on('before-quit', async () => {
|
||||||
pauseWebsockets()
|
|
||||||
await stopCore()
|
await stopCore()
|
||||||
triggerSysProxy(false)
|
triggerSysProxy(false)
|
||||||
app.exit()
|
app.exit()
|
||||||
@ -186,13 +184,8 @@ export async function createWindow(): Promise<void> {
|
|||||||
mainWindow?.webContents.reload()
|
mainWindow?.webContents.reload()
|
||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.on('show', () => {
|
|
||||||
startMihomoMemory()
|
|
||||||
})
|
|
||||||
|
|
||||||
mainWindow.on('close', (event) => {
|
mainWindow.on('close', (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
stopMihomoMemory()
|
|
||||||
mainWindow?.hide()
|
mainWindow?.hide()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -15,11 +15,7 @@ import {
|
|||||||
mihomoUpgrade,
|
mihomoUpgrade,
|
||||||
mihomoUpgradeGeo,
|
mihomoUpgradeGeo,
|
||||||
mihomoVersion,
|
mihomoVersion,
|
||||||
patchMihomoConfig,
|
patchMihomoConfig
|
||||||
startMihomoConnections,
|
|
||||||
startMihomoLogs,
|
|
||||||
stopMihomoConnections,
|
|
||||||
stopMihomoLogs
|
|
||||||
} from '../core/mihomoApi'
|
} from '../core/mihomoApi'
|
||||||
import { checkAutoRun, disableAutoRun, enableAutoRun } from '../sys/autoRun'
|
import { checkAutoRun, disableAutoRun, enableAutoRun } from '../sys/autoRun'
|
||||||
import {
|
import {
|
||||||
@ -112,10 +108,6 @@ export function registerIpcMainHandlers(): void {
|
|||||||
ipcMain.handle('mihomoGroupDelay', (_e, group, url) =>
|
ipcMain.handle('mihomoGroupDelay', (_e, group, url) =>
|
||||||
ipcErrorWrapper(mihomoGroupDelay)(group, url)
|
ipcErrorWrapper(mihomoGroupDelay)(group, url)
|
||||||
)
|
)
|
||||||
ipcMain.handle('startMihomoLogs', ipcErrorWrapper(startMihomoLogs))
|
|
||||||
ipcMain.handle('stopMihomoLogs', stopMihomoLogs)
|
|
||||||
ipcMain.handle('startMihomoConnections', ipcErrorWrapper(startMihomoConnections))
|
|
||||||
ipcMain.handle('stopMihomoConnections', stopMihomoConnections)
|
|
||||||
ipcMain.handle('patchMihomoConfig', (_e, patch) => ipcErrorWrapper(patchMihomoConfig)(patch))
|
ipcMain.handle('patchMihomoConfig', (_e, patch) => ipcErrorWrapper(patchMihomoConfig)(patch))
|
||||||
ipcMain.handle('checkAutoRun', ipcErrorWrapper(checkAutoRun))
|
ipcMain.handle('checkAutoRun', ipcErrorWrapper(checkAutoRun))
|
||||||
ipcMain.handle('enableAutoRun', ipcErrorWrapper(enableAutoRun))
|
ipcMain.handle('enableAutoRun', ipcErrorWrapper(enableAutoRun))
|
||||||
|
|||||||
@ -1,10 +1,5 @@
|
|||||||
import BasePage from '@renderer/components/base/base-page'
|
import BasePage from '@renderer/components/base/base-page'
|
||||||
import {
|
import { mihomoCloseAllConnections, mihomoCloseConnection } from '@renderer/utils/ipc'
|
||||||
mihomoCloseAllConnections,
|
|
||||||
mihomoCloseConnection,
|
|
||||||
startMihomoConnections,
|
|
||||||
stopMihomoConnections
|
|
||||||
} from '@renderer/utils/ipc'
|
|
||||||
import { useEffect, useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { Badge, Button, Divider, Input, Select, SelectItem } from '@nextui-org/react'
|
import { Badge, Button, Divider, Input, Select, SelectItem } from '@nextui-org/react'
|
||||||
import { calcTraffic } from '@renderer/utils/calc'
|
import { calcTraffic } from '@renderer/utils/calc'
|
||||||
@ -66,7 +61,6 @@ const Connections: React.FC = () => {
|
|||||||
}, [connections, filter])
|
}, [connections, filter])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
startMihomoConnections()
|
|
||||||
window.electron.ipcRenderer.on('mihomoConnections', (_e, info: IMihomoConnectionsInfo) => {
|
window.electron.ipcRenderer.on('mihomoConnections', (_e, info: IMihomoConnectionsInfo) => {
|
||||||
setConnectionsInfo(info)
|
setConnectionsInfo(info)
|
||||||
const newConns: IMihomoConnectionDetail[] = []
|
const newConns: IMihomoConnectionDetail[] = []
|
||||||
@ -84,7 +78,6 @@ const Connections: React.FC = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (): void => {
|
return (): void => {
|
||||||
stopMihomoConnections()
|
|
||||||
window.electron.ipcRenderer.removeAllListeners('mihomoConnections')
|
window.electron.ipcRenderer.removeAllListeners('mihomoConnections')
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import BasePage from '@renderer/components/base/base-page'
|
import BasePage from '@renderer/components/base/base-page'
|
||||||
import { startMihomoLogs, stopMihomoLogs } from '@renderer/utils/ipc'
|
|
||||||
import LogItem from '@renderer/components/logs/log-item'
|
import LogItem from '@renderer/components/logs/log-item'
|
||||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { Button, Divider, Input } from '@nextui-org/react'
|
import { Button, Divider, Input } from '@nextui-org/react'
|
||||||
@ -29,7 +28,6 @@ const Logs: React.FC = () => {
|
|||||||
}, [filteredLogs, trace])
|
}, [filteredLogs, trace])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
startMihomoLogs()
|
|
||||||
window.electron.ipcRenderer.on('mihomoLogs', (_e, log: IMihomoLogInfo) => {
|
window.electron.ipcRenderer.on('mihomoLogs', (_e, log: IMihomoLogInfo) => {
|
||||||
log.time = new Date().toLocaleString()
|
log.time = new Date().toLocaleString()
|
||||||
setLogs((prevLogs) => {
|
setLogs((prevLogs) => {
|
||||||
@ -38,7 +36,6 @@ const Logs: React.FC = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (): void => {
|
return (): void => {
|
||||||
stopMihomoLogs()
|
|
||||||
window.electron.ipcRenderer.removeAllListeners('mihomoLogs')
|
window.electron.ipcRenderer.removeAllListeners('mihomoLogs')
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|||||||
@ -75,22 +75,6 @@ export async function mihomoGroupDelay(group: string, url?: string): Promise<IMi
|
|||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoGroupDelay', group, url))
|
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoGroupDelay', group, url))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startMihomoLogs(): Promise<void> {
|
|
||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('startMihomoLogs'))
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function stopMihomoLogs(): Promise<void> {
|
|
||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('stopMihomoLogs'))
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function startMihomoConnections(): Promise<void> {
|
|
||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('startMihomoConnections'))
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function stopMihomoConnections(): Promise<void> {
|
|
||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('stopMihomoConnections'))
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function patchMihomoConfig(patch: Partial<IMihomoConfig>): Promise<void> {
|
export async function patchMihomoConfig(patch: Partial<IMihomoConfig>): Promise<void> {
|
||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('patchMihomoConfig', patch))
|
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('patchMihomoConfig', patch))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user