fix: 修复系统代理开关状态不会实时显示的bug,增加更新版本进度条

pull/180/head
xiaojunnuo 2020-11-24 00:24:57 +08:00
parent 5e80350827
commit 0c3be78ba3
5 changed files with 27 additions and 28 deletions

View File

@ -21,7 +21,7 @@ const ProxyPlugin = function (context) {
async unsetProxy () { async unsetProxy () {
try { try {
await shell.setSystemProxy() await shell.setSystemProxy()
event.fire('status', { key: 'proxy.enabled', vlaue: false }) event.fire('status', { key: 'proxy.enabled', value: false })
log.info('关闭系统代理成功') log.info('关闭系统代理成功')
return true return true
} catch (err) { } catch (err) {

View File

@ -1,6 +1,6 @@
{ {
"name": "@docmirror/dev-sidecar-gui", "name": "@docmirror/dev-sidecar-gui",
"version": "1.2.1", "version": "1.2.0",
"private": false, "private": false,
"license": "MPL-2.0", "license": "MPL-2.0",
"scripts": { "scripts": {

View File

@ -190,8 +190,8 @@ if (!isFirstInstance) {
return true return true
} }
}) })
// updateUrl = 'https://dev-sidecar.docmirror.cn/update/' updateUrl = 'https://dev-sidecar.docmirror.cn/update/'
updateUrl = 'http://localhost/dev-sidecar/' // updateUrl = 'http://localhost/dev-sidecar/'
} }
// 自动更新 // 自动更新
updateHandle(app, win, beforeQuit, updateUrl) updateHandle(app, win, beforeQuit, updateUrl)

View File

@ -1,13 +1,16 @@
let updateParams = { }
function install (app, api) { function install (app, api) {
const updateParams = app.$global.update = { fromUser: false, autoDownload: true, progress: 0, downloading: false, newVersion: false }
api.ipc.on('update', (event, message) => { api.ipc.on('update', (event, message) => {
console.log('on message', event, message) console.log('on message', event, message)
handleUpdateMessage(message, app) handleUpdateMessage(message, app)
}) })
api.update = { api.update = {
checkForUpdate (params) { checkForUpdate (fromUser) {
updateParams = params || { fromUser: false, autoDownload: true, progress: 0 } if (fromUser != null) {
updateParams.fromUser = fromUser
}
api.ipc.send('update', { key: 'checkForUpdate' }) api.ipc.send('update', { key: 'checkForUpdate' })
}, },
downloadUpdate () { downloadUpdate () {
@ -26,6 +29,8 @@ function install (app, api) {
noNewVersion() noNewVersion()
} else if (type === 'downloaded') { } else if (type === 'downloaded') {
// 更新包已下载完成,让用户确认是否更新 // 更新包已下载完成,让用户确认是否更新
updateParams.downloading = false
console.log('updateParams', updateParams)
newUpdateIsReady(message.value) newUpdateIsReady(message.value)
} else if (type === 'progress') { } else if (type === 'progress') {
progressUpdate(message.value) progressUpdate(message.value)
@ -50,6 +55,7 @@ function install (app, api) {
if (updateParams.autoDownload !== false) { if (updateParams.autoDownload !== false) {
app.$message.info('发现新版本,正在下载中...') app.$message.info('发现新版本,正在下载中...')
updateParams.downloading = true
api.update.downloadUpdate() api.update.downloadUpdate()
return return
} }
@ -70,6 +76,7 @@ function install (app, api) {
} }
function newUpdateIsReady (value) { function newUpdateIsReady (value) {
updateParams.downloading = false
app.$confirm({ app.$confirm({
title: '新版本已准备好', title: '新版本已准备好',
content: `是否立即升级安装v${value.version}?`, content: `是否立即升级安装v${value.version}?`,

View File

@ -8,9 +8,9 @@
<a-badge :count="_rootCaSetuped?0:1" dot>安装根证书 </a-badge> <a-badge :count="_rootCaSetuped?0:1" dot>安装根证书 </a-badge>
</a-button> </a-button>
<a-button style="margin-right:10px" @click="doCheckUpdate" :title="'当前版本:'+info.version"> <a-button style="margin-right:10px" @click="doCheckUpdate(true)" :loading="update.downloading" :title="'当前版本:'+info.version">
<a-badge :count="update.newVersion?1:0" dot> <a-badge :count="update.newVersion?1:0" dot>
检查更新 <span v-if="update.downloading">{{update.progress}}%</span>{{update.downloading?'':''}}
</a-badge> </a-badge>
</a-button> </a-button>
@ -31,7 +31,7 @@
<a-form style="margin-top:20px" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }"> <a-form style="margin-top:20px" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
<a-form-item v-for=" (item, key) in switchBtns" :key="key" :label="item.label"> <a-form-item v-for=" (item, key) in switchBtns" :key="key" :label="item.label">
<a-switch style="margin-left:10px" :loading="item.loading" v-model="item.status[key].enabled" default-checked v-on:click="item.doClick"> <a-switch style="margin-left:10px" :loading="item.loading" :checked="item.status()" default-checked @change="item.doClick">
<a-icon slot="checkedChildren" type="check"/> <a-icon slot="checkedChildren" type="check"/>
<a-icon slot="unCheckedChildren" type="close"/> <a-icon slot="unCheckedChildren" type="close"/>
</a-switch> </a-switch>
@ -57,7 +57,6 @@
import lodash from 'lodash' import lodash from 'lodash'
import setupCa from '../components/setup-ca' import setupCa from '../components/setup-ca'
import DsContainer from '../components/container' import DsContainer from '../components/container'
export default { export default {
name: 'Index', name: 'Index',
components: { components: {
@ -89,6 +88,7 @@ export default {
} }
}, },
info: {}, info: {},
newVersionDownloading: false,
setting: undefined, setting: undefined,
server: { server: {
key: '代理服务', key: '代理服务',
@ -102,30 +102,20 @@ export default {
setupCa: { setupCa: {
visible: false visible: false
}, },
update: {} update: { downloading: false, progress: 0, newVersion: false }
} }
}, },
async created () { async created () {
this.doCheckRootCa() this.doCheckRootCa()
console.log('index created', this.status, this.$status)
await this.reloadConfig() await this.reloadConfig()
const status = await this.$api.status.get() this.$set(this, 'status', this.$status)
console.log('status', status)
this.$set(this, 'status', status)
this.switchBtns = this.createSwitchBtns() this.switchBtns = this.createSwitchBtns()
console.log('switchBtns', this.switchBtns) console.log('switchBtns', this.switchBtns)
if (this.$global.update == null) { this.$set(this, 'update', this.$global.update)
this.$global.update = { if (!this.update.autoChecked) {
fromUser: false, this.update.autoChecked = true
autoDownload: true,
progress: 0,
newVersion: false
}
this.update = this.$global.update
this.doCheckUpdate(false) this.doCheckUpdate(false)
} }
this.update = this.$global.update
this.$api.info.get().then(ret => { this.$api.info.get().then(ret => {
this.info = ret this.info = ret
}) })
@ -190,7 +180,9 @@ export default {
loading: false, loading: false,
key: key, key: key,
label: label, label: label,
status: statusParent, status: () => {
return statusParent[key].enabled
},
doClick: (checked) => { doClick: (checked) => {
this.onSwitchClick(this.switchBtns[key], apiTarget.start, apiTarget.close, checked) this.onSwitchClick(this.switchBtns[key], apiTarget.start, apiTarget.close, checked)
} }
@ -235,7 +227,7 @@ export default {
}, },
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)
}, },
openExternal (url) { openExternal (url) {
this.$api.ipc.openExternal(url) this.$api.ipc.openExternal(url)