diff --git a/src/main/config/controledMihomo.ts b/src/main/config/controledMihomo.ts index 4ce01a4..83e692f 100644 --- a/src/main/config/controledMihomo.ts +++ b/src/main/config/controledMihomo.ts @@ -1,7 +1,7 @@ import { controledMihomoConfigPath } from '../utils/dirs' import yaml from 'yaml' import fs from 'fs' -import { getAxios } from '../core/mihomoApi' +import { getAxios, startMihomoMemory, startMihomoTraffic } from '../core/mihomoApi' export let controledMihomoConfig: Partial // mihomo.yaml @@ -21,6 +21,8 @@ export function setControledMihomoConfig(patch: Partial): void { controledMihomoConfig = Object.assign(controledMihomoConfig, patch) if (patch['external-controller'] || patch.secret) { getAxios(true) + startMihomoMemory() + startMihomoTraffic() } fs.writeFileSync(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig)) } diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index 2902543..4250129 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -37,10 +37,20 @@ export function startCore(): void { } ) }) + child.on('close', (code, signal) => { + fs.writeFileSync(logPath(), `[Manager]: Core closed, code: ${code}, signal: ${signal}\n`, { + flag: 'a' + }) + fs.writeFileSync(logPath(), `[Manager]: Restart Core\n`, { + flag: 'a' + }) + restartCore() + }) } export function stopCore(): void { if (child) { + child.removeAllListeners() child.kill('SIGINT') } } diff --git a/src/main/core/mihomoApi.ts b/src/main/core/mihomoApi.ts index 4cb665e..0a8fafc 100644 --- a/src/main/core/mihomoApi.ts +++ b/src/main/core/mihomoApi.ts @@ -124,7 +124,7 @@ const mihomoTraffic = (): void => { if (server?.startsWith(':')) server = `127.0.0.1${server}` stopMihomoTraffic() - mihomoTrafficWs = new WebSocket(`ws://${server}/traffic?secret=${secret}`) + mihomoTrafficWs = new WebSocket(`ws://${server}/traffic?token=${encodeURIComponent(secret)}`) mihomoTrafficWs.onmessage = (e): void => { const data = e.data as string @@ -163,7 +163,7 @@ const mihomoMemory = (): void => { if (server?.startsWith(':')) server = `127.0.0.1${server}` stopMihomoMemory() - mihomoMemoryWs = new WebSocket(`ws://${server}/memory?secret=${secret}`) + mihomoMemoryWs = new WebSocket(`ws://${server}/memory?token=${encodeURIComponent(secret)}`) mihomoMemoryWs.onmessage = (e): void => { const data = e.data as string @@ -202,7 +202,7 @@ const mihomoLogs = (): void => { if (server?.startsWith(':')) server = `127.0.0.1${server}` stopMihomoLogs() - mihomoLogsWs = new WebSocket(`ws://${server}/logs?secret=${secret}`) + mihomoLogsWs = new WebSocket(`ws://${server}/logs?token=${encodeURIComponent(secret)}`) mihomoLogsWs.onmessage = (e): void => { const data = e.data as string