mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-23 01:33:48 +08:00
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:
parent
87b74db9fc
commit
d44fa1775c
@ -94,17 +94,14 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
|||||||
let proxyConfig: ProxyConfig
|
let proxyConfig: ProxyConfig
|
||||||
|
|
||||||
if (proxy === 'system') {
|
if (proxy === 'system') {
|
||||||
|
// system proxy will use the system filter by themselves
|
||||||
proxyConfig = { mode: 'system' }
|
proxyConfig = { mode: 'system' }
|
||||||
} else if (proxy) {
|
} else if (proxy) {
|
||||||
proxyConfig = { mode: 'fixed_servers', proxyRules: proxy }
|
proxyConfig = { mode: 'fixed_servers', proxyRules: proxy, proxyBypassRules: bypassRules }
|
||||||
} else {
|
} else {
|
||||||
proxyConfig = { mode: 'direct' }
|
proxyConfig = { mode: 'direct' }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bypassRules) {
|
|
||||||
proxyConfig.proxyBypassRules = bypassRules
|
|
||||||
}
|
|
||||||
|
|
||||||
await proxyManager.configureProxy(proxyConfig)
|
await proxyManager.configureProxy(proxyConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { loggerService } from '@logger'
|
import { loggerService } from '@logger'
|
||||||
import { defaultByPassRules } from '@shared/config/constant'
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { app, ProxyConfig, session } from 'electron'
|
import { app, ProxyConfig, session } from 'electron'
|
||||||
import { socksDispatcher } from 'fetch-socks'
|
import { socksDispatcher } from 'fetch-socks'
|
||||||
@ -10,9 +9,13 @@ import { ProxyAgent } from 'proxy-agent'
|
|||||||
import { Dispatcher, EnvHttpProxyAgent, getGlobalDispatcher, setGlobalDispatcher } from 'undici'
|
import { Dispatcher, EnvHttpProxyAgent, getGlobalDispatcher, setGlobalDispatcher } from 'undici'
|
||||||
|
|
||||||
const logger = loggerService.withContext('ProxyManager')
|
const logger = loggerService.withContext('ProxyManager')
|
||||||
let byPassRules = defaultByPassRules.split(',')
|
let byPassRules: string[] = []
|
||||||
|
|
||||||
const isByPass = (hostname: string) => {
|
const isByPass = (hostname: string) => {
|
||||||
|
if (byPassRules.length === 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return byPassRules.includes(hostname)
|
return byPassRules.includes(hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +101,7 @@ export class ProxyManager {
|
|||||||
await this.configureProxy({
|
await this.configureProxy({
|
||||||
mode: 'system',
|
mode: 'system',
|
||||||
proxyRules: currentProxy?.proxyUrl.toLowerCase(),
|
proxyRules: currentProxy?.proxyUrl.toLowerCase(),
|
||||||
proxyBypassRules: this.config.proxyBypassRules
|
proxyBypassRules: undefined
|
||||||
})
|
})
|
||||||
}, 1000 * 60)
|
}, 1000 * 60)
|
||||||
}
|
}
|
||||||
@ -131,7 +134,7 @@ export class ProxyManager {
|
|||||||
this.monitorSystemProxy()
|
this.monitorSystemProxy()
|
||||||
}
|
}
|
||||||
|
|
||||||
byPassRules = config.proxyBypassRules?.split(',') || defaultByPassRules.split(',')
|
byPassRules = config.proxyBypassRules?.split(',') || []
|
||||||
this.setGlobalProxy(this.config)
|
this.setGlobalProxy(this.config)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to config proxy:', error as Error)
|
logger.error('Failed to config proxy:', error as Error)
|
||||||
|
|||||||
@ -229,7 +229,7 @@ const GeneralSettings: FC = () => {
|
|||||||
</SettingRow>
|
</SettingRow>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{(storeProxyMode === 'custom' || storeProxyMode === 'system') && (
|
{storeProxyMode === 'custom' && (
|
||||||
<>
|
<>
|
||||||
<SettingDivider />
|
<SettingDivider />
|
||||||
<SettingRow>
|
<SettingRow>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user