mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +08:00
default listen on 127.0.0.1, listen on demand (#304)
Some checks failed
Build / windows (arm64) (push) Has been cancelled
Build / windows (ia32) (push) Has been cancelled
Build / windows (x64) (push) Has been cancelled
Build / windows7 (ia32) (push) Has been cancelled
Build / windows7 (x64) (push) Has been cancelled
Build / linux (arm64) (push) Has been cancelled
Build / linux (x64) (push) Has been cancelled
Build / macos (arm64) (push) Has been cancelled
Build / macos (x64) (push) Has been cancelled
Build / macos10 (arm64) (push) Has been cancelled
Build / macos10 (x64) (push) Has been cancelled
Build / aur-git-updater (push) Has been cancelled
Build / artifact-windows (push) Has been cancelled
Build / artifact-windows7 (push) Has been cancelled
Build / artifact-macos (push) Has been cancelled
Build / artifact-macos10 (push) Has been cancelled
Build / artifact-linux (push) Has been cancelled
Build / updater (push) Has been cancelled
Build / aur-release-updater (mihomo-party) (push) Has been cancelled
Build / aur-release-updater (mihomo-party-bin) (push) Has been cancelled
Build / aur-release-updater (mihomo-party-electron) (push) Has been cancelled
Build / aur-release-updater (mihomo-party-electron-bin) (push) Has been cancelled
Build / Update WinGet Package (push) Has been cancelled
Build / Update Homebrew cask (push) Has been cancelled
Some checks failed
Build / windows (arm64) (push) Has been cancelled
Build / windows (ia32) (push) Has been cancelled
Build / windows (x64) (push) Has been cancelled
Build / windows7 (ia32) (push) Has been cancelled
Build / windows7 (x64) (push) Has been cancelled
Build / linux (arm64) (push) Has been cancelled
Build / linux (x64) (push) Has been cancelled
Build / macos (arm64) (push) Has been cancelled
Build / macos (x64) (push) Has been cancelled
Build / macos10 (arm64) (push) Has been cancelled
Build / macos10 (x64) (push) Has been cancelled
Build / aur-git-updater (push) Has been cancelled
Build / artifact-windows (push) Has been cancelled
Build / artifact-windows7 (push) Has been cancelled
Build / artifact-macos (push) Has been cancelled
Build / artifact-macos10 (push) Has been cancelled
Build / artifact-linux (push) Has been cancelled
Build / updater (push) Has been cancelled
Build / aur-release-updater (mihomo-party) (push) Has been cancelled
Build / aur-release-updater (mihomo-party-bin) (push) Has been cancelled
Build / aur-release-updater (mihomo-party-electron) (push) Has been cancelled
Build / aur-release-updater (mihomo-party-electron-bin) (push) Has been cancelled
Build / Update WinGet Package (push) Has been cancelled
Build / Update Homebrew cask (push) Has been cancelled
This commit is contained in:
parent
f20f15df85
commit
d02421414f
|
@ -41,21 +41,32 @@ export function findAvailablePort(startPort: number): Promise<number> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pacServer: http.Server
|
||||||
|
|
||||||
export async function startPacServer(): Promise<void> {
|
export async function startPacServer(): Promise<void> {
|
||||||
|
await stopPacServer()
|
||||||
|
const { sysProxy } = await getAppConfig()
|
||||||
|
const { mode = 'manual', host: cHost, pacScript } = sysProxy
|
||||||
|
if (mode !== 'auto') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const host = cHost || '127.0.0.1'
|
||||||
|
let script = pacScript || defaultPacScript
|
||||||
|
const { 'mixed-port': port = 7890 } = await getControledMihomoConfig()
|
||||||
|
script = script.replaceAll('%mixed-port%', port.toString())
|
||||||
pacPort = await findAvailablePort(10000)
|
pacPort = await findAvailablePort(10000)
|
||||||
const server = http
|
pacServer = http
|
||||||
.createServer(async (_req, res) => {
|
.createServer(async (_req, res) => {
|
||||||
const {
|
|
||||||
sysProxy: { pacScript }
|
|
||||||
} = await getAppConfig()
|
|
||||||
const { 'mixed-port': port = 7890 } = await getControledMihomoConfig()
|
|
||||||
let script = pacScript || defaultPacScript
|
|
||||||
script = script.replaceAll('%mixed-port%', port.toString())
|
|
||||||
res.writeHead(200, { 'Content-Type': 'application/x-ns-proxy-autoconfig' })
|
res.writeHead(200, { 'Content-Type': 'application/x-ns-proxy-autoconfig' })
|
||||||
res.end(script)
|
res.end(script)
|
||||||
})
|
})
|
||||||
.listen(pacPort)
|
.listen(pacPort, host)
|
||||||
server.unref()
|
}
|
||||||
|
|
||||||
|
export async function stopPacServer(): Promise<void> {
|
||||||
|
if (pacServer) {
|
||||||
|
pacServer.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startSubStoreFrontendServer(): Promise<void> {
|
export async function startSubStoreFrontendServer(): Promise<void> {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { triggerAutoProxy, triggerManualProxy } from '@mihomo-party/sysproxy'
|
import { triggerAutoProxy, triggerManualProxy } from '@mihomo-party/sysproxy'
|
||||||
import { getAppConfig, getControledMihomoConfig } from '../config'
|
import { getAppConfig, getControledMihomoConfig } from '../config'
|
||||||
import { pacPort } from '../resolve/server'
|
import { pacPort, startPacServer, stopPacServer } from '../resolve/server'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import { execFile } from 'child_process'
|
import { execFile } from 'child_process'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
@ -63,6 +63,7 @@ export async function triggerSysProxy(enable: boolean): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function enableSysProxy(): Promise<void> {
|
async function enableSysProxy(): Promise<void> {
|
||||||
|
await startPacServer()
|
||||||
const { sysProxy } = await getAppConfig()
|
const { sysProxy } = await getAppConfig()
|
||||||
const { mode, host, bypass = defaultBypass } = sysProxy
|
const { mode, host, bypass = defaultBypass } = sysProxy
|
||||||
const { 'mixed-port': port = 7890 } = await getControledMihomoConfig()
|
const { 'mixed-port': port = 7890 } = await getControledMihomoConfig()
|
||||||
|
@ -105,6 +106,7 @@ async function enableSysProxy(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function disableSysProxy(): Promise<void> {
|
async function disableSysProxy(): Promise<void> {
|
||||||
|
await stopPacServer()
|
||||||
const execFilePromise = promisify(execFile)
|
const execFilePromise = promisify(execFile)
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -239,11 +239,13 @@ export async function init(): Promise<void> {
|
||||||
await migration()
|
await migration()
|
||||||
await initFiles()
|
await initFiles()
|
||||||
await cleanup()
|
await cleanup()
|
||||||
await startPacServer()
|
|
||||||
await startSubStoreFrontendServer()
|
await startSubStoreFrontendServer()
|
||||||
await startSubStoreBackendServer()
|
await startSubStoreBackendServer()
|
||||||
const { sysProxy } = await getAppConfig()
|
const { sysProxy } = await getAppConfig()
|
||||||
try {
|
try {
|
||||||
|
if (sysProxy.enable) {
|
||||||
|
await startPacServer()
|
||||||
|
}
|
||||||
await triggerSysProxy(sysProxy.enable)
|
await triggerSysProxy(sysProxy.enable)
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Button, Input, Tab, Tabs } from '@nextui-org/react'
|
import { Button, Input, Tab, Tabs, Tooltip } from '@nextui-org/react'
|
||||||
import BasePage from '@renderer/components/base/base-page'
|
import BasePage from '@renderer/components/base/base-page'
|
||||||
import SettingCard from '@renderer/components/base/base-setting-card'
|
import SettingCard from '@renderer/components/base/base-setting-card'
|
||||||
import SettingItem from '@renderer/components/base/base-setting-item'
|
import SettingItem from '@renderer/components/base/base-setting-item'
|
||||||
|
@ -9,6 +9,7 @@ import { openUWPTool, triggerSysProxy } from '@renderer/utils/ipc'
|
||||||
import { Key, useState } from 'react'
|
import { Key, useState } from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { MdDeleteForever } from 'react-icons/md'
|
import { MdDeleteForever } from 'react-icons/md'
|
||||||
|
import { IoIosHelpCircle } from 'react-icons/io'
|
||||||
|
|
||||||
const defaultBypass: string[] =
|
const defaultBypass: string[] =
|
||||||
platform === 'linux'
|
platform === 'linux'
|
||||||
|
@ -135,7 +136,17 @@ const Sysproxy: React.FC = () => {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
<SettingItem title="代理模式" divider>
|
<SettingItem
|
||||||
|
actions={
|
||||||
|
<Tooltip content="PAC监听 代理主机:端口(10000开始的可用)">
|
||||||
|
<Button isIconOnly size="sm" variant="light">
|
||||||
|
<IoIosHelpCircle className="text-lg" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
}
|
||||||
|
title="代理模式"
|
||||||
|
divider
|
||||||
|
>
|
||||||
<Tabs
|
<Tabs
|
||||||
size="sm"
|
size="sm"
|
||||||
color="primary"
|
color="primary"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user