feat: complete check for update

This commit is contained in:
tiny-craft 2023-08-20 15:46:06 +08:00
parent 36c23deef8
commit 218bebe09d
4 changed files with 42 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import { BrowserOpenURL } from 'wailsjs/runtime/runtime.js'
import Log from '@/components/icons/Log.vue'
import useConnectionStore from 'stores/connections.js'
import Help from '@/components/icons/Help.vue'
import usePreferencesStore from 'stores/preferences.js'
const themeVars = useThemeVars()
@ -80,12 +81,14 @@ const renderContextLabel = (option) => {
}
const dialogStore = useDialogStore()
const preferencesStore = usePreferencesStore()
const onSelectPreferenceMenu = (key) => {
switch (key) {
case 'preferences':
dialogStore.openPreferencesDialog()
break
case 'update':
preferencesStore.checkForUpdate(true)
break
}
}

View File

@ -142,6 +142,8 @@
"help": "Help",
"check_update": "Check for Updates...",
"auto_refresh": "Auto Refresh",
"new_version_tip": "A new version is available. Download now?",
"no_update": "You're update to date",
"refresh": "Refresh",
"uptime": "Uptime",
"connected_clients": "Clients",

View File

@ -142,6 +142,8 @@
"help": "帮助",
"check_update": "检查更新...",
"auto_refresh": "自动刷新",
"new_version_tip": "有可用的新版本,是否立即下载",
"no_update": "当前已是最新版",
"refresh": "立即刷新",
"uptime": "运行时间",
"connected_clients": "已连客户端",

View File

@ -131,6 +131,10 @@ const usePreferencesStore = defineStore('preferences', {
}
return lang || 'en'
},
autoCheckUpdate() {
return get(this.general, 'checkUpdate', false)
},
},
actions: {
_applyPreferences(data) {
@ -216,6 +220,37 @@ const usePreferencesStore = defineStore('preferences', {
setAsideWidth(width) {
this.general.asideWidth = width
},
async checkForUpdate(manual = false) {
const message = useMessage()
const confirmDialog = useConfirmDialog()
let msgRef = null
if (manual) {
msgRef = message.loading('Retrieving for new version', { duration: 0 })
}
let respObj = null
try {
const resp = await fetch('https://api.github.com/repos/tiny-craft/tiny-rdm/releases/latest')
if (resp.status === 200) {
respObj = await resp.json()
}
} finally {
if (msgRef != null) {
msgRef.destroy()
msgRef = null
}
}
if (respObj != null && !isEmpty(respObj['html_url'])) {
confirmDialog.warning(i18nGlobal.t('new_version_tip'), () => {
BrowserOpenURL(respObj['html_url'])
})
} else {
if (manual) {
message.info(i18nGlobal.t('no_update'))
}
}
},
},
})