Skip to content

Commit b4d810a

Browse files
committed
auto update
1 parent 37a54ea commit b4d810a

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "PocketBook",
3-
"version": "0.0.2",
3+
"version": "0.0.1",
44
"author": "hilanmiao <hilanmiao@126.com>",
55
"description": "An electron-vue project",
66
"license": "MIT",

src/main/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function autoUpdate() {
223223
// 当更新出现错误时触发
224224
autoUpdater.on('error', (err) => {
225225
// sendUpdateMessage('error')
226-
sendUpdateMessage({action: 'error'})
226+
sendUpdateMessage({action: 'error', errorInfo: err})
227227
})
228228

229229
// 当开始检查更新的时候触发
@@ -242,7 +242,7 @@ function autoUpdate() {
242242
// 当没有可用更新的时候触发
243243
autoUpdater.on('update-not-available', (info) => {
244244
// sendUpdateMessage('updateNotAva')
245-
sendUpdateMessage({action: 'updateNotAva'})
245+
sendUpdateMessage({action: 'updateNotAva', updateInfo: info})
246246
})
247247

248248
// 更新下载进度事件
@@ -258,6 +258,8 @@ function autoUpdate() {
258258
* updateUrl String - 更新地址
259259
*/
260260
autoUpdater.on('update-downloaded', (info) => {
261+
// 下载太快可能无法触发downloadProgress事件,所以手动通知一下
262+
mainWindow.webContents.send('downloadProgress', {percent: 100})
261263
// 可以手动选择是否立即退出并更新
262264
ipcMain.on('isUpdateNow', (e, arg) => {
263265
// some code here to handle event

src/renderer/views/Notes/Notes.vue

+28-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
<template>
22
<v-layout row wrap>
33
<v-flex xs4>
4-
<v-layout column wrap text-xs-center>
4+
<v-layout column wrap text-xs-left>
55
<v-flex>
66
<v-btn color="info"
77
@click="checkForUpdate()">
88
Check for updates
9+
<v-icon right>new_releases</v-icon>
910
</v-btn>
1011
</v-flex>
12+
<v-flex class="title" v-show="noNewVersion">
13+
<v-icon>thumb_up</v-icon> Already the latest version
14+
</v-flex>
1115
<v-flex v-show="hasNewVersion">
1216
<v-btn color="info"
1317
:loading="downloading"
1418
:disabled="downloading"
1519
@click="downloadAndUpdate">
16-
Download new version!
20+
Download new version
21+
<v-icon right>cloud_download</v-icon>
1722
<template v-slot:loader>
1823
<span>Loading...</span>
1924
</template>
2025
</v-btn>
26+
<v-progress-circular
27+
:size="100"
28+
:width="15"
29+
:rotate="-90"
30+
:value="downloadPercent"
31+
color="primary"
32+
>
33+
{{ downloadPercent }}
34+
</v-progress-circular>
2135
<v-dialog
2236
v-model="downloading"
2337
persistent
@@ -50,20 +64,9 @@
5064
</v-card>
5165
</v-dialog>
5266
</v-flex>
53-
<v-flex v-show="hasNewVersion">
54-
<v-progress-circular
55-
:size="100"
56-
:width="15"
57-
:rotate="-90"
58-
:value="downloadPercent"
59-
color="primary"
60-
>
61-
{{ downloadPercent }}
62-
</v-progress-circular>
63-
</v-flex>
6467
<v-flex class="text-xs-left" v-show="showError">
6568
<v-alert type="error" v-model="showError" transition="scale-transition">
66-
update error
69+
error info {{errorInfo}}
6770
</v-alert>
6871
</v-flex>
6972
</v-layout>
@@ -89,15 +92,17 @@
8992
dialogUpdateNow: false,
9093
downloading: false,
9194
hasNewVersion: false,
95+
noNewVersion: false,
9296
downloadPercent: 0,
9397
showError: false,
94-
info: '',
98+
errorInfo: {},
9599
versionInfoList: []
96100
}),
97101
destroyed() {
98102
// 移除事件监听
99103
ipcRenderer.removeAllListeners('updateMessage')
100104
ipcRenderer.removeAllListeners('downloadProgress')
105+
ipcRenderer.removeAllListeners('isUpdateNow')
101106
},
102107
mounted() {
103108
this.versionInfoList = this.getVersionInfoList()
@@ -126,20 +131,20 @@
126131
// 开始下载
127132
ipcRenderer.send('downloadUpdate')
128133
ipcRenderer.on('downloadProgress', (event, progressObj) => {
134+
this.progress = JSON.stringify(progressObj)
129135
// console.log(progressObj)
130136
this.downloadPercent = progressObj.percent.toFixed(0) || 0
131-
132-
if(this.downloadPercent = 100) {
137+
// if(this.downloadPercent === 100) { // 这样写为啥不好使呢?
138+
if(progressObj.percent === 100) {
133139
this.downloading = false
134140
// 询问是否立即更新
135141
this.dialogUpdateNow = true
136142
}
137143
})
138144
},
139145
updateNow() {
140-
ipcRenderer.on('isUpdateNow', () => {
141-
ipcRenderer.send('isUpdateNow')
142-
})
146+
// 立刻退出并更新
147+
ipcRenderer.send('isUpdateNow')
143148
},
144149
checkForUpdate() {
145150
// 开始检查
@@ -152,6 +157,9 @@
152157
this.versionInfoList = this.getVersionInfoList()
153158
} else if (obj.action === 'error') {
154159
this.showError = true
160+
this.errorInfo = obj.errorInfo
161+
} else if(obj.action ==='updateNotAva') {
162+
this.noNewVersion = true
155163
} else {
156164
// console.log(text)
157165
}

0 commit comments

Comments
 (0)