refactor: 根证书安装提示
parent
3dbd9634dc
commit
bc3f58f0db
|
@ -74,7 +74,7 @@ function createWindow () {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
width: 900,
|
width: 900,
|
||||||
height: 700,
|
height: 750,
|
||||||
title: 'DevSidecar',
|
title: 'DevSidecar',
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
enableRemoteModule: true,
|
enableRemoteModule: true,
|
||||||
|
|
|
@ -24,14 +24,18 @@ const localApi = {
|
||||||
*/
|
*/
|
||||||
setting: {
|
setting: {
|
||||||
load () {
|
load () {
|
||||||
const settingPath = _getSettingPath()
|
const settingPath = _getSettingsPath()
|
||||||
|
if (!fs.existsSync(settingPath)) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
const file = fs.readFileSync(settingPath)
|
const file = fs.readFileSync(settingPath)
|
||||||
const settings = JSON5.parse(file.toString())
|
const setting = JSON5.parse(file.toString())
|
||||||
return settings || {}
|
console.log('read file,', file.toString(), setting)
|
||||||
|
return setting || {}
|
||||||
},
|
},
|
||||||
save (settings = {}) {
|
save (setting = {}) {
|
||||||
const settingPath = _getSettingPath()
|
const settingPath = _getSettingsPath()
|
||||||
fs.writeFileSync(settingPath, JSON5.stringify(settings, null, 2))
|
fs.writeFileSync(settingPath, JSON5.stringify(setting, null, 2))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -98,7 +102,7 @@ function _deepFindFunction (list, parent, parentKey) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getSettingPath () {
|
function _getSettingsPath () {
|
||||||
const dir = './config/'
|
const dir = './config/'
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
fs.mkdirSync(dir)
|
fs.mkdirSync(dir)
|
||||||
|
|
|
@ -16,11 +16,10 @@ Vue.component(DsContainer)
|
||||||
const router = new VueRouter({
|
const router = new VueRouter({
|
||||||
routes // (缩写) 相当于 routes: routes
|
routes // (缩写) 相当于 routes: routes
|
||||||
})
|
})
|
||||||
Vue.prototype.$global = {}
|
|
||||||
view.initApi().then(async (api) => {
|
view.initApi().then(async (api) => {
|
||||||
Vue.prototype.$api = api
|
|
||||||
// 初始化status
|
// 初始化status
|
||||||
await view.initPre(api)
|
await view.initPre(Vue, api)
|
||||||
const app = new Vue({
|
const app = new Vue({
|
||||||
router,
|
router,
|
||||||
render: h => h(App)
|
render: h => h(App)
|
||||||
|
|
|
@ -102,7 +102,7 @@ import vueJsonEditor from 'vue-json-editor'
|
||||||
import lodash from 'lodash'
|
import lodash from 'lodash'
|
||||||
import api from '../api'
|
import api from '../api'
|
||||||
export default {
|
export default {
|
||||||
name: 'settings',
|
name: 'setting',
|
||||||
components: {
|
components: {
|
||||||
vueJsonEditor
|
vueJsonEditor
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
:visible="visible"
|
:visible="visible"
|
||||||
:after-visible-change="afterVisibleChange"
|
:after-visible-change="afterVisibleChange"
|
||||||
@close="onClose"
|
@close="onClose"
|
||||||
width="650px"
|
width="660px"
|
||||||
height="100%"
|
height="100%"
|
||||||
:slots="{ title: 'title' }"
|
:slots="{ title: 'title' }"
|
||||||
wrapClassName="json-wrapper"
|
wrapClassName="json-wrapper"
|
||||||
|
@ -14,6 +14,10 @@
|
||||||
{{title}}
|
{{title}}
|
||||||
<a-button type="primary" style="float:right" @click="doSetup()">点此去安装</a-button>
|
<a-button type="primary" style="float:right" @click="doSetup()">点此去安装</a-button>
|
||||||
</template>
|
</template>
|
||||||
|
<div>
|
||||||
|
请按如下步骤将<b>本地随机生成</b>的根证书添加到<b>信任的根证书颁发机构</b><br/>
|
||||||
|
证书是本地随机生成,所以信任它是安全的
|
||||||
|
</div>
|
||||||
<img width="100%" src="/setup.png" />
|
<img width="100%" src="/setup.png" />
|
||||||
|
|
||||||
</a-drawer>
|
</a-drawer>
|
||||||
|
@ -50,8 +54,9 @@ export default {
|
||||||
onClose () {
|
onClose () {
|
||||||
this.$emit('update:visible', false)
|
this.$emit('update:visible', false)
|
||||||
},
|
},
|
||||||
doSetup () {
|
async doSetup () {
|
||||||
api.shell.setupCa()
|
await api.shell.setupCa()
|
||||||
|
this.$emit('setup')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@ import modules from './modules'
|
||||||
import status from './status'
|
import status from './status'
|
||||||
export default {
|
export default {
|
||||||
initApi: apiInit,
|
initApi: apiInit,
|
||||||
async initPre (api) {
|
async initPre (Vue, api) {
|
||||||
|
Vue.prototype.$api = api
|
||||||
|
const setting = await api.setting.load()
|
||||||
|
Vue.prototype.$global = { setting }
|
||||||
await status.install(api)
|
await status.install(api)
|
||||||
},
|
},
|
||||||
initModules (app) {
|
initModules (app) {
|
||||||
|
|
|
@ -3,10 +3,17 @@
|
||||||
<template slot="header">
|
<template slot="header">
|
||||||
给开发者的辅助工具
|
给开发者的辅助工具
|
||||||
<span>
|
<span>
|
||||||
<a-button style="margin-right:10px" @click="openSetupCa">安装根证书</a-button>
|
|
||||||
<a-badge :count="update.newVersion?1:0" dot>
|
<a-button style="margin-right:10px" @click="openSetupCa">
|
||||||
<a-button style="margin-right:10px" @click="doCheckUpdate">检查更新</a-button>
|
<a-badge :count="_rootCaSetuped?0:1" dot>安装根证书 </a-badge>
|
||||||
</a-badge>
|
</a-button>
|
||||||
|
|
||||||
|
<a-button style="margin-right:10px" @click="doCheckUpdate">
|
||||||
|
<a-badge :count="update.newVersion?1:0" dot>
|
||||||
|
检查更新
|
||||||
|
</a-badge>
|
||||||
|
</a-button>
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -35,7 +42,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<setup-ca title="安装证书" :visible.sync="setupCa.visible"></setup-ca>
|
<setup-ca title="安装证书" :visible.sync="setupCa.visible" @setup="handleCaSetuped"></setup-ca>
|
||||||
</ds-container>
|
</ds-container>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
@ -51,6 +58,14 @@ export default {
|
||||||
DsContainer,
|
DsContainer,
|
||||||
setupCa
|
setupCa
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
_rootCaSetuped () {
|
||||||
|
if (this.setting && this.setting.rootCa) {
|
||||||
|
return this.setting.rootCa.setuped === true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
status: undefined,
|
status: undefined,
|
||||||
|
@ -67,6 +82,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setting: undefined,
|
||||||
server: {
|
server: {
|
||||||
key: '代理服务',
|
key: '代理服务',
|
||||||
loading: false,
|
loading: false,
|
||||||
|
@ -83,6 +99,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async created () {
|
async created () {
|
||||||
|
this.doCheckRootCa()
|
||||||
console.log('index created', this.status, this.$status)
|
console.log('index created', this.status, this.$status)
|
||||||
await this.reloadConfig()
|
await this.reloadConfig()
|
||||||
const status = await this.$api.status.get()
|
const status = await this.$api.status.get()
|
||||||
|
@ -106,6 +123,40 @@ export default {
|
||||||
console.log('index mounted')
|
console.log('index mounted')
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
doCheckRootCa () {
|
||||||
|
this.$api.setting.load().then(setting => {
|
||||||
|
console.log('setting', setting)
|
||||||
|
this.setting = setting
|
||||||
|
if (this.setting.rootCa && (this.setting.rootCa.setuped || this.setting.rootCa.noTip)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.$confirm({
|
||||||
|
title: '提示',
|
||||||
|
content: '第一次使用,请先安装CA根证书',
|
||||||
|
cancelText: '关闭此提示',
|
||||||
|
okText: '去安装',
|
||||||
|
onOk: () => {
|
||||||
|
this.openSetupCa()
|
||||||
|
},
|
||||||
|
onCancel: () => {
|
||||||
|
this.setting.rootCa = this.setting.rootCa || {}
|
||||||
|
const rootCa = this.setting.rootCa
|
||||||
|
rootCa.noTip = true
|
||||||
|
this.$api.setting.save(this.setting)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
openSetupCa () {
|
||||||
|
this.setupCa.visible = true
|
||||||
|
},
|
||||||
|
handleCaSetuped () {
|
||||||
|
this.setting.rootCa = this.setting.rootCa || {}
|
||||||
|
const rootCa = this.setting.rootCa
|
||||||
|
rootCa.setuped = true
|
||||||
|
this.$set(this, 'setting', this.setting)
|
||||||
|
this.$api.setting.save(this.setting)
|
||||||
|
},
|
||||||
reloadConfig () {
|
reloadConfig () {
|
||||||
return this.$api.config.reload().then(ret => {
|
return this.$api.config.reload().then(ret => {
|
||||||
this.config = ret
|
this.config = ret
|
||||||
|
@ -161,7 +212,7 @@ export default {
|
||||||
this.apiCall(this.startup, this.$api.startup)
|
this.apiCall(this.startup, this.$api.startup)
|
||||||
},
|
},
|
||||||
openSettings () {
|
openSettings () {
|
||||||
this.settings.visible = true
|
this.setting.visible = true
|
||||||
},
|
},
|
||||||
onConfigChanged (newConfig) {
|
onConfigChanged (newConfig) {
|
||||||
console.log('config changed', newConfig)
|
console.log('config changed', newConfig)
|
||||||
|
@ -171,9 +222,6 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
openSetupCa () {
|
|
||||||
this.setupCa.visible = true
|
|
||||||
},
|
|
||||||
doCheckUpdate (fromUser = true) {
|
doCheckUpdate (fromUser = true) {
|
||||||
this.update.fromUser = fromUser
|
this.update.fromUser = fromUser
|
||||||
this.$api.update.checkForUpdate(this.update)
|
this.$api.update.checkForUpdate(this.update)
|
||||||
|
|
Loading…
Reference in New Issue