From 4065acb686cbc62ff6130182da6b168a6926c791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Tue, 10 Sep 2024 16:55:22 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20`Git.exe`=20=E4=BB=A3=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=20`=E6=98=AF=E5=90=A6=E4=BB=A3?= =?UTF-8?q?=E7=90=86HTTP=E8=AF=B7=E6=B1=82`=20=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/src/modules/plugin/git/config.js | 3 +- packages/core/src/modules/plugin/git/index.js | 50 +++++++++++++------ packages/gui/src/view/pages/plugin/git.vue | 8 +++ 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/packages/core/src/modules/plugin/git/config.js b/packages/core/src/modules/plugin/git/config.js index e80e7d90..501149a7 100644 --- a/packages/core/src/modules/plugin/git/config.js +++ b/packages/core/src/modules/plugin/git/config.js @@ -3,6 +3,7 @@ module.exports = { enabled: false, tip: '如果你没有安装git命令行则不需要启动它', setting: { - sslVerify: true // 是否关闭sslVerify + proxyHttp: false, // Git.exe 是否代理HTTP请求 + sslVerify: true // Git.exe 是否关闭sslVerify,true=关闭 false=开启 } } diff --git a/packages/core/src/modules/plugin/git/index.js b/packages/core/src/modules/plugin/git/index.js index 4794ad3d..12a13d89 100644 --- a/packages/core/src/modules/plugin/git/index.js +++ b/packages/core/src/modules/plugin/git/index.js @@ -23,15 +23,28 @@ const Plugin = function (context) { }, async setProxy (ip, port) { - const cmds = [ - `git config --global http.proxy http://${ip}:${port} `, - `git config --global https.proxy http://${ip}:${port} ` - ] - if (config.get().plugin.git.setting.sslVerify === true) { - cmds.push('git config --global http.sslVerify false ') + // 代理https + const ret = await shell.exec([`git config --global https.proxy http://${ip}:${port} `], { type: 'cmd' }) + + try { + if (config.get().plugin.git.setting.proxyHttp === true) { + // 代理http + await shell.exec([`git config --global http.proxy http://${ip}:${port} `], { type: 'cmd', printErrorLog: false }) + } else { + // 尝试取消代理http + await shell.exec(['git config --global --unset http.proxy '], { type: 'cmd', printErrorLog: false }) + } + } catch (ignore) { + } + + // 恢复ssl验证 + if (config.get().plugin.git.setting.sslVerify === true) { + try { + await shell.exec(['git config --global http.sslVerify false '], { type: 'cmd', printErrorLog: false }) + } catch (ignore) { + } } - const ret = await shell.exec(cmds, { type: 'cmd' }) event.fire('status', { key: 'plugin.git.enabled', value: true }) log.info('开启【Git】代理成功') @@ -39,14 +52,23 @@ const Plugin = function (context) { }, async unsetProxy () { - const cmds = [ - 'git config --global --unset https.proxy ', - 'git config --global --unset http.proxy ' - ] - if (config.get().plugin.git.setting.sslVerify === true) { - cmds.push('git config --global http.sslVerify true ') + // 取消代理https + const ret = await shell.exec(['git config --global --unset https.proxy '], { type: 'cmd' }) + + // 尝试取消代理http + try { + await shell.exec(['git config --global --unset http.proxy '], { type: 'cmd', printErrorLog: false }) + } catch (ignore) { } - const ret = await shell.exec(cmds, { type: 'cmd' }) + + // 恢复ssl验证 + if (config.get().plugin.git.setting.sslVerify === true) { + try { + await shell.exec(['git config --global http.sslVerify true '], { type: 'cmd', printErrorLog: false }) + } catch (ignore) { + } + } + event.fire('status', { key: 'plugin.git.enabled', value: false }) log.info('关闭【Git】代理成功') return ret diff --git a/packages/gui/src/view/pages/plugin/git.vue b/packages/gui/src/view/pages/plugin/git.vue index e3f9552f..32232327 100644 --- a/packages/gui/src/view/pages/plugin/git.vue +++ b/packages/gui/src/view/pages/plugin/git.vue @@ -20,6 +20,14 @@ 当前未启动 + + + 是否代理HTTP请求 + + + 勾选时,同时代理HTTP和HTTPS请求;不勾选时,只代理HTTPS请求 + + 关闭sslVerify