Skip to content

Commit 054b68c

Browse files
author
pompurin404
committed
fix core manager
1 parent 91d99c3 commit 054b68c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/main/config/controledMihomo.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { controledMihomoConfigPath } from '../utils/dirs'
22
import yaml from 'yaml'
33
import fs from 'fs'
4-
import { getAxios } from '../core/mihomoApi'
4+
import { getAxios, startMihomoMemory, startMihomoTraffic } from '../core/mihomoApi'
55

66
export let controledMihomoConfig: Partial<IMihomoConfig> // mihomo.yaml
77

@@ -21,6 +21,8 @@ export function setControledMihomoConfig(patch: Partial<IMihomoConfig>): void {
2121
controledMihomoConfig = Object.assign(controledMihomoConfig, patch)
2222
if (patch['external-controller'] || patch.secret) {
2323
getAxios(true)
24+
startMihomoMemory()
25+
startMihomoTraffic()
2426
}
2527
fs.writeFileSync(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig))
2628
}

src/main/core/manager.ts

+10
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,20 @@ export function startCore(): void {
3737
}
3838
)
3939
})
40+
child.on('close', (code, signal) => {
41+
fs.writeFileSync(logPath(), `[Manager]: Core closed, code: ${code}, signal: ${signal}\n`, {
42+
flag: 'a'
43+
})
44+
fs.writeFileSync(logPath(), `[Manager]: Restart Core\n`, {
45+
flag: 'a'
46+
})
47+
restartCore()
48+
})
4049
}
4150

4251
export function stopCore(): void {
4352
if (child) {
53+
child.removeAllListeners()
4454
child.kill('SIGINT')
4555
}
4656
}

src/main/core/mihomoApi.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const mihomoTraffic = (): void => {
124124
if (server?.startsWith(':')) server = `127.0.0.1${server}`
125125
stopMihomoTraffic()
126126

127-
mihomoTrafficWs = new WebSocket(`ws://${server}/traffic?secret=${secret}`)
127+
mihomoTrafficWs = new WebSocket(`ws://${server}/traffic?token=${encodeURIComponent(secret)}`)
128128

129129
mihomoTrafficWs.onmessage = (e): void => {
130130
const data = e.data as string
@@ -163,7 +163,7 @@ const mihomoMemory = (): void => {
163163
if (server?.startsWith(':')) server = `127.0.0.1${server}`
164164
stopMihomoMemory()
165165

166-
mihomoMemoryWs = new WebSocket(`ws://${server}/memory?secret=${secret}`)
166+
mihomoMemoryWs = new WebSocket(`ws://${server}/memory?token=${encodeURIComponent(secret)}`)
167167

168168
mihomoMemoryWs.onmessage = (e): void => {
169169
const data = e.data as string
@@ -202,7 +202,7 @@ const mihomoLogs = (): void => {
202202
if (server?.startsWith(':')) server = `127.0.0.1${server}`
203203
stopMihomoLogs()
204204

205-
mihomoLogsWs = new WebSocket(`ws://${server}/logs?secret=${secret}`)
205+
mihomoLogsWs = new WebSocket(`ws://${server}/logs?token=${encodeURIComponent(secret)}`)
206206

207207
mihomoLogsWs.onmessage = (e): void => {
208208
const data = e.data as string

0 commit comments

Comments
 (0)