feat: 初步支持mac
parent
cc65bebc5c
commit
113eb3622d
File diff suppressed because it is too large
Load Diff
|
@ -75,5 +75,5 @@
|
||||||
"last 2 versions",
|
"last 2 versions",
|
||||||
"not dead"
|
"not dead"
|
||||||
],
|
],
|
||||||
"gitHead": "50b256b12aa1e03fe565c3f7fda9ca9b862064c0"
|
"gitHead": "660c77e4279c1499f771270941526614f927bdf1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ const lodash = require('lodash')
|
||||||
const defConfig = require('./config/index.js')
|
const defConfig = require('./config/index.js')
|
||||||
const JSON5 = require('json5').default
|
const JSON5 = require('json5').default
|
||||||
|
|
||||||
console.log('JSON5', JSON5, JSON5.parse)
|
console.log('JSON5', JSON5)
|
||||||
let configTarget = lodash.cloneDeep(defConfig)
|
let configTarget = lodash.cloneDeep(defConfig)
|
||||||
|
|
||||||
function get () {
|
function get () {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const shell = require('../shell/shell')
|
||||||
function getUserBasePath () {
|
function getUserBasePath () {
|
||||||
const userHome = process.env.USERPROFILE
|
let userHome = process.env.USERPROFILE
|
||||||
|
if(shell.getSystemPlatform() === 'mac'){
|
||||||
|
userHome = process.env.HOME
|
||||||
|
}
|
||||||
return path.resolve(userHome, './.dev-sidecar')
|
return path.resolve(userHome, './.dev-sidecar')
|
||||||
}
|
}
|
||||||
function getRootCaCertPath () {
|
function getRootCaCertPath () {
|
||||||
|
|
|
@ -6,7 +6,11 @@ const fork = require('child_process').fork
|
||||||
const log = require('../../utils/util.log')
|
const log = require('../../utils/util.log')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const JSON5 = require('json5').default
|
let JSON5 = require('json5')
|
||||||
|
if (JSON5.default) {
|
||||||
|
JSON5 = JSON5.default
|
||||||
|
}
|
||||||
|
|
||||||
let server
|
let server
|
||||||
function fireStatus (status) {
|
function fireStatus (status) {
|
||||||
event.fire('status', { key: 'server.enabled', value: status })
|
event.fire('status', { key: 'server.enabled', value: status })
|
||||||
|
|
|
@ -9,6 +9,9 @@ const refreshInternetPs = require('./refresh-internet')
|
||||||
const PowerShell = require('node-powershell')
|
const PowerShell = require('node-powershell')
|
||||||
const log = require('../../../utils/util.log')
|
const log = require('../../../utils/util.log')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const childProcess = require('child_process')
|
||||||
|
const util = require('util')
|
||||||
|
const _exec = util.promisify(childProcess.exec)
|
||||||
const _lanIP = [
|
const _lanIP = [
|
||||||
'localhost',
|
'localhost',
|
||||||
'127.*',
|
'127.*',
|
||||||
|
@ -119,11 +122,22 @@ const executor = {
|
||||||
return _winSetProxy(exec, ip, port)
|
return _winSetProxy(exec, ip, port)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async linux (exec, { port }) {
|
async linux (exec, params) {
|
||||||
throw Error('暂未实现此功能')
|
throw Error('暂未实现此功能')
|
||||||
},
|
},
|
||||||
async mac (exec, { port }) {
|
async mac (exec, params) {
|
||||||
throw Error('暂未实现此功能')
|
// 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 | cut -d \' \' -f2"')
|
||||||
|
wifiAdaptor = wifiAdaptor.trim()
|
||||||
|
|
||||||
|
if (params == null) {
|
||||||
|
await exec(`networksetup -setwebproxystate '${wifiAdaptor}' off`)
|
||||||
|
await exec(`networksetup -setsecurewebproxystate '${wifiAdaptor}' off`)
|
||||||
|
} else {
|
||||||
|
const { ip, port } = params
|
||||||
|
await exec(`networksetup -setwebproxy '${wifiAdaptor}' ${ip} ${port}`)
|
||||||
|
await exec(`networksetup -setsecurewebproxy '${wifiAdaptor}' ${ip} ${port}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,23 +14,25 @@ class SystemShell {
|
||||||
|
|
||||||
class LinuxSystemShell extends SystemShell {
|
class LinuxSystemShell extends SystemShell {
|
||||||
static async exec (cmds) {
|
static async exec (cmds) {
|
||||||
if (cmds instanceof String) {
|
if (typeof cmds === 'string') {
|
||||||
cmds = [cmds]
|
cmds = [cmds]
|
||||||
}
|
}
|
||||||
for (const cmd of cmds) {
|
for (const cmd of cmds) {
|
||||||
await exec(cmd)
|
await childExec(cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DarwinSystemShell extends SystemShell {
|
class DarwinSystemShell extends SystemShell {
|
||||||
static async exec (cmds) {
|
static async exec (cmds) {
|
||||||
if (cmds instanceof String) {
|
if (typeof cmds === 'string') {
|
||||||
cmds = [cmds]
|
cmds = [cmds]
|
||||||
}
|
}
|
||||||
|
let ret
|
||||||
for (const cmd of cmds) {
|
for (const cmd of cmds) {
|
||||||
await exec(cmd)
|
ret = await childExec(cmd)
|
||||||
}
|
}
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const server = require('@docmirror/mitmproxy')
|
const server = require('@docmirror/mitmproxy')
|
||||||
const JSON5 = require('json5').default
|
const JSON5 = require('json5')
|
||||||
let configPath = 'C:/Users/Administrator/.dev-sidecar/running.json'
|
const path = require('path')
|
||||||
|
const home = process.env.HOME
|
||||||
|
let configPath = path.join(home, '.dev-sidecar/running.json')
|
||||||
if (process.argv && process.argv.length > 3) {
|
if (process.argv && process.argv.length > 3) {
|
||||||
configPath = process.argv[2]
|
configPath = process.argv[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
|
||||||
const configJson = fs.readFileSync(configPath)
|
const configJson = fs.readFileSync(configPath)
|
||||||
const config = JSON5.parse(configJson)
|
const config = JSON5.parse(configJson)
|
||||||
const scriptDir = '../../gui/extra/scripts/'
|
const scriptDir = '../../gui/extra/scripts/'
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
const childProcess = require('child_process')
|
||||||
|
const util = require('util')
|
||||||
|
const exec = util.promisify(childProcess.exec)
|
||||||
|
|
||||||
|
async function test () {
|
||||||
|
const 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 | cut -d \' \' -f2"')).stdout.trim()
|
||||||
|
|
||||||
|
await exec(`networksetup -setwebproxystate '${wifiAdaptor}' off`)
|
||||||
|
return await exec(`networksetup -setsecurewebproxystate '${wifiAdaptor}' off`)
|
||||||
|
}
|
||||||
|
test().then((ret) => {
|
||||||
|
console.log('haha', ret)
|
||||||
|
})
|
|
@ -93,10 +93,10 @@
|
||||||
lodash "^4.17.19"
|
lodash "^4.17.19"
|
||||||
to-fast-properties "^2.0.0"
|
to-fast-properties "^2.0.0"
|
||||||
|
|
||||||
"@docmirror/mitmproxy@^1.3.2":
|
"@docmirror/mitmproxy@^1.3.3":
|
||||||
version "1.3.2"
|
version "1.3.3"
|
||||||
resolved "https://registry.npmjs.org/@docmirror/mitmproxy/-/mitmproxy-1.3.2.tgz#380e230348380b5a4c8e4e3ddec789ef352a2961"
|
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.3.3.tgz#dcef8fb8d4d552f556a6c60691db4d887efa40c6"
|
||||||
integrity sha512-GP5fNr1KTiVz3Z/Vb5IqCn2FrUw1mIrXKWn4v90YvEKVGjEGSmfvZr8nqypnomiZ7HA4xTQKFLxXf+sYYtTl2A==
|
integrity sha512-YZdVaw3h+zv4Nq70JE4kwAMAtJJyCySSUI2NggG+y6dlr3Pztz7/yQG5Dx6WWYnUmfCWzDO+V3yHkxMBJ/ffGQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
agentkeepalive "^2.1.1"
|
agentkeepalive "^2.1.1"
|
||||||
child_process "^1.0.2"
|
child_process "^1.0.2"
|
||||||
|
|
|
@ -119,9 +119,32 @@ async function quit (app, callback) {
|
||||||
tray.displayBalloon({ title: '正在关闭', content: '关闭中,请稍候。。。' })
|
tray.displayBalloon({ title: '正在关闭', content: '关闭中,请稍候。。。' })
|
||||||
}
|
}
|
||||||
await beforeQuit()
|
await beforeQuit()
|
||||||
|
forceClose = true
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
function setDock () {
|
||||||
|
const { app, Menu } = require('electron')
|
||||||
|
|
||||||
|
const dockMenu = Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: 'New Window',
|
||||||
|
click () { console.log('New Window') }
|
||||||
|
}, {
|
||||||
|
label: 'New Window with Settings',
|
||||||
|
submenu: [
|
||||||
|
{ label: 'Basic' },
|
||||||
|
{ label: 'Pro' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ label: '退出' }
|
||||||
|
])
|
||||||
|
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
app.dock.setMenu(dockMenu)
|
||||||
|
})
|
||||||
|
}
|
||||||
// -------------执行开始---------------
|
// -------------执行开始---------------
|
||||||
app.disableHardwareAcceleration() // 禁用gpu
|
app.disableHardwareAcceleration() // 禁用gpu
|
||||||
|
|
||||||
|
@ -135,6 +158,9 @@ if (!isFirstInstance) {
|
||||||
} else {
|
} else {
|
||||||
app.on('before-quit', async (event) => {
|
app.on('before-quit', async (event) => {
|
||||||
log.info('before-quit')
|
log.info('before-quit')
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
quit(app)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||||
log.info('new app started', commandLine)
|
log.info('new app started', commandLine)
|
||||||
|
@ -156,11 +182,15 @@ if (!isFirstInstance) {
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
// On macOS it's common to re-create a window in the app when the
|
// On macOS it's common to re-create a window in the app when the
|
||||||
// dock icon is clicked and there are no other windows open.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (win === null) {
|
if (win == null) {
|
||||||
createWindow()
|
createWindow()
|
||||||
|
} else {
|
||||||
|
win.show()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// setDock()
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
|
@ -175,7 +205,7 @@ if (!isFirstInstance) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
createWindow()
|
createWindow()
|
||||||
const context = { win, app, beforeQuit, ipcMain, dialog,log }
|
const context = { win, app, beforeQuit, ipcMain, dialog, log }
|
||||||
backend.install(context) // 模块安装
|
backend.install(context) // 模块安装
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.info('err', err)
|
log.info('err', err)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<ds-container>
|
<ds-container>
|
||||||
<template slot="header">
|
<template slot="header">
|
||||||
Ladder
|
梯子
|
||||||
<span>
|
<span>
|
||||||
<a-button type="primary" @click="openExternal('https://github.com/docmirror/dev-sidecar-doc/blob/main/ow.md')">原理说明</a-button>
|
<a-button type="primary" @click="openExternal('https://github.com/docmirror/dev-sidecar-doc/blob/main/ow.md')">原理说明</a-button>
|
||||||
</span>
|
</span>
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
<div v-if="config">
|
<div v-if="config">
|
||||||
<a-form layout="horizontal">
|
<a-form layout="horizontal">
|
||||||
<a-form-item label="Ladder" :label-col="labelCol" :wrapper-col="wrapperCol">
|
<a-form-item label="梯子" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
<a-checkbox v-model="config.plugin.overwall.enabled">
|
<a-checkbox v-model="config.plugin.overwall.enabled">
|
||||||
启用
|
启用
|
||||||
</a-checkbox>
|
</a-checkbox>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -64,5 +64,5 @@
|
||||||
"last 2 versions",
|
"last 2 versions",
|
||||||
"not dead"
|
"not dead"
|
||||||
],
|
],
|
||||||
"gitHead": "50b256b12aa1e03fe565c3f7fda9ca9b862064c0"
|
"gitHead": "660c77e4279c1499f771270941526614f927bdf1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ config.setDefaultCABasePath = function (path) {
|
||||||
config.caBasePath = path
|
config.caBasePath = path
|
||||||
}
|
}
|
||||||
function buildDefaultCABasePath () {
|
function buildDefaultCABasePath () {
|
||||||
const userHome = process.env.USERPROFILE
|
const userHome = process.env.USERPROFILE || process.env.HOME
|
||||||
return path.resolve(userHome, './.dev-sidecar')
|
return path.resolve(userHome, './.dev-sidecar')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue