Browse Source

perf: loopback

pull/192/head
18603046467 3 years ago
parent
commit
fc841b792e
  1. 4
      packages/core/src/config/index.js
  2. 6
      packages/core/src/modules/proxy/index.js
  3. 4
      packages/core/src/shell/index.js
  4. 22
      packages/core/src/shell/scripts/enable-loopback.js
  5. BIN
      packages/core/src/shell/scripts/extra-path/EnableLoopback.exe
  6. 0
      packages/core/src/shell/scripts/extra-path/clear.bat
  7. 31
      packages/core/src/shell/scripts/extra-path/index.js
  8. 0
      packages/core/src/shell/scripts/extra-path/sysproxy.exe
  9. 91
      packages/core/src/shell/scripts/set-system-proxy/index.js
  10. 8
      packages/core/yarn.lock
  11. 1
      packages/gui/package.json
  12. BIN
      packages/gui/public/loopback.png
  13. 12
      packages/gui/src/bridge/api/open-enable-loopback.js
  14. 4
      packages/gui/src/view/pages/index.vue
  15. 40
      packages/gui/src/view/pages/proxy.vue
  16. 16
      packages/mitmproxy/yarn-error.log
  17. 5
      pnpm-workspace.yaml

4
packages/core/src/config/index.js

@ -236,7 +236,9 @@ module.exports = {
'*github.com': 'quad9',
'*.vuepress.vuejs.org': 'quad9',
'gh.docmirror.top': 'quad9',
'*v2ex.com': 'quad9'
'*v2ex.com': 'quad9',
'*pypi.org':'quad9',
'*jetbrains.com':'quad9'
},
speedTest: {
enabled: true,

6
packages/core/src/modules/proxy/index.js

@ -28,6 +28,12 @@ const ProxyPlugin = function (context) {
log.error('关闭系统代理失败', err)
return false
}
},
async setEnableLoopback () {
await shell.enableLoopback()
log.info('打开EnableLoopback成功')
return true
}
}
return api

4
packages/core/src/shell/index.js

@ -6,6 +6,8 @@ const setSystemEnv = require('./scripts/set-system-env')
const getNpmEnv = require('./scripts/get-npm-env')
const setNpmEnv = require('./scripts/set-npm-env')
const setSystemProxy = require('./scripts/set-system-proxy/index')
const enableLoopback = require('./scripts/enable-loopback')
const extraPath = require('./scripts/extra-path')
module.exports = {
killByPort,
setupCa,
@ -14,6 +16,8 @@ module.exports = {
getNpmEnv,
setNpmEnv,
setSystemProxy,
enableLoopback,
extraPath,
async exec (cmds, args) {
return shell.getSystemShell().exec(cmds, args)
},

22
packages/core/src/shell/scripts/enable-loopback.js

@ -0,0 +1,22 @@
/**
*/
const Shell = require('../shell')
const extraPath = require('./extra-path')
const execute = Shell.execute
const executor = {
async windows (exec) {
const loopbackPath = extraPath.getEnableLoopbackPath()
const execFile = Shell.execFile
await execFile(loopbackPath)
},
async linux (exec, { port }) {
throw Error('不支持此操作')
},
async mac (exec, { port }) {
throw Error('不支持此操作')
}
}
module.exports = async function (args) {
return execute(executor, args)
}

BIN
packages/core/src/shell/scripts/extra-path/EnableLoopback.exe

Binary file not shown.

0
packages/core/src/shell/scripts/set-system-proxy/clear.bat → packages/core/src/shell/scripts/extra-path/clear.bat

31
packages/core/src/shell/scripts/extra-path/index.js

@ -0,0 +1,31 @@
const log = require('../../../utils/util.log')
const path = require('path')
function getExtraPath () {
let extraPath = process.env.DS_EXTRA_PATH
log.info('extraPath', extraPath)
if (!extraPath) {
extraPath = __dirname
}
return extraPath
}
function getProxyExePath () {
const extraPath = getExtraPath()
return path.join(extraPath, 'sysproxy.exe')
}
function getClearBatPath () {
const extraPath = getExtraPath()
return path.join(extraPath, 'clear.bat')
}
function getEnableLoopbackPath () {
const extraPath = getExtraPath()
return path.join(extraPath, 'EnableLoopback.exe')
}
module.exports = {
getProxyExePath,
getEnableLoopbackPath,
getClearBatPath
}

0
packages/core/src/shell/scripts/set-system-proxy/sysproxy.exe → packages/core/src/shell/scripts/extra-path/sysproxy.exe

91
packages/core/src/shell/scripts/set-system-proxy/index.js

@ -13,6 +13,7 @@ const childProcess = require('child_process')
const util = require('util')
const fs = require('fs')
const _exec = util.promisify(childProcess.exec)
const extraPath = require('../extra-path/index')
const _lanIP = [
'localhost',
'127.*',
@ -33,95 +34,13 @@ const _lanIP = [
'172.29.*',
'172.30.*',
'172.31.*',
'192.168.*'
'192.168.*',
'<-loopback>'
]
const logoffScriptPath = 'C:\\WINDOWS\\System32\\GroupPolicy\\User\\Scripts\\scripts.ini'
function buildScriptBody (addHeader = true, index = 0) {
const batPath = getClearBatPath()
const header = addHeader ? '[Logoff]\r\n' : ''
return `${header}${index}CmdLine=${batPath}
${index}Parameters=`
}
async function addClearScriptIni () {
const batPath = getClearBatPath()
let body
if (fs.existsSync(logoffScriptPath)) {
body = fs.readFileSync(logoffScriptPath)
if (body.indexOf(batPath) >= 0) {
return
}
let index = 0
// 要加新的
if (body.indexOf('[Logoff]') >= 0) {
// 如果有logoff了
const list = body.trim().split('\n')
let lastParameters = -1
for (const string of list) {
if (string.indexOf('Parameters') >= 0) {
lastParameters = parseInt(string.trim().charAt(0))
}
}
index = lastParameters + 1
body += '\r\n' + buildScriptBody(false, index)
} else {
body += '\r\n' + buildScriptBody(true, 0)
}
} else {
body = buildScriptBody(true, 0)
}
fs.writeFileSync(logoffScriptPath, body)
}
async function removeClearScriptIni () {
if (!fs.existsSync(logoffScriptPath)) {
return
}
const batPath = getClearBatPath()
let body = fs.readFileSync(logoffScriptPath)
if (body.indexOf(batPath) === -1) {
return
}
// 有就要删除
body = body.trim()
const list = body.split('\n')
let lastParameters = -1
for (const string of list) {
if (string.indexOf(batPath) >= 0) {
lastParameters = parseInt(string.trim().charAt(0))
}
}
body = body.replace(`${lastParameters}CmdLine=${batPath}`, '')
body = body.replace(`${lastParameters}Parameters=`, '')
body = body.trim()
fs.writeFileSync(logoffScriptPath, body)
}
function getExtraPath () {
let extraPath = process.env.DS_EXTRA_PATH
log.info('extraPath', extraPath)
if (!extraPath) {
extraPath = __dirname
}
return extraPath
}
function getProxyExePath () {
const extraPath = getExtraPath()
return path.join(extraPath, 'sysproxy.exe')
}
function getClearBatPath () {
const extraPath = getExtraPath()
return path.join(extraPath, 'clear.bat')
}
async function _winUnsetProxy (exec) {
// eslint-disable-next-line no-constant-condition
const proxyPath = getProxyExePath()
const proxyPath = extraPath.getProxyExePath()
await execFile(proxyPath, ['set', '1'])
try {
// await removeClearScriptIni()
@ -135,7 +54,7 @@ async function _winSetProxy (exec, ip, port) {
for (const string of _lanIP) {
lanIpStr += string + ';'
}
const proxyPath = getProxyExePath()
const proxyPath = extraPath.getProxyExePath()
await execFile(proxyPath, ['global', `${ip}:${port}`, lanIpStr])
try {
// await addClearScriptIni()

8
packages/core/yarn.lock

@ -93,10 +93,10 @@
lodash "^4.17.19"
to-fast-properties "^2.0.0"
"@docmirror/mitmproxy@^1.5.1":
version "1.5.1"
resolved "https://registry.nlark.com/@docmirror/mitmproxy/download/@docmirror/mitmproxy-1.5.1.tgz#357142a41b89266491c3519a7528b9b83dc30c85"
integrity sha1-NXFCpBuJJmSRw1GadSi5uD3DDIU=
"@docmirror/mitmproxy@^1.6.2":
version "1.6.2"
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.6.2.tgz#51c7792d7d172820250822abbaacf148e629666c"
integrity sha512-JF/cJzHuV23TTN1oS+r32Qole/u37H8H36ycO06IjxmOfXx5pu0nqeOTMe3bWTXLI1YlnlktVNOH72xH73C1Fg==
dependencies:
agentkeepalive "^2.1.1"
axios "^0.21.1"

1
packages/gui/package.json

@ -30,6 +30,7 @@
"electron-baidu-tongji": "^1.0.5",
"electron-reload": "^1.5.0",
"electron-store": "^6.0.1",
"electron-sudo": "^4.0.12",
"electron-updater": "^4.3.5",
"es-abstract": "^1.17.7",
"extract-zip": "^2.0.1",

BIN
packages/gui/public/loopback.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

12
packages/gui/src/bridge/api/open-enable-loopback.js

@ -0,0 +1,12 @@
import Sudoer from 'electron-sudo'
import DevSidecar from '@docmirror/dev-sidecar'
export default {
async open () {
const options = { name: '设置loopback' }
const sudoer = new Sudoer(options)
const exeFile = DevSidecar.api.shell.extraPath.getEnableLoopbackPath()
await sudoer.exec(
exeFile, { env: { PARAM: 'VALUE' } }
)
}
}

4
packages/gui/src/view/pages/index.vue

@ -86,8 +86,8 @@
捐赠
</div>
<div class="right">
<div>如果它解决了你的问题请不要吝啬你的star哟
<a-icon style="margin-right:10px;" type="smile" theme="outlined"/>
<div>如果它解决了你的问题请不要吝啬你的star哟点这里
<a-icon style="margin-right:10px;" type="arrow-right" theme="outlined"/>
</div>
<a @click="openExternal('https://gitee.com/docmirror/dev-sidecar')"><img
src='https://gitee.com/docmirror/dev-sidecar/badge/star.svg?theme=dark' alt='star'/></a>

40
packages/gui/src/view/pages/proxy.vue

@ -18,6 +18,10 @@
当前未启动
</a-tag>
</a-form-item>
<a-form-item label="设置loopback" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-button @click="loopbackVisible=true">去设置</a-button>
<div class="form-help">解决OneNote微软应用商店微软邮箱等大部分系统自带应用无法访问网络问题点击去设置然后按下图所示操作即可</div>
</a-form-item>
</div>
<template slot="footer">
<div class="footer-bar">
@ -25,6 +29,27 @@
<a-button :loading="applyLoading" icon="check" type="primary" @click="apply()">应用</a-button>
</div>
</template>
<a-drawer
placement="right"
:closable="false"
:visible.sync="loopbackVisible"
width="660px"
height="100%"
@close="loopbackVisible=false"
:slots="{ title: 'title' }"
wrapClassName="json-wrapper"
>
<template slot="title">
设置Loopback <a-button style="float:right;margin-right:10px;" @click="openEnableLoopback()">打开EnableLoopback</a-button>
</template>
<div>
<div>解决OneNote微软应用商店微软邮箱等大部分系统自带应用无法访问网络问题点击右上方按钮然后按下图所示操作即可</div>
<div >注意此操作需要DevSidecar以<b>管理员身份启动</b>才能打开下面的EnableLoopback设置界面</div>
<img style="margin-top:10px;" width="80%" src="loopback.png" />
</div>
</a-drawer>
</ds-container>
</template>
@ -36,7 +61,8 @@ export default {
mixins: [Plugin],
data () {
return {
key: 'proxy'
key: 'proxy',
loopbackVisible: false
}
},
created () {
@ -45,7 +71,17 @@ export default {
mounted () {
},
methods: {
async openEnableLoopback () {
try {
await this.$api.proxy.setEnableLoopback()
} catch (e) {
if (e.message.indexOf('EACCES') !== -1) {
this.$message.error('请将DevSidecar关闭后,以管理员身份重新打开,再尝试此操作')
return
}
this.$message.error('打开失败:' + e.message)
}
}
}
}
</script>

16
packages/mitmproxy/yarn-error.log

@ -1,25 +1,25 @@
Arguments:
/usr/bin/node /usr/local/bin/yarn install
D:\Soft\Development\nodejs\node.exe C:\Users\xiaojunnuo\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js install
PATH:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
D:\Codes\open\dev-sidecar\node_modules\.bin;D:\Soft\Development\python\Scripts\;D:\Soft\Development\python\;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;D:\Soft\Development\Git\cmd;D:\Soft\Development\nodejs\;C:\ProgramData\chocolatey\bin;C:\Users\xiaojunnuo\AppData\Local\Microsoft\WindowsApps;;D:\Soft\Development\IntelliJ IDEA 2021.2.3\bin;;C:\Users\xiaojunnuo\AppData\Roaming\npm;D:\Soft\Development\PyCharm 2021.2.3\bin;
Yarn version:
1.22.11
1.22.17
Node version:
14.17.5
16.13.0
Platform:
linux x64
win32 x64
Trace:
Error: ENOENT: no such file or directory, copyfile '/home/xiaojunnuo/.cache/yarn/v6/npm-webpack-4.44.2-6bfe2b0af055c8b2d1e90ed2cd9363f841266b72-integrity/node_modules/webpack/declarations/plugins/BannerPlugin.d.ts' -> '/home/xiaojunnuo/Codes/dev-sidecar/packages/mitmproxy/node_modules/webpack/declarations/plugins/BannerPlugin.d.ts'
Error: ENOENT: no such file or directory, copyfile 'C:\Users\xiaojunnuo\AppData\Local\Yarn\Cache\v6\npm-ms-2.0.0-5608aeadfc00be6c2901df5f9861788de0d597c8-integrity\node_modules\ms\index.js' -> 'D:\Codes\open\dev-sidecar\packages\mitmproxy\node_modules\eslint-plugin-import\node_modules\ms\index.js'
npm manifest:
{
"name": "@docmirror/mitmproxy",
"version": "1.5.1",
"version": "1.6.2",
"description": "",
"main": "src/index.js",
"keywords": [
@ -85,7 +85,7 @@ npm manifest:
"last 2 versions",
"not dead"
],
"gitHead": "3566cd6d33cbe782d91e408d6f174dd826b2790f"
"gitHead": "9b027af3ee7e88975a54692ed83096802764a8dc"
}
yarn manifest:

5
pnpm-workspace.yaml

@ -0,0 +1,5 @@
packages:
# all packages in subdirs of packages/ and components/
- 'packages/**'
# exclude packages that are inside test directories
- '!**/test/**'
Loading…
Cancel
Save