feat: 初步支持mac

pull/67/head
xiaojunnuo 2020-12-30 00:14:33 +08:00
parent cc65bebc5c
commit 113eb3622d
15 changed files with 644 additions and 12578 deletions

File diff suppressed because it is too large Load Diff

View File

@ -75,5 +75,5 @@
"last 2 versions",
"not dead"
],
"gitHead": "50b256b12aa1e03fe565c3f7fda9ca9b862064c0"
"gitHead": "660c77e4279c1499f771270941526614f927bdf1"
}

View File

@ -4,7 +4,7 @@ const lodash = require('lodash')
const defConfig = require('./config/index.js')
const JSON5 = require('json5').default
console.log('JSON5', JSON5, JSON5.parse)
console.log('JSON5', JSON5)
let configTarget = lodash.cloneDeep(defConfig)
function get () {

View File

@ -1,6 +1,10 @@
const path = require('path')
const shell = require('../shell/shell')
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')
}
function getRootCaCertPath () {

View File

@ -6,7 +6,11 @@ const fork = require('child_process').fork
const log = require('../../utils/util.log')
const fs = require('fs')
const path = require('path')
const JSON5 = require('json5').default
let JSON5 = require('json5')
if (JSON5.default) {
JSON5 = JSON5.default
}
let server
function fireStatus (status) {
event.fire('status', { key: 'server.enabled', value: status })

View File

@ -9,6 +9,9 @@ const refreshInternetPs = require('./refresh-internet')
const PowerShell = require('node-powershell')
const log = require('../../../utils/util.log')
const path = require('path')
const childProcess = require('child_process')
const util = require('util')
const _exec = util.promisify(childProcess.exec)
const _lanIP = [
'localhost',
'127.*',
@ -119,11 +122,22 @@ const executor = {
return _winSetProxy(exec, ip, port)
}
},
async linux (exec, { port }) {
async linux (exec, params) {
throw Error('暂未实现此功能')
},
async mac (exec, { port }) {
throw Error('暂未实现此功能')
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 | 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}`)
}
}
}

View File

@ -14,23 +14,25 @@ class SystemShell {
class LinuxSystemShell extends SystemShell {
static async exec (cmds) {
if (cmds instanceof String) {
if (typeof cmds === 'string') {
cmds = [cmds]
}
for (const cmd of cmds) {
await exec(cmd)
await childExec(cmd)
}
}
}
class DarwinSystemShell extends SystemShell {
static async exec (cmds) {
if (cmds instanceof String) {
if (typeof cmds === 'string') {
cmds = [cmds]
}
let ret
for (const cmd of cmds) {
await exec(cmd)
ret = await childExec(cmd)
}
return ret
}
}

View File

@ -1,13 +1,14 @@
// eslint-disable-next-line no-unused-vars
const server = require('@docmirror/mitmproxy')
const JSON5 = require('json5').default
let configPath = 'C:/Users/Administrator/.dev-sidecar/running.json'
const JSON5 = require('json5')
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) {
configPath = process.argv[2]
}
const fs = require('fs')
const path = require('path')
const configJson = fs.readFileSync(configPath)
const config = JSON5.parse(configJson)
const scriptDir = '../../gui/extra/scripts/'

View File

@ -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)
})

View File

@ -93,10 +93,10 @@
lodash "^4.17.19"
to-fast-properties "^2.0.0"
"@docmirror/mitmproxy@^1.3.2":
version "1.3.2"
resolved "https://registry.npmjs.org/@docmirror/mitmproxy/-/mitmproxy-1.3.2.tgz#380e230348380b5a4c8e4e3ddec789ef352a2961"
integrity sha512-GP5fNr1KTiVz3Z/Vb5IqCn2FrUw1mIrXKWn4v90YvEKVGjEGSmfvZr8nqypnomiZ7HA4xTQKFLxXf+sYYtTl2A==
"@docmirror/mitmproxy@^1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.3.3.tgz#dcef8fb8d4d552f556a6c60691db4d887efa40c6"
integrity sha512-YZdVaw3h+zv4Nq70JE4kwAMAtJJyCySSUI2NggG+y6dlr3Pztz7/yQG5Dx6WWYnUmfCWzDO+V3yHkxMBJ/ffGQ==
dependencies:
agentkeepalive "^2.1.1"
child_process "^1.0.2"

View File

@ -119,9 +119,32 @@ async function quit (app, callback) {
tray.displayBalloon({ title: '正在关闭', content: '关闭中,请稍候。。。' })
}
await beforeQuit()
forceClose = true
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
@ -135,6 +158,9 @@ if (!isFirstInstance) {
} else {
app.on('before-quit', async (event) => {
log.info('before-quit')
if (process.platform === 'darwin') {
quit(app)
}
})
app.on('second-instance', (event, commandLine, workingDirectory) => {
log.info('new app started', commandLine)
@ -156,11 +182,15 @@ if (!isFirstInstance) {
app.on('activate', () => {
// 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.
if (win === null) {
if (win == null) {
createWindow()
} else {
win.show()
}
})
// setDock()
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
@ -175,7 +205,7 @@ if (!isFirstInstance) {
}
try {
createWindow()
const context = { win, app, beforeQuit, ipcMain, dialog,log }
const context = { win, app, beforeQuit, ipcMain, dialog, log }
backend.install(context) // 模块安装
} catch (err) {
log.info('err', err)

View File

@ -1,7 +1,7 @@
<template>
<ds-container>
<template slot="header">
Ladder
梯子
<span>
<a-button type="primary" @click="openExternal('https://github.com/docmirror/dev-sidecar-doc/blob/main/ow.md')"></a-button>
</span>
@ -9,7 +9,7 @@
<div v-if="config">
<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>

File diff suppressed because it is too large Load Diff

View File

@ -64,5 +64,5 @@
"last 2 versions",
"not dead"
],
"gitHead": "50b256b12aa1e03fe565c3f7fda9ca9b862064c0"
"gitHead": "660c77e4279c1499f771270941526614f927bdf1"
}

View File

@ -18,7 +18,7 @@ config.setDefaultCABasePath = function (path) {
config.caBasePath = path
}
function buildDefaultCABasePath () {
const userHome = process.env.USERPROFILE
const userHome = process.env.USERPROFILE || process.env.HOME
return path.resolve(userHome, './.dev-sidecar')
}