Skip to content

Commit

Permalink
feat: 非弹窗形式更新
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghonglu.neo committed Mar 23, 2023
1 parent 8ed5a77 commit a4ea8ca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tauri-build = { version = "1.2.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2.4", features = ["dialog-all", "fs-all", "http-all", "os-all", "path-all", "shell-open", "updater", "window-close", "window-hide", "window-show", "window-start-dragging"] }
tauri = { version = "1.2.4", features = ["dialog-all", "fs-all", "http-all", "os-all", "path-all", "process-exit", "process-relaunch", "shell-open", "updater", "window-close", "window-hide", "window-show", "window-start-dragging"] }
tauri-plugin-log = { git = "https://github.com/lencx/tauri-plugins-workspace", branch = "dev", features = ["colored"] }
tokio = "1.26.0"
reqwest = { version="0.11.14", features= ["stream", "socks"] }
Expand Down
9 changes: 7 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "ChatGPT-Tauri",
"version": "0.1.3"
"version": "0.1.2"
},
"tauri": {
"allowlist": {
Expand Down Expand Up @@ -44,6 +44,11 @@
},
"dialog": {
"all": true
},
"process": {
"all": false,
"relaunch": true,
"exit": true
}
},
"bundle": {
Expand Down Expand Up @@ -84,7 +89,7 @@
},
"updater": {
"active": true,
"dialog": true,
"dialog": false,
"endpoints": [
"https://pljhonglu.github.io/ChatGPT-T/install.json"
],
Expand Down
27 changes: 22 additions & 5 deletions src/components/common/Setting/General.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { computed, ref } from 'vue'
import { NButton, NPopconfirm, NSelect, useMessage } from 'naive-ui'
import { checkUpdate, installUpdate } from '@tauri-apps/api/updater'
import { relaunch } from '@tauri-apps/api/process'
import type { Language, Theme } from '@/store/modules/app/helper'
import { SvgIcon } from '@/components/common'
import { useAppStore } from '@/store'
Expand Down Expand Up @@ -99,10 +100,26 @@ function handleImportButtonClick(): void {
fileInput.click()
}
const updateLoading = ref<boolean>(false)
async function checkAppUpdate() {
const update = await checkUpdate()
if (update.shouldUpdate)
await installUpdate()
const update_info = await checkUpdate()
if (update_info.shouldUpdate) {
try {
ms.info('发现新版本,正在更新...')
updateLoading.value = true
await installUpdate()
await relaunch()
updateLoading.value = false
}
catch (error) {
updateLoading.value = false
ms.error(error as string)
}
}
else {
ms.info('当前是最新版本!')
}
}
</script>

Expand Down Expand Up @@ -174,7 +191,7 @@ async function checkAppUpdate() {
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">更新</span>
<div class="flex flex-wrap items-center gap-4">
<NButton size="small" @click="checkAppUpdate">
<NButton size="small" :loading="updateLoading" :disabled="updateLoading" @click="checkAppUpdate">
<template #icon>
<SvgIcon icon="ri:download-2-fill" />
</template>
Expand Down

0 comments on commit a4ea8ca

Please sign in to comment.