refactor(ProxyManager): don't filter proxy in system proxy (#8919)

refactor(ProxyManager): streamline proxy configuration and bypass rules handling

- Simplified proxy configuration logic in registerIpc by directly assigning bypass rules.
- Removed redundant bypass rules assignment in ProxyManager, initializing it as an empty array.
- Updated GeneralSettings to conditionally render based on custom proxy mode only.
This commit is contained in:
beyondkmp 2025-08-07 15:18:53 +08:00 committed by GitHub
parent 87b74db9fc
commit d44fa1775c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 10 deletions

View File

@ -94,17 +94,14 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
let proxyConfig: ProxyConfig
if (proxy === 'system') {
// system proxy will use the system filter by themselves
proxyConfig = { mode: 'system' }
} else if (proxy) {
proxyConfig = { mode: 'fixed_servers', proxyRules: proxy }
proxyConfig = { mode: 'fixed_servers', proxyRules: proxy, proxyBypassRules: bypassRules }
} else {
proxyConfig = { mode: 'direct' }
}
if (bypassRules) {
proxyConfig.proxyBypassRules = bypassRules
}
await proxyManager.configureProxy(proxyConfig)
})

View File

@ -1,5 +1,4 @@
import { loggerService } from '@logger'
import { defaultByPassRules } from '@shared/config/constant'
import axios from 'axios'
import { app, ProxyConfig, session } from 'electron'
import { socksDispatcher } from 'fetch-socks'
@ -10,9 +9,13 @@ import { ProxyAgent } from 'proxy-agent'
import { Dispatcher, EnvHttpProxyAgent, getGlobalDispatcher, setGlobalDispatcher } from 'undici'
const logger = loggerService.withContext('ProxyManager')
let byPassRules = defaultByPassRules.split(',')
let byPassRules: string[] = []
const isByPass = (hostname: string) => {
if (byPassRules.length === 0) {
return false
}
return byPassRules.includes(hostname)
}
@ -98,7 +101,7 @@ export class ProxyManager {
await this.configureProxy({
mode: 'system',
proxyRules: currentProxy?.proxyUrl.toLowerCase(),
proxyBypassRules: this.config.proxyBypassRules
proxyBypassRules: undefined
})
}, 1000 * 60)
}
@ -131,7 +134,7 @@ export class ProxyManager {
this.monitorSystemProxy()
}
byPassRules = config.proxyBypassRules?.split(',') || defaultByPassRules.split(',')
byPassRules = config.proxyBypassRules?.split(',') || []
this.setGlobalProxy(this.config)
} catch (error) {
logger.error('Failed to config proxy:', error as Error)

View File

@ -229,7 +229,7 @@ const GeneralSettings: FC = () => {
</SettingRow>
</>
)}
{(storeProxyMode === 'custom' || storeProxyMode === 'system') && (
{storeProxyMode === 'custom' && (
<>
<SettingDivider />
<SettingRow>