优化更新提示

This commit is contained in:
kuaifan 2022-04-01 12:27:12 +08:00
parent 91f4b2fd9d
commit 7749fac683
2 changed files with 34 additions and 18 deletions

View File

@ -16,17 +16,21 @@
</template> </template>
<Modal <Modal
v-model="updateShow" v-model="updateShow"
:cancel-text="$L('稍后')"
:ok-text="$L('立即升级')"
:closable="false" :closable="false"
:mask-closable="false" :mask-closable="false"
@on-ok="updateQuitAndInstall"
class-name="common-right-bottom-notification"> class-name="common-right-bottom-notification">
<div slot="header" class="notification-head"> <div slot="header">
<div class="notification-head">
<div class="notification-title">{{$L('发现新版本')}}</div> <div class="notification-title">{{$L('发现新版本')}}</div>
<Tag color="volcano">v{{systemVersion}} -&gt; v{{updateVersion}}</Tag> <Tag color="volcano">v{{systemVersion}} -&gt; v{{updateVersion}}</Tag>
</div> </div>
<div class="notification-tip">{{$L('离最新版本只有一步之遥了!重新启动应用即可完成更新。')}}</div>
</div>
<MarkdownPreview class="notification-body overlay-y" :initialValue="updateNote"/> <MarkdownPreview class="notification-body overlay-y" :initialValue="updateNote"/>
<div slot="footer" class="adaption">
<Button type="default" @click="updateShow=false">{{$L('稍后')}}</Button>
<Button type="primary" @click="updateQuitAndInstall">{{$L('重新启动')}}</Button>
</div>
</Modal> </Modal>
</div> </div>
</template> </template>
@ -59,9 +63,16 @@ export default {
mounted() { mounted() {
this.checkVersion() this.checkVersion()
// //
if (this.$Electron) {
this.subscribe = Store.subscribe('updateNotification', _ => { this.subscribe = Store.subscribe('updateNotification', _ => {
this.updateShow = true this.updateShow = true
}) })
this.$Electron.registerMsgListener('updateDownloaded', info => {
this.updateVersion = info.version;
this.updateNote = info.releaseNotes || this.$L('没有更新描述。');
this.updateShow = true;
})
}
}, },
beforeDestroy() { beforeDestroy() {
@ -92,11 +103,6 @@ export default {
this.apiVersion = data.version || '' this.apiVersion = data.version || ''
if (this.$Electron) { if (this.$Electron) {
// //
this.$Electron.registerMsgListener('updateDownloaded', info => {
this.updateVersion = info.version;
this.updateNote = info.releaseNotes || this.$L('没有更新描述。');
this.updateShow = true;
})
this.$Electron.sendMessage('updateCheckAndDownload', { this.$Electron.sendMessage('updateCheckAndDownload', {
apiVersion: this.apiVersion apiVersion: this.apiVersion
}) })
@ -107,7 +113,10 @@ export default {
} }
}).catch(_ => { }).catch(_ => {
}); })
//
this.__checkVersion && clearTimeout(this.__checkVersion)
this.__checkVersion = setTimeout(this.checkVersion, 600 * 1000)
}, },
getDownloadUrl(publish) { getDownloadUrl(publish) {
@ -126,7 +135,6 @@ export default {
let timeout = 600; let timeout = 600;
if (cache.time && cache.time + timeout > Math.round(new Date().getTime() / 1000)) { if (cache.time && cache.time + timeout > Math.round(new Date().getTime() / 1000)) {
this.downloadUrl = cache.data.html_url; this.downloadUrl = cache.data.html_url;
setTimeout(this.checkVersion, timeout * 1000)
return; return;
} }
// //
@ -142,10 +150,8 @@ export default {
$A.setStorage(key, cache); $A.setStorage(key, cache);
this.downloadUrl = cache.data.html_url; this.downloadUrl = cache.data.html_url;
} }
setTimeout(this.checkVersion, timeout * 1000)
}).catch(() => { }).catch(() => {
this.loadIng--; this.loadIng--;
setTimeout(this.checkVersion, timeout * 1000)
}); });
break; break;
} }

View File

@ -28,6 +28,9 @@
} }
.common-right-bottom-notification { .common-right-bottom-notification {
.ivu-modal-header {
padding-bottom: 8px !important;
}
.notification-head { .notification-head {
display: flex; display: flex;
align-items: center; align-items: center;
@ -70,6 +73,13 @@
} }
} }
} }
.notification-tip {
display: inline-block;
color: #999999;
line-height: 22px;
padding-top: 4px;
font-size: 12px;
}
.notification-link { .notification-link {
margin-top: 20px; margin-top: 20px;
text-align: right; text-align: right;