feature: `MacOS` 也支持系统代理排除域名功能
parent
33ccf67fdb
commit
59aead2ba4
|
@ -181,14 +181,11 @@ function getDomesticDomainAllowList () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _winSetProxy (exec, ip, port, setEnv) {
|
function getProxyExcludeIpStr (split) {
|
||||||
// 延迟加载config
|
|
||||||
loadConfig()
|
|
||||||
|
|
||||||
let excludeIpStr = ''
|
let excludeIpStr = ''
|
||||||
for (const ip in config.get().proxy.excludeIpList) {
|
for (const ip in config.get().proxy.excludeIpList) {
|
||||||
if (config.get().proxy.excludeIpList[ip] === true) {
|
if (config.get().proxy.excludeIpList[ip] === true) {
|
||||||
excludeIpStr += ip + ';'
|
excludeIpStr += ip + split
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +194,7 @@ async function _winSetProxy (exec, ip, port, setEnv) {
|
||||||
try {
|
try {
|
||||||
let domesticDomainAllowList = getDomesticDomainAllowList()
|
let domesticDomainAllowList = getDomesticDomainAllowList()
|
||||||
if (domesticDomainAllowList) {
|
if (domesticDomainAllowList) {
|
||||||
domesticDomainAllowList = (domesticDomainAllowList + '\n').replaceAll(/[\r\n]+/g, '\n').replaceAll(/[^\n]*[^*.a-zA-Z\d-\n]+[^\n]*\r?\n/g, '').replaceAll(/\s*\n+\s*/g, ';')
|
domesticDomainAllowList = (domesticDomainAllowList + '\n').replaceAll(/[\r\n]+/g, '\n').replaceAll(/[^\n]*[^*.a-zA-Z\d-\n]+[^\n]*\r?\n/g, '').trim().replaceAll(/\s*\n+\s*/g, split)
|
||||||
if (domesticDomainAllowList) {
|
if (domesticDomainAllowList) {
|
||||||
excludeIpStr += domesticDomainAllowList
|
excludeIpStr += domesticDomainAllowList
|
||||||
log.info('系统代理排除列表拼接国内域名')
|
log.info('系统代理排除列表拼接国内域名')
|
||||||
|
@ -210,6 +207,15 @@ async function _winSetProxy (exec, ip, port, setEnv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug('系统代理排除域名(excludeIpStr):', excludeIpStr)
|
||||||
|
|
||||||
|
return excludeIpStr
|
||||||
|
}
|
||||||
|
|
||||||
|
async function _winSetProxy (exec, ip, port, setEnv) {
|
||||||
|
// 延迟加载config
|
||||||
|
loadConfig()
|
||||||
|
|
||||||
const proxyPath = extraPath.getProxyExePath()
|
const proxyPath = extraPath.getProxyExePath()
|
||||||
const execFun = 'global'
|
const execFun = 'global'
|
||||||
|
|
||||||
|
@ -220,6 +226,9 @@ async function _winSetProxy (exec, ip, port, setEnv) {
|
||||||
proxyAddr = `http=http://${ip}:${port};` + proxyAddr
|
proxyAddr = `http=http://${ip}:${port};` + proxyAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 读取排除域名
|
||||||
|
const excludeIpStr = getProxyExcludeIpStr(';')
|
||||||
|
// 设置代理,同时设置排除域名
|
||||||
log.info(`执行“设置系统代理”的程序: ${proxyPath} ${execFun} ${proxyAddr} ......(省略排除IP列表)`)
|
log.info(`执行“设置系统代理”的程序: ${proxyPath} ${execFun} ${proxyAddr} ......(省略排除IP列表)`)
|
||||||
await execFile(proxyPath, [execFun, proxyAddr, excludeIpStr])
|
await execFile(proxyPath, [execFun, proxyAddr, excludeIpStr])
|
||||||
|
|
||||||
|
@ -298,14 +307,18 @@ const executor = {
|
||||||
loadConfig()
|
loadConfig()
|
||||||
|
|
||||||
// https
|
// https
|
||||||
await exec(`networksetup -setsecurewebproxy '${wifiAdaptor}' ${ip} ${port}`)
|
await exec(`networksetup -setsecurewebproxy "${wifiAdaptor}" ${ip} ${port}`)
|
||||||
// http
|
// http
|
||||||
if (config.get().proxy.proxyHttp) {
|
if (config.get().proxy.proxyHttp) {
|
||||||
await exec(`networksetup -setwebproxy '${wifiAdaptor}' ${ip} ${port}`)
|
await exec(`networksetup -setwebproxy "${wifiAdaptor}" ${ip} ${port}`)
|
||||||
} else {
|
} else {
|
||||||
await exec(`networksetup -setwebproxystate '${wifiAdaptor}' off`)
|
await exec(`networksetup -setwebproxystate "${wifiAdaptor}" off`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置排除域名
|
||||||
|
const excludeIpStr = getProxyExcludeIpStr('" "')
|
||||||
|
await exec(`networksetup -setproxybypassdomains "${wifiAdaptor}" "${excludeIpStr}"`)
|
||||||
|
|
||||||
// const setEnv = `cat <<ENDOF >> ~/.zshrc
|
// const setEnv = `cat <<ENDOF >> ~/.zshrc
|
||||||
// export http_proxy="http://${ip}:${port}"
|
// export http_proxy="http://${ip}:${port}"
|
||||||
// export https_proxy="http://${ip}:${port}"
|
// export https_proxy="http://${ip}:${port}"
|
||||||
|
@ -315,9 +328,9 @@ const executor = {
|
||||||
// await exec(setEnv)
|
// await exec(setEnv)
|
||||||
} else { // 关闭代理
|
} else { // 关闭代理
|
||||||
// https
|
// https
|
||||||
await exec(`networksetup -setsecurewebproxystate '${wifiAdaptor}' off`)
|
await exec(`networksetup -setsecurewebproxystate "${wifiAdaptor}" off`)
|
||||||
// http
|
// http
|
||||||
await exec(`networksetup -setwebproxystate '${wifiAdaptor}' off`)
|
await exec(`networksetup -setwebproxystate "${wifiAdaptor}" off`)
|
||||||
|
|
||||||
// const removeEnv = `
|
// const removeEnv = `
|
||||||
// sed -ie '/export http_proxy/d' ~/.zshrc
|
// sed -ie '/export http_proxy/d' ~/.zshrc
|
||||||
|
|
|
@ -32,20 +32,22 @@
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<!-- 以下功能仅windows支持,mac和linux暂不支持 -->
|
<!-- 以下功能仅windows支持,mac和linux暂不支持 -->
|
||||||
<div v-if="isWindows()">
|
<a-form-item v-if="isWindows()" label="设置环境变量" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
<a-form-item label="设置环境变量" :label-col="labelCol" :wrapper-col="wrapperCol">
|
<a-checkbox v-model="config.proxy.setEnv" >
|
||||||
<a-checkbox v-model="config.proxy.setEnv" >
|
是否同时修改<code>HTTPS_PROXY</code>环境变量(不好用,不建议勾选)
|
||||||
是否同时修改<code>HTTPS_PROXY</code>环境变量(不好用,不建议勾选)
|
</a-checkbox>
|
||||||
</a-checkbox>
|
<div class="form-help">
|
||||||
<div class="form-help">
|
当发现某些应用并没有走加速通道或加速报错时,可尝试勾选此选项,并重新开启系统代理开关<br/>
|
||||||
当发现某些应用并没有走加速通道或加速报错时,可尝试勾选此选项,并重新开启系统代理开关<br/>
|
注意:当前已打开的命令行并不会实时生效,需要重新打开一个新的命令行窗口
|
||||||
注意:当前已打开的命令行并不会实时生效,需要重新打开一个新的命令行窗口
|
</div>
|
||||||
</div>
|
</a-form-item>
|
||||||
</a-form-item>
|
<a-form-item v-if="isWindows()" label="设置loopback" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
<a-form-item label="设置loopback" :label-col="labelCol" :wrapper-col="wrapperCol">
|
<a-button @click="loopbackVisible=true">去设置</a-button>
|
||||||
<a-button @click="loopbackVisible=true">去设置</a-button>
|
<div class="form-help">解决<code>OneNote</code>、<code>MicrosoftStore</code>、<code>Outlook</code>等<code>UWP应用</code>开启代理后无法访问网络的问题</div>
|
||||||
<div class="form-help">解决<code>OneNote</code>、<code>MicrosoftStore</code>、<code>Outlook</code>等<code>UWP应用</code>开启代理后无法访问网络的问题</div>
|
</a-form-item>
|
||||||
</a-form-item>
|
|
||||||
|
<!-- 以下功能仅windows和macos支持,linux暂不支持 -->
|
||||||
|
<div v-if="isWindows() || isMac()">
|
||||||
<hr/>
|
<hr/>
|
||||||
<a-form-item label="排除国内域名" :label-col="labelCol" :wrapper-col="wrapperCol">
|
<a-form-item label="排除国内域名" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
<a-checkbox v-model="config.proxy.excludeDomesticDomainAllowList" >
|
<a-checkbox v-model="config.proxy.excludeDomesticDomainAllowList" >
|
||||||
|
|
Loading…
Reference in New Issue