refactor: 修复mac无法开启代理的bug
parent
7cf5c6119e
commit
8cd5708529
|
@ -198,6 +198,7 @@ module.exports = {
|
||||||
'gh.docmirror.top': 'usa'
|
'gh.docmirror.top': 'usa'
|
||||||
},
|
},
|
||||||
speedTest: {
|
speedTest: {
|
||||||
|
enabled: true,
|
||||||
hostnameList: ['github.com'],
|
hostnameList: ['github.com'],
|
||||||
dnsProviders: ['usa', 'quad9', 'rubyfish']
|
dnsProviders: ['usa', 'quad9', 'rubyfish']
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,8 +127,8 @@ const executor = {
|
||||||
},
|
},
|
||||||
async mac (exec, params) {
|
async mac (exec, params) {
|
||||||
// exec = _exec
|
// 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"')
|
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(3).trim()
|
||||||
|
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
await exec(`networksetup -setwebproxystate '${wifiAdaptor}' off`)
|
await exec(`networksetup -setwebproxystate '${wifiAdaptor}' off`)
|
||||||
|
|
|
@ -17,14 +17,14 @@ Vue.component(DsContainer)
|
||||||
const router = new VueRouter({
|
const router = new VueRouter({
|
||||||
routes // (缩写) 相当于 routes: routes
|
routes // (缩写) 相当于 routes: routes
|
||||||
})
|
})
|
||||||
|
const app = new Vue({
|
||||||
view.initApi().then(async (api) => {
|
|
||||||
// 初始化status
|
|
||||||
await view.initPre(Vue, api)
|
|
||||||
const app = new Vue({
|
|
||||||
router,
|
router,
|
||||||
render: h => h(App)
|
render: h => h(App)
|
||||||
}).$mount('#app')
|
})
|
||||||
|
view.initApi(app).then(async (api) => {
|
||||||
|
// 初始化status
|
||||||
|
await view.initPre(Vue, api)
|
||||||
|
app.$mount('#app')
|
||||||
view.initModules(app, router)
|
view.initModules(app, router)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
import lodash from 'lodash'
|
import lodash from 'lodash'
|
||||||
import { ipcRenderer, shell } from 'electron'
|
import { ipcRenderer, shell } from 'electron'
|
||||||
|
let inited = false
|
||||||
const invoke = (api, args) => {
|
let apiObj = null
|
||||||
return ipcRenderer.invoke('apiInvoke', [api, args]).catch(err => {
|
export function apiInit (app) {
|
||||||
console.error('api invoke error:', err)
|
const invoke = (api, args) => {
|
||||||
|
return ipcRenderer.invoke('apiInvoke', [api, args]).catch(e => {
|
||||||
|
app.$notification.error({
|
||||||
|
message: 'Api invoke error',
|
||||||
|
description: e.message
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
const send = (channel, message) => {
|
}
|
||||||
|
const send = (channel, message) => {
|
||||||
console.log('do send,', channel, message)
|
console.log('do send,', channel, message)
|
||||||
return ipcRenderer.send(channel, message)
|
return ipcRenderer.send(channel, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
const bindApi = (api, param1) => {
|
apiObj = {
|
||||||
lodash.set(apiObj, api, (param2) => {
|
|
||||||
return invoke(api, param2 || param1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const apiObj = {
|
|
||||||
ipc: {
|
ipc: {
|
||||||
on (channel, callback) {
|
on (channel, callback) {
|
||||||
ipcRenderer.on(channel, callback)
|
ipcRenderer.on(channel, callback)
|
||||||
|
@ -33,10 +33,14 @@ const apiObj = {
|
||||||
shell.openPath(file)
|
shell.openPath(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let inited = false
|
|
||||||
|
const bindApi = (api, param1) => {
|
||||||
|
lodash.set(apiObj, api, (param2) => {
|
||||||
|
return invoke(api, param2 || param1)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function apiInit () {
|
|
||||||
if (!inited) {
|
if (!inited) {
|
||||||
return invoke('getApiList').then(list => {
|
return invoke('getApiList').then(list => {
|
||||||
inited = true
|
inited = true
|
||||||
|
@ -52,4 +56,6 @@ export function apiInit () {
|
||||||
resolve(apiObj)
|
resolve(apiObj)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
export default apiObj
|
export function useApi () {
|
||||||
|
return apiObj
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import api, { apiInit } from './api'
|
import { apiInit, useApi } from './api'
|
||||||
import modules from '../bridge/front'
|
import modules from '../bridge/front'
|
||||||
import status from './status'
|
import status from './status'
|
||||||
export default {
|
export default {
|
||||||
|
@ -10,6 +10,7 @@ export default {
|
||||||
await status.install(api)
|
await status.install(api)
|
||||||
},
|
},
|
||||||
initModules (app, router) {
|
initModules (app, router) {
|
||||||
|
const api = useApi()
|
||||||
modules.install(app, api, router)
|
modules.install(app, api, router)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,10 +55,13 @@
|
||||||
</a-tab-pane>
|
</a-tab-pane>
|
||||||
<a-tab-pane tab="DNS设置" key="3">
|
<a-tab-pane tab="DNS设置" key="3">
|
||||||
<div>
|
<div>
|
||||||
<div>某些域名需要通过国外DNS服务器获取到IP列表中选取相对最优的IP进行访问</div>
|
|
||||||
<a-row style="margin-top:10px">
|
<a-row style="margin-top:10px">
|
||||||
<a-col>
|
<a-col span="19">
|
||||||
<a-button type="primary" icon="plus" @click="addDnsMapping()" />
|
<div>这里配置哪些域名需要通过国外DNS服务器获取IP进行访问</div>
|
||||||
|
</a-col>
|
||||||
|
<a-col span="3">
|
||||||
|
<a-button style="margin-left:8px" type="primary" icon="plus" @click="addDnsMapping()" />
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
<a-row :gutter="10" style="margin-top: 10px" v-for="(item,index) of dnsMappings" :key = 'index'>
|
<a-row :gutter="10" style="margin-top: 10px" v-for="(item,index) of dnsMappings" :key = 'index'>
|
||||||
|
@ -73,8 +76,8 @@
|
||||||
</a-select>
|
</a-select>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col :span="3">
|
<a-col :span="3">
|
||||||
<a-button v-if="item.value!==false" style="margin-left:10px" type="danger" icon="minus" @click="deleteDnsMapping(item,index)" />
|
<a-button v-if="item.value!==false" type="danger" icon="minus" @click="deleteDnsMapping(item,index)" />
|
||||||
<a-button v-if="item.value===false" style="margin-left:10px" type="primary" icon="checked" @click="restoreDefDnsMapping(item,index)" ></a-button>
|
<a-button v-if="item.value===false" type="primary" icon="checked" @click="restoreDefDnsMapping(item,index)" ></a-button>
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
|
|
||||||
|
@ -82,6 +85,12 @@
|
||||||
</a-tab-pane>
|
</a-tab-pane>
|
||||||
<a-tab-pane tab="DNS测速设置" key="4">
|
<a-tab-pane tab="DNS测速设置" key="4">
|
||||||
<div>
|
<div>
|
||||||
|
<a-alert type="info" message="对从dns获取到的ip进行测速,使用速度最快的ip进行访问。(对使用增强功能的域名没啥用)"></a-alert>
|
||||||
|
<a-form-item label="开启dns测速" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
|
<a-checkbox v-model="getSpeedTestConfig().enabled" >
|
||||||
|
启用
|
||||||
|
</a-checkbox>
|
||||||
|
</a-form-item>
|
||||||
<div>使用以下dns获取ip进行测速</div>
|
<div>使用以下dns获取ip进行测速</div>
|
||||||
<a-row style="margin-top:10px">
|
<a-row style="margin-top:10px">
|
||||||
<a-col span="24">
|
<a-col span="24">
|
||||||
|
|
18539
packages/gui/yarn.lock
18539
packages/gui/yarn.lock
File diff suppressed because it is too large
Load Diff
|
@ -70,7 +70,7 @@ module.exports = {
|
||||||
map[dnsProvider] = dnsMap[dnsProvider]
|
map[dnsProvider] = dnsMap[dnsProvider]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
speedTest.initSpeedTestPool({ hostnameList: speedTestConfig.hostnameList, dnsMap: map })
|
speedTest.initSpeedTest({ enabled: speedTestConfig.enabled, hostnameList: speedTestConfig.hostnameList, dnsMap: map })
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestHandler = createRequestHandler(
|
const requestHandler = createRequestHandler(
|
||||||
|
|
|
@ -1,21 +1,29 @@
|
||||||
const SpeedTester = require('./SpeedTester.js')
|
const SpeedTester = require('./SpeedTester.js')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
|
const log = require('../../utils/util.log.js')
|
||||||
const SpeedTestPool = {
|
const SpeedTestPool = {
|
||||||
|
|
||||||
}
|
}
|
||||||
function initSpeedTestPool ({ hostnameList, dnsMap }) {
|
function initSpeedTest ({ enabled, hostnameList, dnsMap }) {
|
||||||
config.getConfig().dnsMap = dnsMap
|
const conf = config.getConfig()
|
||||||
|
conf.enabled = enabled
|
||||||
|
if (!conf.enabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conf.dnsMap = dnsMap
|
||||||
_.forEach(hostnameList, (hostname) => {
|
_.forEach(hostnameList, (hostname) => {
|
||||||
SpeedTestPool[hostname] = new SpeedTester({ hostname })
|
SpeedTestPool[hostname] = new SpeedTester({ hostname })
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('[speed] dnsMap', dnsMap)
|
log.info('[speed] dnsMap', dnsMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllSpeedTester () {
|
function getAllSpeedTester () {
|
||||||
const allSpeed = {}
|
const allSpeed = {}
|
||||||
|
if (!config.getConfig().enabled) {
|
||||||
|
return allSpeed
|
||||||
|
}
|
||||||
_.forEach(SpeedTestPool, (item, key) => {
|
_.forEach(SpeedTestPool, (item, key) => {
|
||||||
allSpeed[key] = {
|
allSpeed[key] = {
|
||||||
hostname: key,
|
hostname: key,
|
||||||
|
@ -27,6 +35,9 @@ function getAllSpeedTester () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSpeedTester (hostname) {
|
function getSpeedTester (hostname) {
|
||||||
|
if (!config.getConfig().enabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
let instance = SpeedTestPool[hostname]
|
let instance = SpeedTestPool[hostname]
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new SpeedTester({ hostname })
|
instance = new SpeedTester({ hostname })
|
||||||
|
@ -55,7 +66,7 @@ function action (event) {
|
||||||
}
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
SpeedTester,
|
SpeedTester,
|
||||||
initSpeedTestPool,
|
initSpeedTest,
|
||||||
getSpeedTester,
|
getSpeedTester,
|
||||||
getAllSpeedTester,
|
getAllSpeedTester,
|
||||||
registerNotify,
|
registerNotify,
|
||||||
|
|
|
@ -30,7 +30,7 @@ const dnsMap = dns.initDNS({
|
||||||
// }
|
// }
|
||||||
})
|
})
|
||||||
|
|
||||||
SpeedTest.initSpeedTestPool({ hostnameList: {}, dnsMap })
|
SpeedTest.initSpeedTest({ hostnameList: {}, dnsMap })
|
||||||
|
|
||||||
const tester = new SpeedTester({ hostname: 'github.com' })
|
const tester = new SpeedTester({ hostname: 'github.com' })
|
||||||
tester.test().then(ret => {
|
tester.test().then(ret => {
|
||||||
|
|
Loading…
Reference in New Issue