Skip to content

Commit

Permalink
set sysproxy bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 7, 2024
1 parent 95ae550 commit 71ebb00
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/main/resolve/sysproxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export function triggerSysProxy(enable: boolean): void {

export function enableSysProxy(): void {
const { sysProxy } = getAppConfig()
const { mode, host, bypass = defaultBypass } = sysProxy
const { mode, host, bypass = [], useDefaultBypass } = sysProxy
if (useDefaultBypass) bypass.unshift(...defaultBypass)
const { 'mixed-port': port = 7890 } = getControledMihomoConfig()

switch (mode || 'manual') {
Expand Down
83 changes: 75 additions & 8 deletions src/renderer/src/pages/syspeoxy.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Input, Tab, Tabs } from '@nextui-org/react'
import { Button, Input, Switch, Tab, Tabs } from '@nextui-org/react'
import BasePage from '@renderer/components/base/base-page'
import SettingCard from '@renderer/components/base/base-setting-card'
import SettingItem from '@renderer/components/base/base-setting-item'
Expand All @@ -7,6 +7,7 @@ import { useAppConfig } from '@renderer/hooks/use-app-config'
import { triggerSysProxy } from '@renderer/utils/ipc'
import { Key, useState } from 'react'
import React from 'react'
import { MdDeleteForever } from 'react-icons/md'

const defaultPacScript = `
function FindProxyForURL(url, host) {
Expand All @@ -16,10 +17,35 @@ 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 ?? '',
useDefaultBypass: sysProxy.useDefaultBypass ?? true,
bypass: sysProxy.bypass ?? [],
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 })
Expand Down Expand Up @@ -74,11 +100,52 @@ 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>
<Switch
size="sm"
isSelected={values.useDefaultBypass}
onValueChange={(v) => {
setValues({ ...values, useDefaultBypass: v })
}}
/>
</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>
)
Expand Down
1 change: 1 addition & 0 deletions src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ interface ISysProxyConfig {
enable: boolean
host?: string
mode?: SysProxyMode
useDefaultBypass?: boolean
bypass?: string[]
pacScript?: string
}
Expand Down

0 comments on commit 71ebb00

Please sign in to comment.