diff --git a/src/main/core/mihomoApi.ts b/src/main/core/mihomoApi.ts index 7f49917..c306358 100644 --- a/src/main/core/mihomoApi.ts +++ b/src/main/core/mihomoApi.ts @@ -5,8 +5,6 @@ import WebSocket from 'ws' import { tray } from '../resolve/tray' import { calcTraffic } from '../utils/calc' import { getRuntimeConfig } from './factory' -import { join } from 'path' -import { mihomoWorkDir } from '../utils/dirs' let axiosIns: AxiosInstance = null! let mihomoTrafficWs: WebSocket | null = null @@ -21,13 +19,13 @@ let connectionsRetry = 10 export const getAxios = async (force: boolean = false): Promise => { const { 'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo', - 'external-controller-unix': mihomoUnix = 'mihomo-party.sock' + 'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock' } = await getControledMihomoConfig() if (axiosIns && !force) return axiosIns axiosIns = axios.create({ baseURL: `http://localhost`, - socketPath: process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix), + socketPath: process.platform === 'win32' ? mihomoPipe : mihomoUnix, timeout: 15000 }) @@ -183,11 +181,11 @@ export const stopMihomoTraffic = (): void => { const mihomoTraffic = async (): Promise => { const { 'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo', - 'external-controller-unix': mihomoUnix = 'mihomo-party.sock' + 'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock' } = await getControledMihomoConfig() mihomoTrafficWs = new WebSocket( - `ws+unix:${process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)}:/traffic` + `ws+unix:${process.platform === 'win32' ? mihomoPipe : mihomoUnix}:/traffic` ) mihomoTrafficWs.onmessage = async (e): Promise => { @@ -241,11 +239,11 @@ export const stopMihomoMemory = (): void => { const mihomoMemory = async (): Promise => { const { 'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo', - 'external-controller-unix': mihomoUnix = 'mihomo-party.sock' + 'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock' } = await getControledMihomoConfig() mihomoMemoryWs = new WebSocket( - `ws+unix:${process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)}:/memory` + `ws+unix:${process.platform === 'win32' ? mihomoPipe : mihomoUnix}:/memory` ) mihomoMemoryWs.onmessage = (e): void => { @@ -290,12 +288,12 @@ export const stopMihomoLogs = (): void => { const mihomoLogs = async (): Promise => { const { 'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo', - 'external-controller-unix': mihomoUnix = 'mihomo-party.sock', + 'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock', 'log-level': logLevel = 'info' } = await getControledMihomoConfig() mihomoLogsWs = new WebSocket( - `ws+unix:${process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)}:/logs?level=${logLevel}` + `ws+unix:${process.platform === 'win32' ? mihomoPipe : mihomoUnix}:/logs?level=${logLevel}` ) mihomoLogsWs.onmessage = (e): void => { @@ -340,11 +338,11 @@ export const stopMihomoConnections = (): void => { const mihomoConnections = async (): Promise => { const { 'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo', - 'external-controller-unix': mihomoUnix = 'mihomo-party.sock' + 'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock' } = await getControledMihomoConfig() mihomoConnectionsWs = new WebSocket( - `ws+unix:${process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)}:/connections` + `ws+unix:${process.platform === 'win32' ? mihomoPipe : mihomoUnix}:/connections` ) mihomoConnectionsWs.onmessage = (e): void => { diff --git a/src/main/utils/init.ts b/src/main/utils/init.ts index 4496656..a39a801 100644 --- a/src/main/utils/init.ts +++ b/src/main/utils/init.ts @@ -192,8 +192,8 @@ async function migration(): Promise { await patchAppConfig({ envType: [envType] }) } // use unix socket - if (process.platform !== 'win32' && externalControllerUnix !== 'mihomo-party.sock') { - await patchControledMihomoConfig({ 'external-controller-unix': 'mihomo-party.sock' }) + if (process.platform !== 'win32' && externalControllerUnix !== '/tmp/mihomo-party.sock') { + await patchControledMihomoConfig({ 'external-controller-unix': '/tmp/mihomo-party.sock' }) } // use named pipe if ( diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index e86eb47..dcf0c4b 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -37,7 +37,7 @@ export const defaultConfig: IAppConfig = { export const defaultControledMihomoConfig: Partial = { 'external-controller-pipe': '\\\\.pipe\\MihomoParty\\mihomo', - 'external-controller-unix': 'mihomo-party.sock', + 'external-controller-unix': '/tmp/mihomo-party.sock', ipv6: true, mode: 'rule', 'mixed-port': 7890,