mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +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 fs from 'fs'
|
||||||
import { dialog } from 'electron'
|
import { dialog } from 'electron'
|
||||||
import { addProfileUpdater } from '../core/profileUpdater'
|
import { addProfileUpdater } from '../core/profileUpdater'
|
||||||
|
import { pauseWebsockets } from '../core/mihomoApi'
|
||||||
|
|
||||||
let profileConfig: IProfileConfig // profile.yaml
|
let profileConfig: IProfileConfig // profile.yaml
|
||||||
|
|
||||||
@ -27,7 +28,9 @@ export async function changeCurrentProfile(id: string): Promise<void> {
|
|||||||
const oldId = getProfileConfig().current
|
const oldId = getProfileConfig().current
|
||||||
profileConfig.current = id
|
profileConfig.current = id
|
||||||
try {
|
try {
|
||||||
|
const recover = pauseWebsockets()
|
||||||
await startCore()
|
await startCore()
|
||||||
|
recover()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
profileConfig.current = oldId
|
profileConfig.current = oldId
|
||||||
} finally {
|
} finally {
|
||||||
@ -177,7 +180,9 @@ export function getProfileStr(id: string): string {
|
|||||||
export async function setProfileStr(id: string, content: string): Promise<void> {
|
export async function setProfileStr(id: string, content: string): Promise<void> {
|
||||||
fs.writeFileSync(profilePath(id), content, 'utf-8')
|
fs.writeFileSync(profilePath(id), content, 'utf-8')
|
||||||
if (id === getProfileConfig().current) {
|
if (id === getProfileConfig().current) {
|
||||||
|
const recover = pauseWebsockets()
|
||||||
await startCore()
|
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,
|
mihomoUpgradeGeo,
|
||||||
mihomoVersion,
|
mihomoVersion,
|
||||||
patchMihomoConfig,
|
patchMihomoConfig,
|
||||||
|
pauseWebsockets,
|
||||||
startMihomoConnections,
|
startMihomoConnections,
|
||||||
startMihomoLogs,
|
startMihomoLogs,
|
||||||
stopMihomoConnections,
|
stopMihomoConnections,
|
||||||
@ -79,7 +80,11 @@ export function registerIpcMainHandlers(): void {
|
|||||||
ipcMain.handle('changeCurrentProfile', (_e, id) => changeCurrentProfile(id))
|
ipcMain.handle('changeCurrentProfile', (_e, id) => changeCurrentProfile(id))
|
||||||
ipcMain.handle('addProfileItem', (_e, item) => addProfileItem(item))
|
ipcMain.handle('addProfileItem', (_e, item) => addProfileItem(item))
|
||||||
ipcMain.handle('removeProfileItem', (_e, id) => removeProfileItem(id))
|
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('triggerSysProxy', (_e, enable) => triggerSysProxy(enable))
|
||||||
ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable)
|
ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable)
|
||||||
ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str))
|
ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user