diff --git a/.gitignore b/.gitignore index c94498f..07e2255 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ gen node_modules/ *.lock *.log +pnpm-lock.yaml \ No newline at end of file diff --git a/README.md b/README.md index be10ea1..738119f 100644 --- a/README.md +++ b/README.md @@ -325,11 +325,19 @@ npm run electron:build ## 九、联系作者 +欢迎bug反馈,需求建议,技术交流等(请备注dev-sidecar,或简称DS) -欢迎bug反馈,需求建议,技术交流等(请备注dev-sidecar,或简称DS) +1、 加群
- + + + +
+ +2、 加作者好友 +
+
diff --git a/lerna.json b/lerna.json index f31f2f3..ab64e87 100644 --- a/lerna.json +++ b/lerna.json @@ -14,5 +14,5 @@ "ignore": [] } }, - "version": "1.6.2" + "version": "1.7.1" } 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/index.js b/packages/core/index.js index 36e33d6..9d18798 100644 --- a/packages/core/index.js +++ b/packages/core/index.js @@ -1,6 +1,7 @@ module.exports = require('./src') -// TODO 这是个彩蛋 ↓ ↓ ↓ ↓ ↓ ↓ ,如果你破解了它,请不要公开,好好用它来学习和查资料吧。 +// TODO 这是一个解谜游戏 ↓ ↓ ↓ ↓ ↓ ↓ ,如果你破解了它,请不要公开,好好用它来学习和查资料吧。 /** \u0061\u0048\u0052\u0030\u0063\u0044\u006f\u0076\u004c\u0032\u0052\u006c\u0064\u0069\u0031\u007a\u0061\u0057\u0052\u006c\u0059\u0032\u0046\u0079\u004c\u006d\u0052\u0076\u0059\u0032\u0031\u0070\u0063\u006e\u004a\u0076\u0063\u0069\u0035\u006a\u0062\u0069\u0039\u0035\u0062\u0033\u0056\u006d\u0061\u0057\u0035\u006b\u0061\u0058\u0051\u0076\u0061\u0057\u0035\u006b\u005a\u0058\u0067\u0075\u0061\u0048\u0052\u0074\u0062\u0041\u003d\u003d **/ +// 这个项目里有一点点解谜提示: https://github.com/fast-crud/fast-crud (打开拉到最下面) diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json index e6ae714..1db4ca6 100644 --- a/packages/core/package-lock.json +++ b/packages/core/package-lock.json @@ -1,6 +1,6 @@ { "name": "@docmirror/dev-sidecar", - "version": "1.6.2", + "version": "1.7.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/core/package.json b/packages/core/package.json index 3baaf33..751a5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@docmirror/dev-sidecar", - "version": "1.6.2", + "version": "1.7.1", "description": "给开发者的加速代理工具", "main": "src/index.js", "keywords": [ @@ -17,7 +17,7 @@ "test": "mocha" }, "dependencies": { - "@docmirror/mitmproxy": "^1.6.2", + "@docmirror/mitmproxy": "^1.7.1", "agentkeepalive": "^2.1.1", "babel-preset-es2020": "^1.0.2", "charset": "^1.0.0", diff --git a/packages/core/src/config/index.js b/packages/core/src/config/index.js index 6ea1a31..add18b1 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': { @@ -159,7 +163,7 @@ module.exports = { 'www.googleapis.com': { '.*': { abort: false, desc: '设置abort:true可以快速失败,节省时间' } }, 'lh*.googleusercontent.com': { '.*': { abort: false, desc: '设置abort:true可以快速失败,节省时间' } }, // mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.0/napi-v3-win32-x64.tar.gz - '*.s3.amazonaws.com': { + '*.s3.1amazonaws1.com': { '/sqlite3/.*': { redirect: 'npm.taobao.org/mirrors' } 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..d065738 --- /dev/null +++ b/packages/core/src/modules/plugin/pip/config.js @@ -0,0 +1,13 @@ +module.exports = { + name: 'PIP加速', + statusOff: true, + enabled: null, // 没有开关 + tip: '如果你没有安装pip则不需要启动它', + startup: { + }, + setting: { + command: 'pip', + trustedHost: 'pypi.org', + registry: 'https://pypi.org/simple/'// 可以选择切换官方或者淘宝镜像 + } +} 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..ea3fe13 --- /dev/null +++ b/packages/core/src/modules/plugin/pip/index.js @@ -0,0 +1,96 @@ +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 () { + const command = config.get().plugin.pip.setting.command + let ret = await shell.exec([command + ' 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 command = config.get().plugin.pip.setting.command + const cmds = [] + for (const item of list) { + if (item.value != null) { + cmds.push(`${command} config set global.${item.key} ${item.value}`) + } else { + cmds.push(`${command} config unset global.${item.key}`) + } + } + const ret = await shell.exec(cmds, { type: 'cmd' }) + return ret + }, + + async unsetPipEnv (list) { + const command = config.get().plugin.pip.setting.command + const cmds = [] + for (const item of list) { + cmds.push(`${command} 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..1f4394a 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,70 @@ 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.get('HTTPS_PROXY', (err) => { + if (!err) { + 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) { + log.info('同时设置 https_proxy') + try { + await exec('echo \'test\'') + 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) + + log.info('设置代理', ip, port, setEnv) + 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 +122,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 +139,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/extra/scripts/github.script b/packages/gui/extra/scripts/github.script index 1095009..e771c24 100644 --- a/packages/gui/extra/scripts/github.script +++ b/packages/gui/extra/scripts/github.script @@ -1,6 +1,6 @@ // ==UserScript== // @name Github 增强 - 高速下载 -// @version 1.5.7 +// @version 1.6.8 // @author X.I.U // @description 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁) // @match *://github.com/* @@ -17,43 +17,32 @@ // @namespace https://greasyfork.org/scripts/412245 // @supportURL https://github.com/XIU2/UserScript // @homepageURL https://github.com/XIU2/UserScript -// @downloadURL none // ==/UserScript== (function() { 'use strict'; - var backColor = '#ffffff'; - var fontColor = '#888888'; + var backColor = '#ffffff', fontColor = '#888888'; if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'dark') { // 黑暗模式判断 if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme') === 'dark_dimmed') { - backColor = '#272e37'; - fontColor = '#768390'; + backColor = '#272e37'; fontColor = '#768390'; } else { - backColor = '#161a21'; - fontColor = '#97a0aa'; + backColor = '#161a21'; fontColor = '#97a0aa'; } } else if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'auto') { - console.log(window.getComputedStyle(document.body).backgroundColor) if (window.getComputedStyle(document.body).backgroundColor === 'rgb(34, 39, 46)') { - backColor = '#272e37'; - fontColor = '#768390'; + backColor = '#272e37'; fontColor = '#768390'; } else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(13, 17, 23)') { - backColor = '#161a21'; - fontColor = '#97a0aa'; + backColor = '#161a21'; fontColor = '#97a0aa'; } } - //['https://gh.66ccff.work', '美国'], - //['https://github.91chifun.workers.dev', '美国'], - //['https://github.rc1844.workers.dev', '美国'], const download_url = [ - ['https://gh.api.99988866.xyz', '美国'], - ['https://gh.msx.workers.dev', '美国'], - ['https://gh.xiu2.xyz', '美国'], - ['https://gh.argv.cc', '美国费利蒙'], - ['https://git.yumenaka.net', '美国洛杉矶'], - ['https://download.fastgit.org', '日本东京'], - ['https://ghproxy.com', '韩国首尔'], - ['https://pd.zwc365.com/seturl', '中国香港'] + ['https://gh.api.99988866.xyz/https://github.com', '美国 1'], + ['https://github.91chifun.workers.dev/https://github.com', '美国 2'], + ['https://gh.xiu2.xyz/https://github.com', '美国 3'], + ['https://github.rc1844.workers.dev', '美国 4'], + ['https://pd.zwc365.com/seturl/https://github.com', '美国 5'], + ['https://download.fastgit.org', '日本'], + ['https://ghproxy.com/https://github.com/', '韩国'] ], clone_url = [ ['https://hub.fastgit.org', '中国香港'], @@ -68,8 +57,7 @@ ['https://raw.githubusercontent.com', 'Github 原生',''], ['https://cdn.jsdelivr.net','中国国内', '注意:该加速源存在缓存机制(24小时),所以文件可能不是最新。 注意:当前分支所有文件总文件大小超过 50MB 时,该加速源不可用。 注意:当前分支名为版本号格式时(如 v1.2.3),该高速下载链接因格式限制不可用。'], ['https://raw.fastgit.org','中国香港', '注意:单个文件太大时可能会提示超时(实时获取中),请重试。'], - ['https://cdn.staticaly.com','日本东京', '注意:该加速是全球 Anycast CDN,国内一般分配到日本节点。'], - ['https://ghproxy.com','韩国首尔', ''] + ['https://cdn.staticaly.com','日本东京', '注意:该加速是全球 Anycast CDN,国内一般分配到日本节点。'] ], svg = [ '', @@ -114,19 +102,19 @@ return ['0️⃣','1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣','🔟'][num] } - addRelease(); // Release 加速 - addDownloadZIP(); // Download ZIP 加速 - addGitClone(); // Git Clone 加速 - addGitCloneSSH(); // Git Clone SSH 加速 - addRawFile(); // Raw 加速 + addRelease(); // Release 加速 + setTimeout(addDownloadZIP, 2000); // Download ZIP 加速 + setTimeout(addGitClone, 2000); // Git Clone 加速 + setTimeout(addGitCloneSSH, 2000); // Git Clone SSH 加速 + addRawFile(); // Raw 加速 setTimeout(addRawDownLink, 2000); // 添加 Raw 下载链接(☁),延迟 2 秒执行,避免被 pjax 刷掉 document.addEventListener('pjax:success',function(){ // pjax 事件发生后 - addRelease(); // Release 加速 - addDownloadZIP(); // Download ZIP 加速 - addGitClone(); // Git Clone 加速 - addGitCloneSSH(); // Git Clone SSH 加速 - addRawFile(); // Raw 加速 + addRelease(); // Release 加速 + setTimeout(addDownloadZIP, 2000); // Download ZIP 加速 + setTimeout(addGitClone, 2000); // Git Clone 加速 + setTimeout(addGitCloneSSH, 2000); // Git Clone SSH 加速 + addRawFile(); // Raw 加速 setTimeout(addRawDownLink, 2000); // 添加 Raw 下载链接(☁),延迟 2 秒执行,避免被 pjax 刷掉 }); @@ -138,53 +126,21 @@ // Release function addRelease() { - let html = document.getElementsByClassName('Box Box--condensed');if (!html) return - let divDisplay; - if (document.documentElement.clientWidth > 1000) { - divDisplay = 'display: flex;'; - } else { - divDisplay = 'display: block;'; - } + let html = document.getElementsByClassName('Box-footer'); if (html.length == 0) return + let divDisplay = ''; + if (document.documentElement.clientWidth > 1000) {divDisplay = 'float: right;margin-top: -3px;margin-left: 8px;';}; // 调整小屏幕时的样式 Array.from(html).forEach(function (current) { - current.querySelectorAll('.d-flex.Box-body > a').forEach(function (_this) { + current.querySelectorAll('li.Box-row > a').forEach(function (_this) { let href = _this.href.split(location.host), url = [], - _html = `
`; - + _html = `
`; + // 循环组合 URL 链接 for (let i=0;i -1) url[i] = url[i].replace('https://download.fastgit.org','https://archive.fastgit.org') } - - for (let i=0;i${download_url[i][1]}` - } - _html += `
` - _this.nextElementSibling.insertAdjacentHTML('afterend', _html); - }); - // 修改[文件大小]元素样式 - document.querySelectorAll('small.pl-2.color-text-secondary.flex-shrink-0').forEach(el=>{el.style.cssText='display: flex; justify-content: flex-end; flex-grow: 1; margin-right: 8px;'}); - - - // Source Code - current.querySelectorAll('.d-block.Box-body > a').forEach(function (_this) { - let href = _this.href.split(location.host), - url = [], - _html = `
`; - - for (let i=0;i${download_url[i][1]}` } @@ -192,29 +148,25 @@ _this.insertAdjacentHTML('afterend', _html); }); }); - // 修改 Source code 样式,使其和加速按钮并列一排 - document.querySelectorAll('div.d-block.py-1.py-md-2.Box-body.px-2').forEach(el=>{el.className='d-flex py-1 py-md-2 Box-body px-2'}); } // Download ZIP function addDownloadZIP() { + if (document.querySelector('.XIU2-DZ')) return let html = document.querySelector('.dropdown-menu.dropdown-menu-sw.p-0 ul li:last-child');if (!html) return let href = html.getElementsByTagName('a')[0].href, url = [], _html = ``; for (let i=0;i -1) url[i] = url[i].replace('https://download.fastgit.org','https://archive.fastgit.org') } for (let i=0;i${svg[0]}Download ZIP ${download_url[i][1]}` + _html += `
  • ${svg[0]}Download ZIP ${download_url[i][1]}
  • ` } html.insertAdjacentHTML('afterend', _html); } @@ -222,6 +174,7 @@ // Git Clone function addGitClone() { + if (document.querySelector('.XIU2-GC')) return let html = document.querySelector('[role="tabpanel"]:nth-child(2) div.input-group');if (!html) return let href_split = html.getElementsByTagName('input')[0].getAttribute('value').split(location.host), url = [], @@ -236,7 +189,7 @@ } for (let i=0;i
    ${svg[1]}
    ` + _html += `
    ${svg[1]}
    ` } html.insertAdjacentHTML('afterend', _html); } @@ -244,6 +197,7 @@ // Git Clone SSH function addGitCloneSSH() { + if (document.querySelector('.XIU2-GCS')) return let html = document.querySelector('[role="tabpanel"]:nth-child(3) div.input-group');if (!html) return let href_split = html.getElementsByTagName('input')[0].getAttribute('value').split(':'), url = [], @@ -252,11 +206,11 @@ if (href_split[0] != 'git@github.com') return for (let i=0;i
    ${svg[1]}
    ` + _html += `
    ${svg[1]}
    ` } html.insertAdjacentHTML('afterend', _html); } @@ -264,18 +218,18 @@ // Raw function addRawFile() { + if (document.querySelector('.XIU2-RF')) return let html = document.getElementById('raw-url');if (!html) return let href = location.href.replace(`https://${location.host}`,''), href2 = href.replace('/blob/','/'), url = [ - raw_url[1][0] + "/gh" + href.replace('/blob/','@'), + raw_url[1][0] + '/gh' + href.replace('/blob/','@'), raw_url[2][0] + href2, - raw_url[3][0] + "/gh" + href.replace('/blob/','/'), - raw_url[4][0] + "/" + raw_url[0][0] + href2 + raw_url[3][0] + '/gh' + href.replace('/blob/','/') ], _html = ``; for (let i=0;i${raw_url[i+1][1]}` + _html += `${raw_url[i+1][1]}` } html.insertAdjacentHTML('afterend', _html); } @@ -284,14 +238,14 @@ // 添加 Raw 下载链接(☁) function addRawDownLink() { // 如果不是项目文件页面,就返回,如果网页有 Raw 下载链接(☁)就返回 - let files = document.querySelectorAll('div.Box-row svg.octicon.octicon-file');if(files.length === 0) return; + let files = document.querySelectorAll('div.Box-row svg.octicon.octicon-file');if(files.length === 0) return;if (location.pathname.indexOf('/tags') > -1) return let files1 = document.querySelectorAll('a.fileDownLink');if(files1.length > 0) return; // 鼠标指向则显示 var mouseOverHandler = function(evt) { let elem = evt.currentTarget, aElm_new = elem.querySelectorAll('.fileDownLink'), - aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary'); + aElm_now = elem.querySelectorAll('svg.octicon.octicon-file'); aElm_new.forEach(el=>{el.style.cssText = 'display: inline'}); aElm_now.forEach(el=>{el.style.cssText = 'display: none'}); }; @@ -300,7 +254,7 @@ var mouseOutHandler = function(evt) { let elem = evt.currentTarget, aElm_new = elem.querySelectorAll('.fileDownLink'), - aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary'); + aElm_now = elem.querySelectorAll('svg.octicon.octicon-file'); aElm_new.forEach(el=>{el.style.cssText = 'display: none'}); aElm_now.forEach(el=>{el.style.cssText = 'display: inline'}); }; @@ -309,32 +263,22 @@ files.forEach(function(fileElm, i) { let trElm = fileElm.parentNode.parentNode, cntElm_a = trElm.querySelector('.css-truncate.css-truncate-target.d-block.width-fit a'), - cntElm_svg = trElm.querySelector('.mr-3.flex-shrink-0 svg.octicon.octicon-file.color-icon-tertiary'), + cntElm_svg = trElm.querySelector('.mr-3.flex-shrink-0 svg.octicon.octicon-file'), Name = cntElm_a.innerText, href = cntElm_a.attributes.href.nodeValue.replace(`https://${location.host}`,''); let href2 = href.replace('/blob/','/'), url, url_name, url_tip = ''; switch(menu_raw_fast) { + case 0: + case 2: + url = raw_url[menu_raw_fast][0] + href2; break; case 1: - url = raw_url[1][0] + '/gh' + href.replace('/blob/','@'); - url_name = raw_url[1][1]; - url_tip = raw_url[1][2]; - break; + url = raw_url[menu_raw_fast][0] + '/gh' + href.replace('/blob/','@'); break; case 3: - url = raw_url[3][0] + '/gh' + href.replace('/blob/','/'); - url_name = raw_url[3][1]; - url_tip = raw_url[3][2]; - break; - case 4: - url = raw_url[4][0] + "/" + raw_url[0][0] + href2; - url_name = raw_url[4][1]; - url_tip = raw_url[4][2]; - break; + url = raw_url[menu_raw_fast][0] + '/gh' + href.replace('/blob/','/'); break; default: - url = raw_url[menu_raw_fast][0] + href2; - url_name = raw_url[menu_raw_fast][1]; - url_tip = raw_url[menu_raw_fast][2]; - break; + url = raw_url[menu_raw_fast][0] + '/' + raw_url[0][0] + href2; } + url_name = raw_url[menu_raw_fast][1]; url_tip = raw_url[menu_raw_fast][2]; let _html = ` `; cntElm_svg.insertAdjacentHTML('afterend', _html); // 绑定鼠标事件 @@ -363,7 +307,7 @@ var mouseOverHandler = function(evt) { let elem = evt.currentTarget, aElm_new = elem.querySelectorAll('.fileDownLink'), - aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary'); + aElm_now = elem.querySelectorAll('svg.octicon.octicon-file'); aElm_new.forEach(el=>{el.style.cssText = 'display: inline'}); aElm_now.forEach(el=>{el.style.cssText = 'display: none'}); }; @@ -372,7 +316,7 @@ var mouseOutHandler = function(evt) { let elem = evt.currentTarget, aElm_new = elem.querySelectorAll('.fileDownLink'), - aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary'); + aElm_now = elem.querySelectorAll('svg.octicon.octicon-file'); aElm_new.forEach(el=>{el.style.cssText = 'display: none'}); aElm_now.forEach(el=>{el.style.cssText = 'display: inline'}); }; diff --git a/packages/gui/package.json b/packages/gui/package.json index 9be3229..3bdf981 100644 --- a/packages/gui/package.json +++ b/packages/gui/package.json @@ -1,6 +1,6 @@ { "name": "@docmirror/dev-sidecar-gui", - "version": "1.6.2", + "version": "1.7.1", "private": false, "license": "MPL-2.0", "main": "background.js", @@ -21,8 +21,8 @@ "name": "Greper" }, "dependencies": { - "@docmirror/dev-sidecar": "^1.6.2", - "@docmirror/mitmproxy": "^1.6.2", + "@docmirror/dev-sidecar": "^1.7.1", + "@docmirror/mitmproxy": "^1.7.1", "adm-zip": "^0.5.5", "ant-design-vue": "^1.6.5", "compressing": "^1.5.1", diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index ed901db..95b4f3b 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -26,10 +26,20 @@ protocol.registerSchemesAsPrivileged([ ]) // 隐藏主窗口,并创建托盘,绑定关闭事件 function setTray () { + // const topMenu = Menu.buildFromTemplate({}) + // Menu.setApplicationMenu(topMenu) // 用一个 Tray 来表示一个图标,这个图标处于正在运行的系统的通知区 // 通常被添加到一个 context menu 上. // 系统托盘右键菜单 const trayMenuTemplate = [ + + { + // 系统托盘图标目录 + label: 'DevTools', + click: () => { + win.webContents.openDevTools() + } + }, { // 系统托盘图标目录 label: '退出', @@ -109,7 +119,9 @@ function showWin () { if (win) { win.show() } - app.dock.show() + if (app.dock) { + app.dock.show() + } } function changeAppConfig (config) { @@ -128,6 +140,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 @@ -138,6 +151,9 @@ function createWindow (startHideWindow) { icon: path.join(__static, 'icon.png') }) + Menu.setApplicationMenu(null) + win.setMenu(null) + if (process.env.WEBPACK_DEV_SERVER_URL) { // Load the url of the dev server if in development mode win.loadURL(process.env.WEBPACK_DEV_SERVER_URL) diff --git a/packages/gui/src/view/components/setup-ca.vue b/packages/gui/src/view/components/setup-ca.vue index 19bcfa5..8a954c4 100644 --- a/packages/gui/src/view/components/setup-ca.vue +++ b/packages/gui/src/view/components/setup-ca.vue @@ -54,7 +54,7 @@ export default { }, data () { return { - systemPlatform: 'win' + systemPlatform: '' } }, async created () { diff --git a/packages/gui/src/view/mixins/plugin.js b/packages/gui/src/view/mixins/plugin.js index e977dee..d968948 100644 --- a/packages/gui/src/view/mixins/plugin.js +++ b/packages/gui/src/view/mixins/plugin.js @@ -11,7 +11,8 @@ export default { status: {}, labelCol: { span: 4 }, wrapperCol: { span: 20 }, - applyLoading: false + applyLoading: false, + systemPlatform: '' } }, created () { @@ -26,15 +27,17 @@ export default { } throw new Error('请设置key') }, - init () { + async init () { this.status = this.$status - return this.$api.config.reload().then(ret => { - this.config = ret - console.log('config', this.config) - if (this.ready) { - return this.ready(this.config) - } - }) + + this.config = await this.$api.config.reload() + this.systemPlatform = await this.$api.info.getSystemPlatform() + console.log('config', this.config, this.systemPlatform) + // eslint-disable-next-line no-debugger + + if (this.ready) { + return this.ready(this.config) + } }, async apply () { this.applyLoading = true @@ -84,6 +87,15 @@ export default { return {} } return value + }, + isWindows () { + return this.systemPlatform === 'windows' + }, + isMac () { + return this.systemPlatform === 'mac' + }, + isLinux () { + return this.systemPlatform === 'linux' } } } diff --git a/packages/gui/src/view/pages/index.vue b/packages/gui/src/view/pages/index.vue index d6847b8..f92a3fb 100644 --- a/packages/gui/src/view/pages/index.vue +++ b/packages/gui/src/view/pages/index.vue @@ -36,6 +36,11 @@ 增强模式 + + + 彩蛋 + + @@ -72,9 +77,9 @@
    -
    +
    @@ -163,7 +168,7 @@ export default { } }, async created () { - this.doCheckRootCa() + await this.doCheckRootCa() await this.reloadConfig() this.$set(this, 'status', this.$status) this.switchBtns = this.createSwitchBtns() @@ -208,7 +213,7 @@ export default { }, wantOW () { this.$success({ - title: '彩蛋', + title: '彩蛋(增强模式)', content: (
    我把它藏在了源码里,感兴趣的话可以找一找它(线索提示 // TODO) @@ -216,28 +221,27 @@ export default { ) }) }, - doCheckRootCa () { - this.$api.setting.load().then(setting => { - console.log('setting', setting) - this.setting = setting - if (this.setting.rootCa && (this.setting.rootCa.setuped || this.setting.rootCa.noTip)) { - return + async doCheckRootCa () { + const setting = await this.$api.setting.load() + console.log('setting', setting) + this.setting = setting + if (this.setting.rootCa && (this.setting.rootCa.setuped || this.setting.rootCa.noTip)) { + return + } + this.$confirm({ + title: '第一次使用,请先安装CA根证书', + content: '本应用正常使用,必须安装和信任CA根证书', + cancelText: '下次', + okText: '去安装', + onOk: () => { + this.openSetupCa() + }, + onCancel: () => { + this.setting.rootCa = this.setting.rootCa || {} + // const rootCa = this.setting.rootCa + // rootCa.noTip = true + // this.$api.setting.save(this.setting) } - this.$confirm({ - title: '第一次使用,请先安装CA根证书', - content: '本应用正常使用,必须安装和信任CA根证书', - cancelText: '下次', - okText: '去安装', - onOk: () => { - this.openSetupCa() - }, - onCancel: () => { - this.setting.rootCa = this.setting.rootCa || {} - // const rootCa = this.setting.rootCa - // rootCa.noTip = true - // this.$api.setting.save(this.setting) - } - }) }) }, openSetupCa () { @@ -265,6 +269,9 @@ export default { btns.server = this.createSwitchBtn('server', '代理服务', this.$api.server, status) btns.proxy = this.createSwitchBtn('proxy', '系统代理', this.$api.proxy, status) lodash.forEach(status.plugin, (item, key) => { + if (this.config.plugin[key].statusOff) { + return + } btns[key] = this.createSwitchBtn(key, this.config.plugin[key].name, this.$api.plugin[key], status.plugin, this.config.plugin[key].tip) }) return btns diff --git a/packages/gui/src/view/pages/plugin/node.vue b/packages/gui/src/view/pages/plugin/node.vue index c7c671f..b672e80 100644 --- a/packages/gui/src/view/pages/plugin/node.vue +++ b/packages/gui/src/view/pages/plugin/node.vue @@ -26,27 +26,29 @@ npm代理启用后必须关闭 - + - npmjs + npmjs原生 - taobao + taobao镜像 +
    设置后立即生效,即使关闭ds也会继续保持
    - + - yarn + yarn原生 - taobao + taobao镜像 +
    设置后立即生效,即使关闭ds也会继续保持
    diff --git a/packages/gui/src/view/pages/plugin/pip.vue b/packages/gui/src/view/pages/plugin/pip.vue new file mode 100644 index 0000000..59e6fd2 --- /dev/null +++ b/packages/gui/src/view/pages/plugin/pip.vue @@ -0,0 +1,104 @@ + + + + diff --git a/packages/gui/src/view/pages/proxy.vue b/packages/gui/src/view/pages/proxy.vue index afd5754..22d784a 100644 --- a/packages/gui/src/view/pages/proxy.vue +++ b/packages/gui/src/view/pages/proxy.vue @@ -18,9 +18,16 @@ 当前未启动 - + + + 是否同时修改HTTPS_PROXY环境变量 + +
    当发现某些应用并没有走加速通道或者加速报错时,可以尝试勾选此选项,并重新开启系统代理开关
    +
    注意:当前已打开的命令行并不会实时生效,需要重新打开一个新的命令行窗口
    +
    + 去设置 -
    解决OneNote、微软应用商店、微软邮箱等大部分系统自带应用无法访问网络问题。点击去设置,然后按下图所示操作即可
    +
    解决OneNote、MicrosoftStore、Outlook等UWP应用开启代理后无法访问网络的问题
    -
    解决OneNote、微软应用商店、微软邮箱等大部分系统自带应用无法访问网络问题。点击右上方按钮,然后按下图所示操作即可
    -
    注意:此操作需要DevSidecar以管理员身份启动,才能打开下面的EnableLoopback设置界面
    - +
    1、此设置用于解决OneNote、MicrosoftStore、Outlook等UWP应用无法访问网络的问题。
    +
    2、点击右上方按钮,打开EnableLoopback,然后按下图所示操作即可
    +
    3、注意:此操作需要DevSidecar以管理员身份启动,才能打开下面的EnableLoopback设置界面
    +
    @@ -65,12 +73,14 @@ export default { loopbackVisible: false } }, - created () { - + async created () { }, mounted () { }, methods: { + async applyAfter () { + await this.$api.proxy.restart() + }, async openEnableLoopback () { try { await this.$api.proxy.setEnableLoopback() 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/pages/setting.vue b/packages/gui/src/view/pages/setting.vue index ff473b4..39a5754 100644 --- a/packages/gui/src/view/pages/setting.vue +++ b/packages/gui/src/view/pages/setting.vue @@ -15,7 +15,7 @@ windows下建议开启开机自启。更多说明参考
    - + 关闭窗口时隐藏Dock图标(仅限Mac) 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..5655bd5 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' }, diff --git a/packages/mitmproxy/package.json b/packages/mitmproxy/package.json index 0c3d5e9..9878eef 100644 --- a/packages/mitmproxy/package.json +++ b/packages/mitmproxy/package.json @@ -1,6 +1,6 @@ { "name": "@docmirror/mitmproxy", - "version": "1.6.2", + "version": "1.7.1", "description": "", "main": "src/index.js", "keywords": [ diff --git a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js index d72bf07..22af3a6 100644 --- a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js +++ b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js @@ -8,6 +8,9 @@ function matched (hostname, regexpMap) { if (ret1) { return true } + if (pacClient == null) { + return false + } const ret = pacClient.FindProxyForURL('https://' + hostname, hostname) if (ret && ret.indexOf('PROXY ') === 0) { return true @@ -19,7 +22,7 @@ module.exports = function createOverWallIntercept (overWallConfig) { if (!overWallConfig || overWallConfig.enabled !== true) { return null } - if (overWallConfig.pac) { + if (overWallConfig.pac && overWallConfig.pac.enabled) { // 初始化pac pacClient = pac.createPacClient(overWallConfig.pac.pacFileAbsolutePath) }