Skip to content

Commit 75ba530

Browse files
author
jianghonglu.neo
committed
feat: show update log when check update
1 parent fd1ae14 commit 75ba530

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

src/components/common/Setting/General.vue

+36-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script lang="ts" setup>
22
import { computed, ref } from 'vue'
3-
import { NButton, NPopconfirm, NSelect, useMessage } from 'naive-ui'
3+
import { NButton, NModal, NPopconfirm, NSelect, useMessage } from 'naive-ui'
44
import { checkUpdate, installUpdate } from '@tauri-apps/api/updater'
55
import { relaunch } from '@tauri-apps/api/process'
6+
import MarkdownIt from 'markdown-it'
67
import type { Language, Theme } from '@/store/modules/app/helper'
78
import { SvgIcon } from '@/components/common'
89
import { useAppStore } from '@/store'
@@ -16,6 +17,10 @@ const ms = useMessage()
1617
1718
const theme = computed(() => appStore.theme)
1819
20+
const showDialog = ref<boolean>(false)
21+
const updateContent = ref<string>('')
22+
const updateLoading = ref<boolean>(false)
23+
1924
const language = computed({
2025
get() {
2126
return appStore.language
@@ -54,27 +59,32 @@ function clearData(): void {
5459
location.reload()
5560
}
5661
57-
const updateLoading = ref<boolean>(false)
58-
5962
async function checkAppUpdate() {
6063
const update_info = await checkUpdate()
6164
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
7370
}
7471
else {
7572
ms.info('当前是最新版本!')
7673
}
7774
}
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+
}
7888
</script>
7989

8090
<template>
@@ -130,7 +140,7 @@ async function checkAppUpdate() {
130140
<div class="flex items-center space-x-4">
131141
<span class="flex-shrink-0 w-[100px]">更新</span>
132142
<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">
134144
<template #icon>
135145
<SvgIcon icon="ri:download-2-fill" />
136146
</template>
@@ -140,4 +150,15 @@ async function checkAppUpdate() {
140150
</div>
141151
</div>
142152
</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>
143164
</template>

0 commit comments

Comments
 (0)