mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
set sysproxy bypass
This commit is contained in:
parent
95ae550216
commit
ddcb73016e
@ -3,6 +3,7 @@ import { getAppConfig, getControledMihomoConfig } from '../config'
|
||||
import { pacPort } from './server'
|
||||
|
||||
let defaultBypass: string[]
|
||||
|
||||
if (process.platform === 'linux')
|
||||
defaultBypass = ['localhost', '127.0.0.1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12', '::1']
|
||||
if (process.platform === 'darwin')
|
||||
|
||||
@ -4,9 +4,49 @@ import SettingCard from '@renderer/components/base/base-setting-card'
|
||||
import SettingItem from '@renderer/components/base/base-setting-item'
|
||||
import PacEditorViewer from '@renderer/components/sysproxy/pac-editor-modal'
|
||||
import { useAppConfig } from '@renderer/hooks/use-app-config'
|
||||
import { platform } from '@renderer/utils/init'
|
||||
import { triggerSysProxy } from '@renderer/utils/ipc'
|
||||
import { Key, useState } from 'react'
|
||||
import React from 'react'
|
||||
import { MdDeleteForever } from 'react-icons/md'
|
||||
|
||||
const defaultBypass: string[] =
|
||||
platform === 'linux'
|
||||
? ['localhost', '127.0.0.1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12', '::1']
|
||||
: platform === 'darwin'
|
||||
? [
|
||||
'127.0.0.1',
|
||||
'192.168.0.0/16',
|
||||
'10.0.0.0/8',
|
||||
'172.16.0.0/12',
|
||||
'localhost',
|
||||
'*.local',
|
||||
'*.crashlytics.com',
|
||||
'<local>'
|
||||
]
|
||||
: [
|
||||
'localhost',
|
||||
'127.*',
|
||||
'192.168.*',
|
||||
'10.*',
|
||||
'172.16.*',
|
||||
'172.17.*',
|
||||
'172.18.*',
|
||||
'172.19.*',
|
||||
'172.20.*',
|
||||
'172.21.*',
|
||||
'172.22.*',
|
||||
'172.23.*',
|
||||
'172.24.*',
|
||||
'172.25.*',
|
||||
'172.26.*',
|
||||
'172.27.*',
|
||||
'172.28.*',
|
||||
'172.29.*',
|
||||
'172.30.*',
|
||||
'172.31.*',
|
||||
'<local>'
|
||||
]
|
||||
|
||||
const defaultPacScript = `
|
||||
function FindProxyForURL(url, host) {
|
||||
@ -16,10 +56,34 @@ function FindProxyForURL(url, host) {
|
||||
|
||||
const Sysproxy: React.FC = () => {
|
||||
const { appConfig, patchAppConfig } = useAppConfig()
|
||||
const { sysProxy } = appConfig || { sysProxy: { enable: false } }
|
||||
const { sysProxy } = appConfig || ({ sysProxy: { enable: false } } as IAppConfig)
|
||||
|
||||
const [values, setValues] = useState({
|
||||
enable: sysProxy.enable,
|
||||
host: sysProxy.host ?? '',
|
||||
bypass: sysProxy.bypass ?? defaultBypass,
|
||||
mode: sysProxy.mode ?? 'manual',
|
||||
pacScript: sysProxy.pacScript ?? defaultPacScript
|
||||
})
|
||||
|
||||
const [values, setValues] = useState<ISysProxyConfig>(sysProxy)
|
||||
const [openPacEditor, setOpenPacEditor] = useState(false)
|
||||
|
||||
const handleBypassChange = (value: string, index: number): void => {
|
||||
const newBypass = [...values.bypass]
|
||||
if (index === newBypass.length) {
|
||||
if (value.trim() !== '') {
|
||||
newBypass.push(value)
|
||||
}
|
||||
} else {
|
||||
if (value.trim() === '') {
|
||||
newBypass.splice(index, 1)
|
||||
} else {
|
||||
newBypass[index] = value
|
||||
}
|
||||
}
|
||||
setValues({ ...values, bypass: newBypass })
|
||||
}
|
||||
|
||||
const onSave = async (): Promise<void> => {
|
||||
// check valid TODO
|
||||
await patchAppConfig({ sysProxy: values })
|
||||
@ -74,11 +138,53 @@ const Sysproxy: React.FC = () => {
|
||||
<Tab className="select-none" key="auto" title="PAC" />
|
||||
</Tabs>
|
||||
</SettingItem>
|
||||
<SettingItem title="代理模式">
|
||||
<Button size="sm" onPress={() => setOpenPacEditor(true)} variant="bordered">
|
||||
编辑PAC脚本
|
||||
</Button>
|
||||
</SettingItem>
|
||||
|
||||
{values.mode === 'auto' && (
|
||||
<SettingItem title="代理模式">
|
||||
<Button size="sm" onPress={() => setOpenPacEditor(true)} variant="bordered">
|
||||
编辑PAC脚本
|
||||
</Button>
|
||||
</SettingItem>
|
||||
)}
|
||||
{values.mode === 'manual' && (
|
||||
<>
|
||||
<SettingItem title="添加默认代理绕过" divider>
|
||||
<Button
|
||||
size="sm"
|
||||
onPress={() => {
|
||||
setValues({ ...values, bypass: defaultBypass.concat(values.bypass) })
|
||||
}}
|
||||
>
|
||||
添加默认代理绕过
|
||||
</Button>
|
||||
</SettingItem>
|
||||
<div className="flex flex-col items-stretch">
|
||||
<h3 className="select-none mb-2">代理绕过</h3>
|
||||
{[...values.bypass, ''].map((domain, index) => (
|
||||
<div key={index} className="mb-2 flex">
|
||||
<Input
|
||||
fullWidth
|
||||
size="sm"
|
||||
placeholder="例: *.baidu.com"
|
||||
value={domain}
|
||||
onValueChange={(v) => handleBypassChange(v, index)}
|
||||
/>
|
||||
{index < values.bypass.length && (
|
||||
<Button
|
||||
className="ml-2"
|
||||
size="sm"
|
||||
variant="flat"
|
||||
color="warning"
|
||||
onClick={() => handleBypassChange('', index)}
|
||||
>
|
||||
<MdDeleteForever className="text-lg" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</SettingCard>
|
||||
</BasePage>
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user