mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
fix core manager
This commit is contained in:
parent
3cf9f0dccc
commit
5dfcd08867
@ -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<IMihomoConfig> // mihomo.yaml
|
||||
|
||||
@ -21,6 +21,8 @@ export function setControledMihomoConfig(patch: Partial<IMihomoConfig>): void {
|
||||
controledMihomoConfig = Object.assign(controledMihomoConfig, patch)
|
||||
if (patch['external-controller'] || patch.secret) {
|
||||
getAxios(true)
|
||||
startMihomoMemory()
|
||||
startMihomoTraffic()
|
||||
}
|
||||
fs.writeFileSync(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig))
|
||||
}
|
||||
|
||||
@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user