feature: `Git.exe` 代理,添加 `是否代理HTTP请求` 的配置项 (#349)

pull/350/head
王良 2024-09-10 16:55:22 +08:00 committed by GitHub
parent 6c4f108d76
commit 4065acb686
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 46 additions and 15 deletions

View File

@ -3,6 +3,7 @@ module.exports = {
enabled: false, enabled: false,
tip: '如果你没有安装git命令行则不需要启动它', tip: '如果你没有安装git命令行则不需要启动它',
setting: { setting: {
sslVerify: true // 是否关闭sslVerify proxyHttp: false, // Git.exe 是否代理HTTP请求
sslVerify: true // Git.exe 是否关闭sslVerifytrue=关闭 false=开启
} }
} }

View File

@ -23,15 +23,28 @@ const Plugin = function (context) {
}, },
async setProxy (ip, port) { async setProxy (ip, port) {
const cmds = [ // 代理https
`git config --global http.proxy http://${ip}:${port} `, const ret = await shell.exec([`git config --global https.proxy http://${ip}:${port} `], { type: 'cmd' })
`git config --global https.proxy http://${ip}:${port} `
] try {
if (config.get().plugin.git.setting.sslVerify === true) { if (config.get().plugin.git.setting.proxyHttp === true) {
cmds.push('git config --global http.sslVerify false ') // 代理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 }) event.fire('status', { key: 'plugin.git.enabled', value: true })
log.info('开启【Git】代理成功') log.info('开启【Git】代理成功')
@ -39,14 +52,23 @@ const Plugin = function (context) {
}, },
async unsetProxy () { async unsetProxy () {
const cmds = [ // 取消代理https
'git config --global --unset https.proxy ', const ret = await shell.exec(['git config --global --unset https.proxy '], { type: 'cmd' })
'git config --global --unset http.proxy '
] // 尝试取消代理http
if (config.get().plugin.git.setting.sslVerify === true) { try {
cmds.push('git config --global http.sslVerify true ') 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 }) event.fire('status', { key: 'plugin.git.enabled', value: false })
log.info('关闭【Git】代理成功') log.info('关闭【Git】代理成功')
return ret return ret

View File

@ -20,6 +20,14 @@
当前未启动 当前未启动
</a-tag> </a-tag>
</a-form-item> </a-form-item>
<a-form-item label="代理HTTP请求" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.plugin.git.setting.proxyHttp">
是否代理HTTP请求
</a-checkbox>
<div class="form-help">
勾选时同时代理HTTP和HTTPS请求不勾选时只代理HTTPS请求
</div>
</a-form-item>
<a-form-item label="SSL校验" :label-col="labelCol" :wrapper-col="wrapperCol"> <a-form-item label="SSL校验" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.plugin.git.setting.sslVerify"> <a-checkbox v-model="config.plugin.git.setting.sslVerify">
关闭sslVerify 关闭sslVerify