1
1
<script lang="ts" setup>
2
2
import { computed , ref } from ' vue'
3
- import { NButton , NPopconfirm , NSelect , useMessage } from ' naive-ui'
3
+ import { NButton , NModal , NPopconfirm , NSelect , useMessage } from ' naive-ui'
4
4
import { checkUpdate , installUpdate } from ' @tauri-apps/api/updater'
5
5
import { relaunch } from ' @tauri-apps/api/process'
6
+ import MarkdownIt from ' markdown-it'
6
7
import type { Language , Theme } from ' @/store/modules/app/helper'
7
8
import { SvgIcon } from ' @/components/common'
8
9
import { useAppStore } from ' @/store'
@@ -16,6 +17,10 @@ const ms = useMessage()
16
17
17
18
const theme = computed (() => appStore .theme )
18
19
20
+ const showDialog = ref <boolean >(false )
21
+ const updateContent = ref <string >(' ' )
22
+ const updateLoading = ref <boolean >(false )
23
+
19
24
const language = computed ({
20
25
get() {
21
26
return appStore .language
@@ -54,27 +59,32 @@ function clearData(): void {
54
59
location .reload ()
55
60
}
56
61
57
- const updateLoading = ref <boolean >(false )
58
-
59
62
async function checkAppUpdate() {
60
63
const update_info = await checkUpdate ()
61
64
if (update_info .shouldUpdate ) {
62
- try {
63
- ms .info (' 发现新版本,正在更新...' )
64
- updateLoading .value = true
65
- await installUpdate ()
66
- await relaunch ()
67
- updateLoading .value = false
68
- }
69
- catch (error ) {
70
- updateLoading .value = false
71
- ms .error (error as string )
72
- }
65
+ const featLog = update_info .manifest ?.body
66
+ const md = new MarkdownIt ()
67
+ const result = md .render (featLog || ' ' )
68
+ updateContent .value = result
69
+ showDialog .value = true
73
70
}
74
71
else {
75
72
ms .info (' 当前是最新版本!' )
76
73
}
77
74
}
75
+
76
+ async function appInstallUpdate() {
77
+ try {
78
+ updateLoading .value = true
79
+ await installUpdate ()
80
+ await relaunch ()
81
+ updateLoading .value = false
82
+ }
83
+ catch (error ) {
84
+ updateLoading .value = false
85
+ ms .error (error as string )
86
+ }
87
+ }
78
88
</script >
79
89
80
90
<template >
@@ -130,7 +140,7 @@ async function checkAppUpdate() {
130
140
<div class =" flex items-center space-x-4" >
131
141
<span class =" flex-shrink-0 w-[100px]" >更新</span >
132
142
<div class =" flex flex-wrap items-center gap-4" >
133
- <NButton size =" small" :loading = " updateLoading " :disabled = " updateLoading " @click =" checkAppUpdate" >
143
+ <NButton size =" small" @click =" checkAppUpdate" >
134
144
<template #icon >
135
145
<SvgIcon icon =" ri:download-2-fill" />
136
146
</template >
@@ -140,4 +150,15 @@ async function checkAppUpdate() {
140
150
</div >
141
151
</div >
142
152
</div >
153
+ <NModal
154
+ v-model:show =" showDialog"
155
+ preset =" dialog"
156
+ title =" 发现新版本"
157
+ negative-text =" 取消"
158
+ positive-text =" 立即更新"
159
+ :loading =" updateLoading"
160
+ @positive-click =" appInstallUpdate"
161
+ >
162
+ <div v-html =" updateContent" />
163
+ </NModal >
143
164
</template >
0 commit comments