From e6ef700dabf78b25223d33e7bf604b36be4fc798 Mon Sep 17 00:00:00 2001 From: 18603046467 Date: Sat, 20 Nov 2021 13:53:00 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20pip=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- packages/core/src/config/index.js | 10 +- packages/core/src/expose.js | 1 - packages/core/src/modules/plugin/index.js | 3 +- .../core/src/modules/plugin/pip/config.js | 12 +++ packages/core/src/modules/plugin/pip/index.js | 93 ++++++++++++++++++ packages/core/src/modules/proxy/index.js | 18 +++- .../shell/scripts/set-system-proxy/index.js | 55 +++++++---- packages/core/yarn.lock | 52 +++++++++- packages/gui/src/background.js | 1 + packages/gui/src/view/pages/index.vue | 48 ++++----- packages/gui/src/view/pages/plugin/node.vue | 14 +-- packages/gui/src/view/pages/plugin/pip.vue | 98 +++++++++++++++++++ packages/gui/src/view/pages/proxy.vue | 16 ++- packages/gui/src/view/pages/server.vue | 2 +- packages/gui/src/view/router/index.js | 2 + packages/gui/src/view/router/menu.js | 3 +- 17 files changed, 364 insertions(+), 67 deletions(-) create mode 100644 packages/core/src/modules/plugin/pip/config.js create mode 100644 packages/core/src/modules/plugin/pip/index.js create mode 100644 packages/gui/src/view/pages/plugin/pip.vue diff --git a/package.json b/package.json index 29e44cc..5b93967 100644 --- a/package.json +++ b/package.json @@ -6,5 +6,6 @@ "devDependencies": { "lerna": "^3.22.1" }, - "dependencies": {} + "dependencies": { + } } diff --git a/packages/core/src/config/index.js b/packages/core/src/config/index.js index b7ba710..788d2cf 100644 --- a/packages/core/src/config/index.js +++ b/packages/core/src/config/index.js @@ -80,7 +80,11 @@ module.exports = { }, 'github.githubassets.com': { '.*': { - proxy: 'assets.fastgit.org' + proxy: 'github.githubassets.com', + backup: [ + 'assets.fastgit.org' + ], + sni: 'assets.fastgit.org' } }, 'customer-stories-feed.github.com': { @@ -237,8 +241,8 @@ module.exports = { '*.vuepress.vuejs.org': 'quad9', 'gh.docmirror.top': 'quad9', '*v2ex.com': 'quad9', - '*pypi.org':'quad9', - '*jetbrains.com':'quad9' + '*pypi.org': 'quad9', + '*jetbrains.com': 'quad9' }, speedTest: { enabled: true, diff --git a/packages/core/src/expose.js b/packages/core/src/expose.js index 31905bb..5020bb0 100644 --- a/packages/core/src/expose.js +++ b/packages/core/src/expose.js @@ -22,7 +22,6 @@ function setupPlugin (key, plugin, context, config) { if (pluginStatus) { lodash.set(status, key, pluginStatus) } - return api } diff --git a/packages/core/src/modules/plugin/index.js b/packages/core/src/modules/plugin/index.js index 06fcf96..3b1058e 100644 --- a/packages/core/src/modules/plugin/index.js +++ b/packages/core/src/modules/plugin/index.js @@ -1,7 +1,8 @@ const node = require('./node') const git = require('./git') const overwall = require('./overwall') +const pip = require('./pip') module.exports = { - node, git, overwall + node, git, pip, overwall } diff --git a/packages/core/src/modules/plugin/pip/config.js b/packages/core/src/modules/plugin/pip/config.js new file mode 100644 index 0000000..686548b --- /dev/null +++ b/packages/core/src/modules/plugin/pip/config.js @@ -0,0 +1,12 @@ +module.exports = { + name: 'PIP加速', + statusOff: true, + enabled: null, // 没有开关 + tip: '如果你没有安装pip则不需要启动它', + startup: { + }, + setting: { + trustedHost: 'pypi.org', + registry: ''// 可以选择切换官方或者淘宝镜像 + } +} diff --git a/packages/core/src/modules/plugin/pip/index.js b/packages/core/src/modules/plugin/pip/index.js new file mode 100644 index 0000000..4a06f82 --- /dev/null +++ b/packages/core/src/modules/plugin/pip/index.js @@ -0,0 +1,93 @@ +const pipConfig = require('./config') +const PipPlugin = function (context) { + const { config, shell, event, log } = context + const api = { + async start () { + await api.setRegistry({ registry: config.get().plugin.pip.setting.registry }) + await api.setTrustedHost(config.get().plugin.pip.setting.trustedHost) + }, + + async close () { + }, + + async restart () { + await api.close() + await api.start() + }, + + async save (newConfig) { + await api.setVariables() + }, + async getPipEnv () { + let ret = await shell.exec(['pip config list'], { type: 'cmd' }) + if (ret != null) { + ret = ret.trim() + const lines = ret.split('\n') + const vars = {} + for (const line of lines) { + if (!line.startsWith('global')) { + continue + } + const key = line.substring(0, line.indexOf('=')) + let value = line.substring(line.indexOf('=') + 1) + if (value.startsWith('\'')) { + value = value.startsWith(1, value.length - 1) + } + vars[key] = value + } + return vars + } + return {} + }, + + async setPipEnv (list) { + const cmds = [] + for (const item of list) { + if (item.value != null) { + cmds.push(`pip config set global.${item.key} ${item.value}`) + } else { + cmds.push(`pip config unset global.${item.key}`) + } + } + const ret = await shell.exec(cmds, { type: 'cmd' }) + return ret + }, + + async unsetPipEnv (list) { + const cmds = [] + for (const item of list) { + cmds.push(`pip config unset global.${item} `) + } + const ret = await shell.exec(cmds, { type: 'cmd' }) + return ret + }, + + async setRegistry ({ registry }) { + await api.setPipEnv([{ key: 'index-url', value: registry }]) + return true + }, + + async setTrustedHost (host) { + await api.setPipEnv([{ key: 'trusted-host', value: host }]) + return true + }, + + async setProxy (ip, port) { + + }, + + async unsetProxy () { + + } + } + return api +} + +module.exports = { + key: 'pip', + config: pipConfig, + status: { + enabled: false + }, + plugin: PipPlugin +} diff --git a/packages/core/src/modules/proxy/index.js b/packages/core/src/modules/proxy/index.js index 3bc05e0..11c9914 100644 --- a/packages/core/src/modules/proxy/index.js +++ b/packages/core/src/modules/proxy/index.js @@ -9,18 +9,27 @@ const ProxyPlugin = function (context) { return api.unsetProxy() }, + async restart () { + await api.close() + await api.start() + }, + async setProxy () { const ip = '127.0.0.1' const port = config.get().server.port - await shell.setSystemProxy({ ip, port }) + const setEnv = config.get().proxy.setEnv + await shell.setSystemProxy({ ip, port, setEnv }) log.info(`开启系统代理成功:${ip}:${port}`) event.fire('status', { key: 'proxy.enabled', value: true }) return { ip, port } }, - async unsetProxy () { + async unsetProxy (setEnv) { + if (setEnv) { + setEnv = config.get().proxy.setEnv + } try { - await shell.setSystemProxy() + await shell.setSystemProxy({ setEnv }) event.fire('status', { key: 'proxy.enabled', value: false }) log.info('关闭系统代理成功') return true @@ -44,7 +53,8 @@ module.exports = { enabled: true, name: '系统代理', use: 'local', - other: [] + other: [], + setEnv: false }, status: { enabled: false, 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 a00713d..bccde64 100644 --- a/packages/core/src/shell/scripts/set-system-proxy/index.js +++ b/packages/core/src/shell/scripts/set-system-proxy/index.js @@ -2,9 +2,10 @@ * 获取环境变量 */ const Shell = require('../../shell') +const Registry = require('winreg') + const execute = Shell.execute const execFile = Shell.execFile -const Registry = require('winreg') const refreshInternetPs = require('./refresh-internet') const PowerShell = require('node-powershell') const log = require('../../../utils/util.log') @@ -38,49 +39,64 @@ const _lanIP = [ '<-loopback>' ] -async function _winUnsetProxy (exec) { +async function _winUnsetProxy (exec, setEnv) { // eslint-disable-next-line no-constant-condition const proxyPath = extraPath.getProxyExePath() await execFile(proxyPath, ['set', '1']) + try { - // await removeClearScriptIni() + await exec('echo \'test\'') + const regKey = new Registry({ // new operator is optional + hive: Registry.HKCU, // open registry hive HKEY_CURRENT_USER + key: '\\Environment' // key containing autostart programs + }) + regKey.remove('HTTPS_PROXY', async (err) => { + log.info('删除环境变量https_proxy', err) + await exec('setx DS_REFRESH "1"') + }) } catch (e) { log.error(e) } } -async function _winSetProxy (exec, ip, port) { +async function _winSetProxy (exec, ip, port, setEnv) { let lanIpStr = '' for (const string of _lanIP) { lanIpStr += string + ';' } const proxyPath = extraPath.getProxyExePath() await execFile(proxyPath, ['global', `${ip}:${port}`, lanIpStr]) - try { - // await addClearScriptIni() - } catch (e) { - log.error(e) + + if (setEnv == null) { + try { + await exec('echo \'test\'') + await exec(`setx HTTPS_PROXY "http://${ip}:${port}/"`) + // await addClearScriptIni() + } catch (e) { + log.error(e) + } } return true } const executor = { - async windows (exec, params) { - if (params == null) { + async windows (exec, params = {}) { + const { ip, port, setEnv } = params + if (ip == null) { // 清空代理 log.info('关闭代理') - return _winUnsetProxy(exec) + return _winUnsetProxy(exec, setEnv) } else { // 设置代理 - const { ip, port } = params + log.info('设置代理', ip, port) - return _winSetProxy(exec, ip, port) + return _winSetProxy(exec, ip, port, setEnv) } }, - async linux (exec, params) { - if (params != null) { - const { ip, port } = params + async linux (exec, params = {}) { + const { ip, port } = params + if (ip != null) { // const local = 'localhost, 127.0.0.0/8, ::1' const setProxyCmd = [ @@ -100,13 +116,13 @@ const executor = { await exec(setProxyCmd) } }, - async mac (exec, params) { + async mac (exec, params = {}) { // exec = _exec let wifiAdaptor = await exec('sh -c "networksetup -listnetworkserviceorder | grep `route -n get 0.0.0.0 | grep \'interface\' | cut -d \':\' -f2` -B 1 | head -n 1 "') wifiAdaptor = wifiAdaptor.trim() wifiAdaptor = wifiAdaptor.substring(wifiAdaptor.indexOf(' ')).trim() - - if (params == null) { + const { ip, port } = params + if (ip == null) { await exec(`networksetup -setwebproxystate '${wifiAdaptor}' off`) await exec(`networksetup -setsecurewebproxystate '${wifiAdaptor}' off`) @@ -117,7 +133,6 @@ const executor = { // ` // await exec(removeEnv) } else { - const { ip, port } = params await exec(`networksetup -setwebproxy '${wifiAdaptor}' ${ip} ${port}`) await exec(`networksetup -setsecurewebproxy '${wifiAdaptor}' ${ip} ${port}`) diff --git a/packages/core/yarn.lock b/packages/core/yarn.lock index 8167af4..508d373 100644 --- a/packages/core/yarn.lock +++ b/packages/core/yarn.lock @@ -2637,6 +2637,11 @@ ieee754@^1.1.4: resolved "https://registry.npm.taobao.org/ieee754/download/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84" integrity sha1-7BaFWOlaoYH9h9N/VcMrvLZwi4Q= +if-async@^3.7.4: + version "3.7.4" + resolved "https://registry.yarnpkg.com/if-async/-/if-async-3.7.4.tgz#55868deb0093d3c67bf7166e745353fb9bcb21a2" + integrity sha1-VYaN6wCT08Z79xZudFNT+5vLIaI= + iferr@^0.1.5: version "0.1.5" resolved "https://registry.npm.taobao.org/iferr/download/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501" @@ -2950,6 +2955,11 @@ is-wsl@^1.1.0: resolved "https://registry.npm.taobao.org/is-wsl/download/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d" integrity sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0= +isarray@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" + integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= + isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" @@ -4154,6 +4164,16 @@ read-pkg@^5.1.1: string_decoder "~1.1.1" util-deprecate "~1.0.1" +"readable-stream@>=1.0.33-1 <1.1.0-0": + version "1.0.34" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c" + integrity sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw= + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + readable-stream@^3.6.0: version "3.6.0" resolved "https://registry.npm.taobao.org/readable-stream/download/readable-stream-3.6.0.tgz?cache=0&sync_timestamp=1589682741447&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Freadable-stream%2Fdownload%2Freadable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" @@ -4179,6 +4199,16 @@ readdirp@~3.5.0: dependencies: picomatch "^2.2.1" +regedit@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/regedit/-/regedit-5.0.0.tgz#7ec444ef027cc704e104fae00586f84752291116" + integrity sha512-4uSqj6Injwy5TPtXlE+1F/v2lOW/bMfCqNIAXyib4aG1ZwacG69oyK/yb6EF8KQRMhz7YINxkD+/HHc6i7YJtA== + dependencies: + debug "^4.1.0" + if-async "^3.7.4" + stream-slicer "0.0.6" + through2 "^0.6.3" + regenerator-runtime@^0.11.0: version "0.11.1" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" @@ -4655,6 +4685,11 @@ stream-shift@^1.0.0: resolved "https://registry.npm.taobao.org/stream-shift/download/stream-shift-1.0.1.tgz#d7088281559ab2778424279b0877da3c392d5a3d" integrity sha1-1wiCgVWasneEJCebCHfaPDktWj0= +stream-slicer@0.0.6: + version "0.0.6" + resolved "https://registry.yarnpkg.com/stream-slicer/-/stream-slicer-0.0.6.tgz#f86b2ac5c2440b7a0a87b71f33665c0788046138" + integrity sha1-+GsqxcJEC3oKh7cfM2ZcB4gEYTg= + stream-throttle@^0.1.3: version "0.1.3" resolved "https://registry.npmjs.org/stream-throttle/-/stream-throttle-0.1.3.tgz#add57c8d7cc73a81630d31cd55d3961cfafba9c3" @@ -4721,6 +4756,11 @@ string_decoder@^1.0.0, string_decoder@^1.1.1: dependencies: safe-buffer "~5.2.0" +string_decoder@~0.10.x: + version "0.10.31" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + integrity sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ= + string_decoder@~1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" @@ -4844,6 +4884,14 @@ text-table@^0.2.0: resolved "https://registry.npm.taobao.org/text-table/download/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= +through2@^0.6.3: + version "0.6.5" + resolved "https://registry.yarnpkg.com/through2/-/through2-0.6.5.tgz#41ab9c67b29d57209071410e1d7a7a968cd3ad48" + integrity sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg= + dependencies: + readable-stream ">=1.0.33-1 <1.1.0-0" + xtend ">=4.0.0 <4.1.0-0" + through2@^2.0.0, through2@^2.0.1: version "2.0.5" resolved "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd" @@ -5249,7 +5297,7 @@ wide-align@1.1.3: winreg@^1.2.4: version "1.2.4" - resolved "https://registry.npm.taobao.org/winreg/download/winreg-1.2.4.tgz#ba065629b7a925130e15779108cf540990e98d1b" + resolved "https://registry.yarnpkg.com/winreg/-/winreg-1.2.4.tgz#ba065629b7a925130e15779108cf540990e98d1b" integrity sha1-ugZWKbepJRMOFXeRCM9UCZDpjRs= word-wrap@~1.2.3: @@ -5290,7 +5338,7 @@ write@1.0.3: dependencies: mkdirp "^0.5.1" -xtend@^4.0.0, xtend@~4.0.1: +"xtend@>=4.0.0 <4.1.0-0", xtend@^4.0.0, xtend@~4.0.1: version "4.0.2" resolved "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54" integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index ed901db..6deb163 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -128,6 +128,7 @@ function createWindow (startHideWindow) { webPreferences: { enableRemoteModule: true, contextIsolation: false, + nativeWindowOpen: true, // ADD THIS // preload: path.join(__dirname, 'preload.js'), // Use pluginOptions.nodeIntegration, leave this alone // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info diff --git a/packages/gui/src/view/pages/index.vue b/packages/gui/src/view/pages/index.vue index d6847b8..088f576 100644 --- a/packages/gui/src/view/pages/index.vue +++ b/packages/gui/src/view/pages/index.vue @@ -72,7 +72,7 @@
-
+
-
解决OneNote、微软应用商店、微软邮箱等大部分系统自带应用无法访问网络问题。点击右上方按钮,然后按下图所示操作即可
-
注意:此操作需要DevSidecar以管理员身份启动,才能打开下面的EnableLoopback设置界面
- +
1、此设置用于解决OneNote、微软应用商店、微软邮箱等系统自带应用在开启代理后无法访问网络的问题。
+
2、点击右上方按钮,打开EnableLoopback,然后按下图所示操作即可
+
3、注意:此操作需要DevSidecar以管理员身份启动,才能打开下面的EnableLoopback设置界面
+
diff --git a/packages/gui/src/view/pages/server.vue b/packages/gui/src/view/pages/server.vue index 649287d..19dd85c 100644 --- a/packages/gui/src/view/pages/server.vue +++ b/packages/gui/src/view/pages/server.vue @@ -79,7 +79,7 @@ - + diff --git a/packages/gui/src/view/router/index.js b/packages/gui/src/view/router/index.js index fc93433..e8c11c7 100644 --- a/packages/gui/src/view/router/index.js +++ b/packages/gui/src/view/router/index.js @@ -3,6 +3,7 @@ import Server from '../pages/server' import Proxy from '../pages/proxy' import Node from '../pages/plugin/node' import Git from '../pages/plugin/git' +import Pip from '../pages/plugin/pip' import Overwall from '../pages/plugin/overwall' import Setting from '../pages/setting' @@ -13,6 +14,7 @@ const routes = [ { path: '/proxy', component: Proxy }, { path: '/plugin/node', component: Node }, { path: '/plugin/git', component: Git }, + { path: '/plugin/pip', component: Pip }, { path: '/plugin/overwall', component: Overwall }, { path: '/setting', component: Setting } diff --git a/packages/gui/src/view/router/menu.js b/packages/gui/src/view/router/menu.js index 13945c5..0478fb9 100644 --- a/packages/gui/src/view/router/menu.js +++ b/packages/gui/src/view/router/menu.js @@ -1,7 +1,8 @@ export default function createMenus (app) { const plugins = [ { title: 'NPM加速', path: '/plugin/node', icon: 'like' }, - { title: 'Git.exe代理', path: '/plugin/git', icon: 'github' } + { title: 'Git.exe代理', path: '/plugin/git', icon: 'github' }, + { title: 'pip代理', path: '/plugin/pip', icon: 'bulb' } ] const menus = [ { title: '首页', path: '/index', icon: 'home' },