fix core manager

This commit is contained in:
pompurin404 2024-08-05 12:17:20 +08:00
parent 3cf9f0dccc
commit 5dfcd08867
No known key found for this signature in database
3 changed files with 16 additions and 4 deletions

View File

@ -1,7 +1,7 @@
import { controledMihomoConfigPath } from '../utils/dirs' import { controledMihomoConfigPath } from '../utils/dirs'
import yaml from 'yaml' import yaml from 'yaml'
import fs from 'fs' import fs from 'fs'
import { getAxios } from '../core/mihomoApi' import { getAxios, startMihomoMemory, startMihomoTraffic } from '../core/mihomoApi'
export let controledMihomoConfig: Partial<IMihomoConfig> // mihomo.yaml export let controledMihomoConfig: Partial<IMihomoConfig> // mihomo.yaml
@ -21,6 +21,8 @@ export function setControledMihomoConfig(patch: Partial<IMihomoConfig>): void {
controledMihomoConfig = Object.assign(controledMihomoConfig, patch) controledMihomoConfig = Object.assign(controledMihomoConfig, patch)
if (patch['external-controller'] || patch.secret) { if (patch['external-controller'] || patch.secret) {
getAxios(true) getAxios(true)
startMihomoMemory()
startMihomoTraffic()
} }
fs.writeFileSync(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig)) fs.writeFileSync(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig))
} }

View File

@ -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 { export function stopCore(): void {
if (child) { if (child) {
child.removeAllListeners()
child.kill('SIGINT') child.kill('SIGINT')
} }
} }

View File

@ -124,7 +124,7 @@ const mihomoTraffic = (): void => {
if (server?.startsWith(':')) server = `127.0.0.1${server}` if (server?.startsWith(':')) server = `127.0.0.1${server}`
stopMihomoTraffic() stopMihomoTraffic()
mihomoTrafficWs = new WebSocket(`ws://${server}/traffic?secret=${secret}`) mihomoTrafficWs = new WebSocket(`ws://${server}/traffic?token=${encodeURIComponent(secret)}`)
mihomoTrafficWs.onmessage = (e): void => { mihomoTrafficWs.onmessage = (e): void => {
const data = e.data as string const data = e.data as string
@ -163,7 +163,7 @@ const mihomoMemory = (): void => {
if (server?.startsWith(':')) server = `127.0.0.1${server}` if (server?.startsWith(':')) server = `127.0.0.1${server}`
stopMihomoMemory() stopMihomoMemory()
mihomoMemoryWs = new WebSocket(`ws://${server}/memory?secret=${secret}`) mihomoMemoryWs = new WebSocket(`ws://${server}/memory?token=${encodeURIComponent(secret)}`)
mihomoMemoryWs.onmessage = (e): void => { mihomoMemoryWs.onmessage = (e): void => {
const data = e.data as string const data = e.data as string
@ -202,7 +202,7 @@ const mihomoLogs = (): void => {
if (server?.startsWith(':')) server = `127.0.0.1${server}` if (server?.startsWith(':')) server = `127.0.0.1${server}`
stopMihomoLogs() stopMihomoLogs()
mihomoLogsWs = new WebSocket(`ws://${server}/logs?secret=${secret}`) mihomoLogsWs = new WebSocket(`ws://${server}/logs?token=${encodeURIComponent(secret)}`)
mihomoLogsWs.onmessage = (e): void => { mihomoLogsWs.onmessage = (e): void => {
const data = e.data as string const data = e.data as string