mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
try to fix socket api
This commit is contained in:
parent
e16a12e401
commit
a007434fc5
@ -34,11 +34,11 @@ async function mihomoHttp<T>(method: HttpMethod, path: string, data?: object): P
|
|||||||
const client = net.connect(
|
const client = net.connect(
|
||||||
process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)
|
process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)
|
||||||
)
|
)
|
||||||
client.on('data', function (res) {
|
const parseResult = (str: string): void => {
|
||||||
try {
|
try {
|
||||||
const data = res.toString().split('\r\n\r\n')[1]
|
const data = str.split('\r\n\r\n')[1]
|
||||||
const json = trimJson(data)
|
const json = trimJson(data)
|
||||||
if (res.toString().includes('HTTP/1.1 4') || res.toString().includes('HTTP/1.1 5')) {
|
if (str.includes('HTTP/1.1 4') || str.includes('HTTP/1.1 5')) {
|
||||||
reject(json ? JSON.parse(json) : data)
|
reject(json ? JSON.parse(json) : data)
|
||||||
} else {
|
} else {
|
||||||
resolve(json ? JSON.parse(json) : undefined)
|
resolve(json ? JSON.parse(json) : undefined)
|
||||||
@ -48,6 +48,17 @@ async function mihomoHttp<T>(method: HttpMethod, path: string, data?: object): P
|
|||||||
} finally {
|
} finally {
|
||||||
client.end()
|
client.end()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
let buffer = ''
|
||||||
|
client.on('data', function (res) {
|
||||||
|
if (res.toString().includes('Transfer-Encoding: chunked') || buffer !== '') {
|
||||||
|
buffer += res.toString()
|
||||||
|
if (buffer.endsWith('\r\n\r\n')) {
|
||||||
|
parseResult(buffer)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
parseResult(res.toString())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
client.on('error', function (error) {
|
client.on('error', function (error) {
|
||||||
reject(error)
|
reject(error)
|
||||||
|
|||||||
@ -131,7 +131,12 @@ app.whenReady().then(async () => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
dialog.showErrorBox('内核启动出错', `${e}`)
|
dialog.showErrorBox('内核启动出错', `${e}`)
|
||||||
}
|
}
|
||||||
await startMonitor()
|
try {
|
||||||
|
await startMonitor()
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
// Default open or close DevTools by F12 in development
|
// Default open or close DevTools by F12 in development
|
||||||
// and ignore CommandOrControl + R in production.
|
// and ignore CommandOrControl + R in production.
|
||||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||||
|
|||||||
@ -192,11 +192,14 @@ async function migration(): Promise<void> {
|
|||||||
await patchAppConfig({ envType: [envType] })
|
await patchAppConfig({ envType: [envType] })
|
||||||
}
|
}
|
||||||
// use unix socket
|
// use unix socket
|
||||||
if (process.platform !== 'win32' && !externalControllerUnix) {
|
if (process.platform !== 'win32' && externalControllerUnix !== 'mihomo-party.sock') {
|
||||||
await patchControledMihomoConfig({ 'external-controller-unix': 'mihomo-party.sock' })
|
await patchControledMihomoConfig({ 'external-controller-unix': 'mihomo-party.sock' })
|
||||||
}
|
}
|
||||||
// use named pipe
|
// use named pipe
|
||||||
if (process.platform === 'win32' && !externalControllerPipe) {
|
if (
|
||||||
|
process.platform === 'win32' &&
|
||||||
|
externalControllerPipe !== '\\\\.\\pipe\\MihomoParty\\mihomo'
|
||||||
|
) {
|
||||||
await patchControledMihomoConfig({
|
await patchControledMihomoConfig({
|
||||||
'external-controller-pipe': '\\\\.\\pipe\\MihomoParty\\mihomo'
|
'external-controller-pipe': '\\\\.\\pipe\\MihomoParty\\mihomo'
|
||||||
})
|
})
|
||||||
|
|||||||
@ -41,8 +41,8 @@ const Proxies: React.FC = () => {
|
|||||||
if (groups.length !== searchValue.length) setSearchValue(Array(groups.length).fill(''))
|
if (groups.length !== searchValue.length) setSearchValue(Array(groups.length).fill(''))
|
||||||
groups.forEach((group, index) => {
|
groups.forEach((group, index) => {
|
||||||
if (isOpen[index]) {
|
if (isOpen[index]) {
|
||||||
let groupProxies = group.all.filter((proxy) =>
|
let groupProxies = group.all.filter(
|
||||||
includesIgnoreCase(proxy.name, searchValue[index])
|
(proxy) => proxy && includesIgnoreCase(proxy.name, searchValue[index])
|
||||||
)
|
)
|
||||||
const count = Math.floor(groupProxies.length / cols)
|
const count = Math.floor(groupProxies.length / cols)
|
||||||
groupCounts.push(groupProxies.length % cols === 0 ? count : count + 1)
|
groupCounts.push(groupProxies.length % cols === 0 ? count : count + 1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user