From 6612f4d6503d9f7132eb3352a7889dfc119f8156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Fri, 27 Sep 2024 15:08:40 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20windows=E7=B3=BB=E7=BB=9F=E4=B8=8B?= =?UTF-8?q?=EF=BC=8C=E5=BC=80=E5=90=AF=E4=BB=A3=E7=90=86=E6=97=B6=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E9=85=8D=E7=BD=AE=E5=90=8C=E6=97=B6=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=20`HTTP=5FPROXY`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shell/scripts/set-system-proxy/index.js | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/core/src/shell/scripts/set-system-proxy/index.js b/packages/core/src/shell/scripts/set-system-proxy/index.js index f6a19819..09edddf0 100644 --- a/packages/core/src/shell/scripts/set-system-proxy/index.js +++ b/packages/core/src/shell/scripts/set-system-proxy/index.js @@ -22,7 +22,7 @@ async function _winUnsetProxy (exec, setEnv) { await execFile(proxyPath, ['set', '1']) try { - await exec('echo \'test\'') + await exec('echo \'删除环境变量 HTTPS_PROXY、HTTP_PROXY\'') const regKey = new Registry({ // new operator is optional hive: Registry.HKCU, // open registry hive HKEY_CURRENT_USER key: '\\Environment' // key containing autostart programs @@ -30,13 +30,20 @@ async function _winUnsetProxy (exec, setEnv) { regKey.get('HTTPS_PROXY', (err) => { if (!err) { regKey.remove('HTTPS_PROXY', async (err) => { - log.warn('删除环境变量https_proxy失败:', err) + log.warn('删除环境变量 HTTPS_PROXY 失败:', err) await exec('setx DS_REFRESH "1"') }) } }) + regKey.get('HTTP_PROXY', (err) => { + if (!err) { + regKey.remove('HTTP_PROXY', async (err) => { + log.warn('删除环境变量 HTTP_PROXY 失败:', err) + }) + } + }) } catch (e) { - log.error('关闭系统代理失败:', e) + log.error('删除环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e) } } @@ -65,14 +72,19 @@ async function _winSetProxy (exec, ip, port, setEnv) { await execFile(proxyPath, [execFun, proxyAddr, excludeIpStr]) if (setEnv) { - log.info('同时设置 https_proxy') + log.info(`开启系统代理的同时设置环境变量:HTTPS_PROXY = "http://${ip}:${port}/"`) + if (config.get().proxy.proxyHttp) { + log.info(`开启系统代理的同时设置环境变量:HTTP_PROXY = "http://${ip}:${port}/"`) + } try { - await exec('echo \'test\'') - await exec('echo \'test\'') + await exec('echo \'设置环境变量 HTTPS_PROXY、HTTP_PROXY\'') await exec(`setx HTTPS_PROXY "http://${ip}:${port}/"`) + if (config.get().proxy.proxyHttp) { + await exec(`setx HTTP_PROXY "http://${ip}:${port}/"`) + } // await addClearScriptIni() } catch (e) { - log.error(e) + log.error('设置环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e) } }