mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +08:00
stop and recover websocket
This commit is contained in:
parent
f1916c1027
commit
7f539ad75a
|
@ -8,6 +8,7 @@ import yaml from 'yaml'
|
|||
import fs from 'fs'
|
||||
import { dialog } from 'electron'
|
||||
import { addProfileUpdater } from '../core/profileUpdater'
|
||||
import { pauseWebsockets } from '../core/mihomoApi'
|
||||
|
||||
let profileConfig: IProfileConfig // profile.yaml
|
||||
|
||||
|
@ -27,7 +28,9 @@ export async function changeCurrentProfile(id: string): Promise<void> {
|
|||
const oldId = getProfileConfig().current
|
||||
profileConfig.current = id
|
||||
try {
|
||||
const recover = pauseWebsockets()
|
||||
await startCore()
|
||||
recover()
|
||||
} catch (e) {
|
||||
profileConfig.current = oldId
|
||||
} finally {
|
||||
|
@ -177,7 +180,9 @@ export function getProfileStr(id: string): string {
|
|||
export async function setProfileStr(id: string, content: string): Promise<void> {
|
||||
fs.writeFileSync(profilePath(id), content, 'utf-8')
|
||||
if (id === getProfileConfig().current) {
|
||||
const recover = pauseWebsockets()
|
||||
await startCore()
|
||||
recover()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -340,3 +340,26 @@ const mihomoConnections = (): void => {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const pauseWebsockets = () => {
|
||||
const recoverList: (() => void)[] = []
|
||||
if (mihomoTrafficWs) {
|
||||
stopMihomoTraffic()
|
||||
recoverList.push(startMihomoTraffic)
|
||||
}
|
||||
if (mihomoMemoryWs) {
|
||||
stopMihomoMemory()
|
||||
recoverList.push(startMihomoMemory)
|
||||
}
|
||||
if (mihomoLogsWs) {
|
||||
stopMihomoLogs()
|
||||
recoverList.push(startMihomoLogs)
|
||||
}
|
||||
if (mihomoConnectionsWs) {
|
||||
stopMihomoConnections()
|
||||
recoverList.push(startMihomoConnections)
|
||||
}
|
||||
return (): void => {
|
||||
recoverList.forEach((recover) => recover())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
mihomoUpgradeGeo,
|
||||
mihomoVersion,
|
||||
patchMihomoConfig,
|
||||
pauseWebsockets,
|
||||
startMihomoConnections,
|
||||
startMihomoLogs,
|
||||
stopMihomoConnections,
|
||||
|
@ -79,7 +80,11 @@ export function registerIpcMainHandlers(): void {
|
|||
ipcMain.handle('changeCurrentProfile', (_e, id) => changeCurrentProfile(id))
|
||||
ipcMain.handle('addProfileItem', (_e, item) => addProfileItem(item))
|
||||
ipcMain.handle('removeProfileItem', (_e, id) => removeProfileItem(id))
|
||||
ipcMain.handle('restartCore', startCore)
|
||||
ipcMain.handle('restartCore', async () => {
|
||||
const recover = pauseWebsockets()
|
||||
await startCore()
|
||||
recover()
|
||||
})
|
||||
ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable))
|
||||
ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable)
|
||||
ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str))
|
||||
|
|
Loading…
Reference in New Issue
Block a user