Skip to content

Commit

Permalink
fix core manager
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 5, 2024
1 parent 91d99c3 commit 054b68c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/main/config/controledMihomo.ts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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))
}
10 changes: 10 additions & 0 deletions src/main/core/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/core/mihomoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 054b68c

Please sign in to comment.