feat: support arm (#401)

pull/406/head
star knight 2024-11-27 00:52:16 +08:00 committed by GitHub
parent aa4017d5c0
commit 5b43171ec5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 15880 additions and 254 deletions

View File

@ -11,6 +11,9 @@ jobs:
# job 1
build-and-upload:
runs-on: ${{ matrix.os }}-latest
env:
ELECTRON_CACHE: ${{ github.workspace }}/.cache/electron
ELECTRON_BUILDER_CACHE: ${{ github.workspace }}/.cache/electron-builder
strategy:
fail-fast: false
matrix:
@ -24,14 +27,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v4.1.7
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: 'Setup Node.js "${{ matrix.node }}.x" environment'
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: https://npm.pkg.github.com/
- name: Setup pnpm
uses: pnpm/action-setup@v4
cache: pnpm
- name: Setup Python environment (Mac) Because of electron-builder install-app-deps requires Python setup tools
if: matrix.os == 'macos'
@ -69,15 +73,31 @@ jobs:
echo "--------------------";
python --version;
- name: pnpm install
- name: Setup electron cahce
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.cache/electron
key: ${{ runner.os }}-electron-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-electron-cache-
- name: Setup electron-builder cahce
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.cache/electron-builder
key: ${{ runner.os }}-electron-builder-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-electron-builder-cache-
- name: "'pnpm install --force' Because we need to install optional dependencies"
run: |
echo "======================================================================";
dir || ls -lah;
echo "======================================================================";
echo "pnpm install";
echo "pnpm install --force";
echo "--------------------";
pnpm install;
pnpm install --force;
- name: 'npm run electron:build'
run: |
@ -104,33 +124,63 @@ jobs:
cd ../../../;
dir || ls -lah;
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}.exe - Windows'
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-ia32.exe - Windows'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'windows' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}.exe
name: 'DevSidecar-${{ steps.package-info.outputs.version }}.exe'
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-ia32.exe
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-ia32.exe'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}.deb - Ubuntu'
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-x64.exe - Windows'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'windows' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-x64.exe
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-x64.exe'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-arm64.exe - Windows'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'windows' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-arm64.exe
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-arm64.exe'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-amd64.deb - Ubuntu'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'ubuntu' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}.deb
name: 'DevSidecar-${{ steps.package-info.outputs.version }}.deb'
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-amd64.deb
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-amd64.deb'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}.AppImage - Ubuntu'
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-arm64.deb - Ubuntu'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'ubuntu' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}.AppImage
name: 'DevSidecar-${{ steps.package-info.outputs.version }}.AppImage'
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-arm64.deb
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-arm64.deb'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}.dmg - Mac'
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-x86_64.AppImage - Ubuntu'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'ubuntu' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-x86_64.AppImage
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-x86_64.AppImage'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-arm64.AppImage - Ubuntu'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'ubuntu' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-arm64.AppImage
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-arm64.AppImage'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-universal.dmg - Mac'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'macos' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}.dmg
name: 'DevSidecar-${{ steps.package-info.outputs.version }}.dmg'
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-universal.dmg
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-universal.dmg'
if-no-files-found: error
# job 2
@ -152,25 +202,47 @@ jobs:
run: mkdir release
# Download artifacts
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}.exe - Windows'
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}-ia32.exe - Windows'
uses: actions/download-artifact@v4.1.8
with:
name: DevSidecar-${{ steps.package-info.outputs.version }}.exe
name: DevSidecar-${{ steps.package-info.outputs.version }}-ia32.exe
path: release
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}.deb - Ubuntu'
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}-x64.exe - Windows'
uses: actions/download-artifact@v4.1.8
with:
name: DevSidecar-${{ steps.package-info.outputs.version }}.deb
name: DevSidecar-${{ steps.package-info.outputs.version }}-x64.exe
path: release
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}.AppImage - Ubuntu'
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}-arm64.exe - Windows'
uses: actions/download-artifact@v4.1.8
with:
name: DevSidecar-${{ steps.package-info.outputs.version }}.AppImage
name: DevSidecar-${{ steps.package-info.outputs.version }}-arm64.exe
path: release
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}.dmg - Mac'
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}-amd64.deb - Ubuntu'
uses: actions/download-artifact@v4.1.8
with:
name: DevSidecar-${{ steps.package-info.outputs.version }}.dmg
name: DevSidecar-${{ steps.package-info.outputs.version }}-amd64.deb
path: release
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}-arm64.deb - Ubuntu'
uses: actions/download-artifact@v4.1.8
with:
name: DevSidecar-${{ steps.package-info.outputs.version }}-arm64.deb
path: release
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}-x86_64.AppImage - Ubuntu'
uses: actions/download-artifact@v4.1.8
with:
name: DevSidecar-${{ steps.package-info.outputs.version }}-x86_64.AppImage
path: release
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}-arm64.AppImage - Ubuntu'
uses: actions/download-artifact@v4.1.8
with:
name: DevSidecar-${{ steps.package-info.outputs.version }}-arm64.AppImage
path: release
- name: 'Download DevSidecar-${{ steps.package-info.outputs.version }}-universal.dmg - Mac'
uses: actions/download-artifact@v4.1.8
with:
name: DevSidecar-${{ steps.package-info.outputs.version }}-universal.dmg
path: release
- name: 'Print files from "release" dir'

View File

@ -10,6 +10,9 @@ on:
jobs:
npm-run-electron:
runs-on: ${{ matrix.os }}-latest
env:
ELECTRON_CACHE: ${{ github.workspace }}/.cache/electron
ELECTRON_BUILDER_CACHE: ${{ github.workspace }}/.cache/electron-builder
strategy:
fail-fast: false
matrix:
@ -23,14 +26,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v4.1.7
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: 'Setup Node.js "${{ matrix.node }}.x" environment'
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: https://npm.pkg.github.com/
- name: Setup pnpm
uses: pnpm/action-setup@v4
cache: pnpm
- name: Setup Python environment (Mac) Because of electron-builder install-app-deps requires Python setup tools
if: matrix.os == 'macos'
@ -68,6 +72,22 @@ jobs:
echo "--------------------";
python --version;
- name: Setup electron cahce
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.cache/electron
key: ${{ runner.os }}-electron-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-electron-cache-
- name: Setup electron-builder cahce
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.cache/electron-builder
key: ${{ runner.os }}-electron-builder-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-electron-builder-cache-
- name: pnpm install
run: |
echo "======================================================================";
@ -78,7 +98,7 @@ jobs:
echo "--------------------";
pnpm install;
- name: 'npm run electron'
- name: npm run electron
run: |
echo "======================================================================";
echo "cd packages/gui";

View File

@ -14,6 +14,9 @@ on:
jobs:
test-and-upload:
runs-on: ${{ matrix.os }}-latest
env:
ELECTRON_CACHE: ${{ github.workspace }}/.cache/electron
ELECTRON_BUILDER_CACHE: ${{ github.workspace }}/.cache/electron-builder
strategy:
fail-fast: false
matrix:
@ -27,14 +30,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v4.1.7
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: 'Setup Node.js "${{ matrix.node }}.x" environment'
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: https://npm.pkg.github.com/
- name: Setup pnpm
uses: pnpm/action-setup@v4
cache: pnpm
- name: Setup Python environment (Mac) Because of electron-builder install-app-deps requires Python setup tools
if: matrix.os == 'macos'
@ -72,15 +76,31 @@ jobs:
echo "--------------------";
python --version;
- name: pnpm install
- name: Setup electron cahce
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.cache/electron
key: ${{ runner.os }}-electron-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-electron-cache-
- name: Setup electron-builder cahce
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.cache/electron-builder
key: ${{ runner.os }}-electron-builder-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-electron-builder-cache-
- name: "'pnpm install --force' Because we need to install optional dependencies"
run: |
echo "======================================================================";
dir || ls -lah;
echo "======================================================================";
echo "pnpm install";
echo "pnpm install --force";
echo "--------------------";
pnpm install;
pnpm install --force;
- name: 'npm run electron:build'
run: |
@ -107,31 +127,61 @@ jobs:
cd ../../../;
dir || ls -lah;
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}.exe - Windows'
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-ia32.exe - Windows'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'windows' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}.exe
name: 'DevSidecar-${{ steps.package-info.outputs.version }}.exe'
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-ia32.exe
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-ia32.exe'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}.deb - Ubuntu'
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-x64.exe - Windows'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'windows' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-x64.exe
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-x64.exe'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-arm64.exe - Windows'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'windows' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-arm64.exe
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-arm64.exe'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-amd64.deb - Ubuntu'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'ubuntu' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}.deb
name: 'DevSidecar-${{ steps.package-info.outputs.version }}.deb'
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-amd64.deb
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-amd64.deb'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}.AppImage - Ubuntu'
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-arm64.deb - Ubuntu'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'ubuntu' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}.AppImage
name: 'DevSidecar-${{ steps.package-info.outputs.version }}.AppImage'
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-arm64.deb
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-arm64.deb'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}.dmg - Mac'
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-x86_64.AppImage - Ubuntu'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'ubuntu' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-x86_64.AppImage
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-x86_64.AppImage'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-arm64.AppImage - Ubuntu'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'ubuntu' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-arm64.AppImage
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-arm64.AppImage'
if-no-files-found: error
- name: 'Upload DevSidecar-${{ steps.package-info.outputs.version }}-universal.dmg - Mac'
uses: actions/upload-artifact@v4.4.0
if: ${{ matrix.os == 'macos' }}
with:
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}.dmg
name: 'DevSidecar-${{ steps.package-info.outputs.version }}.dmg'
path: packages/gui/dist_electron/DevSidecar-${{ steps.package-info.outputs.version }}-universal.dmg
name: 'DevSidecar-${{ steps.package-info.outputs.version }}-universal.dmg'
if-no-files-found: error

3
.gitignore vendored
View File

@ -11,11 +11,10 @@
# Node files
node_modules/
*.lock
pnpm-lock.yaml
package-lock.json
# Other files
out
gen
*.log
*.lnk
*.lnk

0
packages/cli/cli.js Normal file → Executable file
View File

View File

@ -16,6 +16,8 @@
"test": "mocha"
},
"dependencies": {
"@starknt/sysproxy": "^0.0.1",
"@vscode/sudo-prompt": "^9.3.1",
"fix-path": "^3.0.0",
"iconv-lite": "^0.6.3",
"lodash": "^4.17.21",

View File

@ -2,14 +2,35 @@
*/
const Shell = require('../shell')
const extraPath = require('./extra-path')
const sudoPrompt = require('@vscode/sudo-prompt')
const log = require('../../utils/util.log')
const execute = Shell.execute
const executor = {
async windows (exec) {
windows (exec) {
const loopbackPath = extraPath.getEnableLoopbackPath()
const execFile = Shell.execFile
await execFile(loopbackPath)
const sudoCommand = [`"${loopbackPath}"`]
const options = {
name: 'EnableLoopback',
}
return new Promise((resolve, reject) => {
sudoPrompt.exec(
sudoCommand.join(' '),
options,
(error, _, stderr) => {
if (stderr) {
log.error(`[sudo-prompt] 发生错误: ${stderr}`)
}
if (error) {
reject(error)
} else {
resolve(undefined)
}
},
)
})
},
async linux (exec, { port }) {
throw new Error('不支持此操作')

View File

@ -7,10 +7,8 @@ const request = require('request')
const Registry = require('winreg')
const log = require('../../../utils/util.log')
const Shell = require('../../shell')
const extraPath = require('../extra-path/index')
const execute = Shell.execute
const execFile = Shell.execFile
let config = null
function loadConfig () {
@ -19,36 +17,6 @@ function loadConfig () {
}
}
async function _winUnsetProxy (exec, setEnv) {
const proxyPath = extraPath.getProxyExePath()
await execFile(proxyPath, ['set', '1'])
try {
await exec('echo \'删除环境变量 HTTPS_PROXY、HTTP_PROXY\'')
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.warn('删除环境变量 HTTPS_PROXY 失败:', err)
await exec('setx DS_REFRESH "1"')
})
}
})
regKey.get('HTTP_PROXY', (err) => {
if (!err) {
regKey.remove('HTTP_PROXY', async (err) => {
log.warn('删除环境变量 HTTP_PROXY 失败:', err)
})
}
})
} catch (e) {
log.error('删除环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e)
}
}
function getDomesticDomainAllowListTmpFilePath () {
return path.join(config.get().server.setting.userBasePath, '/domestic-domain-allowlist.txt')
}
@ -212,57 +180,78 @@ function getProxyExcludeIpStr (split) {
return excludeIpStr
}
async function _winSetProxy (exec, ip, port, setEnv) {
// 延迟加载config
loadConfig()
const proxyPath = extraPath.getProxyExePath()
const execFun = 'global'
// https
let proxyAddr = `https=http://${ip}:${port}`
// http
if (config.get().proxy.proxyHttp) {
proxyAddr = `http=http://${ip}:${port - 1};${proxyAddr}`
}
// 读取排除域名
const excludeIpStr = getProxyExcludeIpStr(';')
// 设置代理,同时设置排除域名
log.info(`执行“设置系统代理”的程序: ${proxyPath} ${execFun} ${proxyAddr} ......(省略排除IP列表)`)
await execFile(proxyPath, [execFun, proxyAddr, excludeIpStr])
if (setEnv) {
// 设置全局代理所需的环境变量
try {
await exec(`echo '设置环境变量 HTTPS_PROXY${config.get().proxy.proxyHttp ? '、HTTP_PROXY' : ''}'`)
log.info(`开启系统代理的同时设置环境变量HTTPS_PROXY = "http://${ip}:${port}/"`)
await exec(`setx HTTPS_PROXY "http://${ip}:${port}/"`)
if (config.get().proxy.proxyHttp) {
log.info(`开启系统代理的同时设置环境变量HTTP_PROXY = "http://${ip}:${port - 1}/"`)
await exec(`setx HTTP_PROXY "http://${ip}:${port - 1}/"`)
}
// await addClearScriptIni()
} catch (e) {
log.error('设置环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e)
}
}
return true
}
const executor = {
async windows (exec, params = {}) {
const sysproxy = require('@starknt/sysproxy')
const { ip, port, setEnv } = params
if (ip != null) { // 设置代理
// 延迟加载config
loadConfig()
log.info('设置windows系统代理:', ip, port, setEnv)
return _winSetProxy(exec, ip, port, setEnv)
// https
let proxyAddr = `https=http://${ip}:${port}`
// http
if (config.get().proxy.proxyHttp) {
proxyAddr = `http=http://${ip}:${port - 1};${proxyAddr}`
}
// 读取排除域名
const excludeIpStr = getProxyExcludeIpStr(';')
// 设置代理,同时设置排除域名
sysproxy.triggerManualProxyByUrl(true, proxyAddr, excludeIpStr)
if (setEnv) {
// 设置全局代理所需的环境变量
try {
await exec(`echo '设置环境变量 HTTPS_PROXY${config.get().proxy.proxyHttp ? '、HTTP_PROXY' : ''}'`)
log.info(`开启系统代理的同时设置环境变量HTTPS_PROXY = "http://${ip}:${port}/"`)
await exec(`setx HTTPS_PROXY "http://${ip}:${port}/"`)
if (config.get().proxy.proxyHttp) {
log.info(`开启系统代理的同时设置环境变量HTTP_PROXY = "http://${ip}:${port - 1}/"`)
await exec(`setx HTTP_PROXY "http://${ip}:${port - 1}/"`)
}
// await addClearScriptIni()
} catch (e) {
log.error('设置环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e)
}
}
return true
} else { // 关闭代理
log.info('关闭windows系统代理')
return _winUnsetProxy(exec, setEnv)
sysproxy.triggerManualProxy(false, '', 0, '')
try {
await exec('echo \'删除环境变量 HTTPS_PROXY、HTTP_PROXY\'')
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.warn('删除环境变量 HTTPS_PROXY 失败:', err)
await exec('setx DS_REFRESH "1"')
})
}
})
regKey.get('HTTP_PROXY', (err) => {
if (!err) {
regKey.remove('HTTP_PROXY', async (err) => {
log.warn('删除环境变量 HTTP_PROXY 失败:', err)
})
}
})
} catch (e) {
log.error('删除环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e)
}
return true
}
},
async linux (exec, params = {}) {

View File

@ -1,12 +1,9 @@
const childProcess = require('node:child_process')
const os = require('node:os')
const fixPath = require('fix-path')
const iconv = require('iconv-lite')
const PowerShell = require('node-powershell')
const log = require('../utils/util.log')
const _execFile = childProcess.execFile
fixPath()
class SystemShell {
@ -21,7 +18,7 @@ class LinuxSystemShell extends SystemShell {
cmds = [cmds]
}
for (const cmd of cmds) {
await _childExec(cmd, { shell: '/bin/bash' })
await childExec(cmd, { shell: '/bin/bash' })
}
}
}
@ -33,7 +30,7 @@ class DarwinSystemShell extends SystemShell {
}
let ret
for (const cmd of cmds) {
ret = await _childExec(cmd)
ret = await childExec(cmd)
}
return ret
}
@ -64,7 +61,7 @@ class WindowsSystemShell extends SystemShell {
ps.dispose()
}
} else {
let compose = 'echo "test" ' // 'chcp 65001 '
let compose = 'chcp 65001' // 'chcp 65001 '
for (const cmd of cmds) {
compose += ` && ${cmd}`
}
@ -76,9 +73,8 @@ class WindowsSystemShell extends SystemShell {
}
}
function _childExec (composeCmds, options = {}) {
function childExec (composeCmds, options = {}) {
return new Promise((resolve, reject) => {
const childProcess = require('node:child_process')
log.info('shell:', composeCmds)
childProcess.exec(composeCmds, options, (error, stdout, stderr) => {
if (error) {
@ -88,33 +84,7 @@ function _childExec (composeCmds, options = {}) {
reject(new Error(stderr))
} else {
// log.info('cmd 命令完成:', stdout)
resolve(stdout)
}
// log.info('关闭 cmd')
// ps.kill('SIGINT')
})
})
}
function childExec (composeCmds, options = {}) {
return new Promise((resolve, reject) => {
const encoding = 'cp936'
const binaryEncoding = 'binary'
const childProcess = require('node:child_process')
log.info('shell:', composeCmds)
childProcess.exec(composeCmds, { encoding: binaryEncoding }, (error, stdout, stderr) => {
if (error) {
// console.log('------', decoder.decode(stderr))
const message = iconv.decode(Buffer.from(stderr, binaryEncoding), encoding)
if (options.printErrorLog !== false) {
log.error('cmd 命令执行错误:\n------------------------------\ncommands:', composeCmds, '\n message:', message, '\n error:', error, '\n------------------------------')
}
reject(new Error(message))
} else {
// log.info('cmd 命令完成:', stdout)
const message = iconv.decode(Buffer.from(stdout, binaryEncoding), encoding)
resolve(message)
resolve(stdout.replace('Active code page: 65001\r\n', ''))
}
// log.info('关闭 cmd')
// ps.kill('SIGINT')
@ -135,6 +105,7 @@ function getSystemShell () {
throw new Error(`UNKNOWN OS TYPE ${os.platform()}`)
}
}
function getSystemPlatform () {
switch (os.platform()) {
case 'darwin':
@ -158,7 +129,7 @@ async function execute (executor, args) {
async function execFile (file, args, options) {
return new Promise((resolve, reject) => {
try {
_execFile(file, args, options, (err, stdout) => {
childProcess.execFile(file, args, options, (err, stdout) => {
if (err) {
log.error('文件执行出错:', file, err)
reject(err)

View File

@ -1,46 +0,0 @@
// const cmd1 = require('node-cmd')
// cmd1.get('set',
// function (err, data, stderr) {
// console.log('cmd complete:', err, data, stderr)
// if (err) {
// console.error('cmd 命令执行错误:', err, stderr)
// } else {
// console.log('cmd 命令执行结果:', data)
// }
// }
// )
// const process = require('child_process')
//
// const cmd = 'set'
// process.exec(cmd, function (error, stdout, stderr) {
// console.log('error:' + error)
// console.log('stdout:' + stdout)
// console.log('stderr:' + stderr)
// })
// const HttpsProxyAgent = require('https-proxy-agent')
// const proxy = 'http://user:pass@xxx.com:port'
// const agent = new HttpsProxyAgent(proxy)
// const https = require('https')
// https.get('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', (res) => {
// console.log('状态码:', res.statusCode)
// console.log('请求头:', res.headers)
//
// res.on('data', (d) => {
// process.stdout.write(d)
// })
// }).on('error', (e) => {
// console.error(e)
// })
const fs = require('node:fs')
const request = require('request')
request({
url: 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js',
proxy: 'http://127.0.0.1:31181',
ca: fs.readFileSync('C:/Users/Administrator/.dev-sidecar/dev-sidecar.ca.crt'),
}, (err, res, body) => {
console.log(body)
})

View File

@ -22,12 +22,12 @@
"dependencies": {
"@docmirror/dev-sidecar": "workspace:*",
"@docmirror/mitmproxy": "workspace:*",
"@mihomo-party/sysproxy": "^2.0.4",
"@natmri/platform-napi": "^0.0.7",
"@starknt/sysproxy": "^0.0.1",
"@vscode/sudo-prompt": "^9.3.1",
"adm-zip": "^0.5.16",
"ant-design-vue": "^1.7.8",
"electron-baidu-tongji": "^1.0.5",
"electron-sudo": "^4.0.12",
"electron-updater": "^6.3.9",
"json5": "^2.2.3",
"lodash": "^4.17.21",

View File

@ -211,8 +211,8 @@ function createWindow (startHideWindow) {
hideWin()
}
win.on('closed', async () => {
log.info('win closed:', arguments)
win.on('closed', async (...args) => {
log.info('win closed:', ...args)
win = null
tray = null
})
@ -225,8 +225,8 @@ function createWindow (startHideWindow) {
}
})
win.on('close', (e) => {
log.info('win close:', arguments)
win.on('close', (e, ...args) => {
log.info('win close:', e, ...args)
if (forceClose) {
return
}
@ -249,8 +249,8 @@ function createWindow (startHideWindow) {
}
})
win.on('session-end', async (e) => {
log.info('win session-end:', arguments)
win.on('session-end', async (e, ...args) => {
log.info('win session-end:', e, ...args)
await quit()
})
@ -289,8 +289,8 @@ function createWindow (startHideWindow) {
})
// 监听渲染进程发送过来的消息
win.webContents.on('ipc-message', (event, channel, message) => {
console.info('win ipc-message:', arguments)
win.webContents.on('ipc-message', (event, channel, message, ...args) => {
console.info('win ipc-message:', event, channel, message, ...args)
if (channel === 'change-showHideShortcut') {
registerShowHideShortcut(message)
}
@ -454,10 +454,7 @@ if (!isFirstInstance) {
e.preventDefault()
}
log.info('系统关机,恢复代理设置')
if (isWindows) {
const Sysproxy = require('@mihomo-party/sysproxy')
Sysproxy.triggerManualProxy(false, '', 0, '')
}
await quit()
})
})

View File

@ -1,14 +1,35 @@
/* global __static */
import DevSidecar from '@docmirror/dev-sidecar'
import Sudoer from 'electron-sudo'
import sudoPrompt from '@vscode/sudo-prompt'
import { join } from 'node:path'
import log from '../../utils/util.log'
export default {
async open () {
const options = { name: '设置loopback' }
const sudoer = new Sudoer(options)
open () {
const options = {
name: 'EnableLoopback',
icns: process.platform === 'darwin' ? join(__static, 'icon.icns') : undefined,
env: { PARAM: 'VALUE' },
}
const exeFile = DevSidecar.api.shell.extraPath.getEnableLoopbackPath()
await sudoer.exec(
exeFile,
{ env: { PARAM: 'VALUE' } },
)
const sudoCommand = [`"${exeFile}"`]
return new Promise((resolve, reject) => {
sudoPrompt.exec(
sudoCommand.join(' '),
options,
(error, _, stderr) => {
if (stderr) {
log.error(`[sudo-prompt] 发生错误: ${stderr}`)
}
if (error) {
reject(error)
} else {
resolve(undefined)
}
},
)
})
},
}

View File

@ -1,5 +1,6 @@
import { ipcRenderer, shell } from 'electron'
import lodash from 'lodash'
import path from 'node:path'
let inited = false
let apiObj = null
@ -31,7 +32,7 @@ export function apiInit (app) {
await shell.openExternal(href)
},
openPath (file) {
shell.openPath(file)
shell.openPath(path.resolve(file))
},
},
}

View File

@ -32,10 +32,6 @@ export default {
try {
await this.$api.proxy.setEnableLoopback()
} catch (e) {
if (e.message.includes('EACCES')) {
this.$message.error('请将DevSidecar关闭后以管理员身份重新打开再尝试此操作')
return
}
this.$message.error(`打开失败:${e.message}`)
}
},
@ -192,7 +188,6 @@ export default {
<div>
<div>1此设置用于解决OneNoteMicrosoftStoreOutlook等UWP应用无法访问网络的问题</div>
<div>2点击右上方按钮打开EnableLoopback然后按下图所示操作即可</div>
<div>3注意此操作需要<b style="color:red">DevSidecar以管理员身份启动</b>才能打开下面的EnableLoopback设置界面</div>
<img style="margin-top:20px;border:1px solid #eee" width="80%" src="loopback.png">
</div>
</a-drawer>

View File

@ -325,9 +325,6 @@ export default {
<a-button class="md-mr-10" icon="profile" @click="openLog()">
日志
</a-button>
<div class="form-help">
windows下建议开启开机自启<a @click="openExternal('https://github.com/docmirror/dev-sidecar/blob/master/doc/recover.md')"></a>
</div>
</a-form-item>
<a-form-item v-if="systemPlatform === 'mac'" label="隐藏Dock图标" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.app.dock.hideWhenWinClose">

View File

@ -37,14 +37,14 @@ module.exports = defineConfig({
// Ref: https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/1891
customFileProtocol: './',
externals: [
'@mihomo-party/sysproxy',
'@mihomo-party/sysproxy-win32-ia32-msvc',
'@mihomo-party/sysproxy-win32-x64-msvc',
'@mihomo-party/sysproxy-win32-arm64-msvc',
'@mihomo-party/sysproxy-linux-x64-gnu',
'@mihomo-party/sysproxy-linux-arm64-gnu',
'@mihomo-party/sysproxy-darwin-x64',
'@mihomo-party/sysproxy-darwin-arm64',
'@starknt/sysproxy',
'@starknt/sysproxy-win32-ia32-msvc',
'@starknt/sysproxy-win32-x64-msvc',
'@starknt/sysproxy-win32-arm64-msvc',
'@starknt/sysproxy-linux-x64-gnu',
'@starknt/sysproxy-linux-arm64-gnu',
'@starknt/sysproxy-darwin-x64',
'@starknt/sysproxy-darwin-arm64',
'@natmri/platform-napi',
'@natmri/platform-napi-win32-ia32-msvc',
'@natmri/platform-napi-win32-x64-msvc',
@ -77,7 +77,7 @@ module.exports = defineConfig({
appId: 'dev-sidecar',
productName: 'dev-sidecar',
// eslint-disable-next-line no-template-curly-in-string
artifactName: 'DevSidecar-${version}.${ext}',
artifactName: 'DevSidecar-${version}-${arch}.${ext}',
copyright: 'Copyright © 2020-2024 Greper, WangLiang',
nsis: {
oneClick: false,
@ -92,17 +92,31 @@ module.exports = defineConfig({
arch: 'universal',
target: 'dmg',
},
category: 'public.app-category.developer-tools',
},
win: {
icon: 'build/icons/',
target: [
{
target: 'nsis',
arch: ['x64', 'ia32', 'arm64'],
},
],
// requestedExecutionLevel: 'highestAvailable', // 加了这个无法开机自启
},
linux: {
icon: 'build/mac/',
target: [
'deb',
'AppImage',
{
target: 'deb',
arch: ['x64', 'arm64'],
},
{
target: 'AppImage',
arch: ['x64', 'arm64'],
},
],
category: 'System',
},
publish: {
provider: publishProvider,

15523
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff