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