From 218bebe09dffaab4dfba219bd45300894c9f315e Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Sun, 20 Aug 2023 15:46:06 +0800 Subject: [PATCH] feat: complete check for update --- frontend/src/components/sidebar/NavMenu.vue | 3 ++ frontend/src/langs/en.json | 2 ++ frontend/src/langs/zh-cn.json | 2 ++ frontend/src/stores/preferences.js | 35 +++++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/frontend/src/components/sidebar/NavMenu.vue b/frontend/src/components/sidebar/NavMenu.vue index 8ec6ab8..31e7278 100644 --- a/frontend/src/components/sidebar/NavMenu.vue +++ b/frontend/src/components/sidebar/NavMenu.vue @@ -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 } } diff --git a/frontend/src/langs/en.json b/frontend/src/langs/en.json index bbc053c..df5b049 100644 --- a/frontend/src/langs/en.json +++ b/frontend/src/langs/en.json @@ -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", diff --git a/frontend/src/langs/zh-cn.json b/frontend/src/langs/zh-cn.json index fae0565..be3b2d3 100644 --- a/frontend/src/langs/zh-cn.json +++ b/frontend/src/langs/zh-cn.json @@ -142,6 +142,8 @@ "help": "帮助", "check_update": "检查更新...", "auto_refresh": "自动刷新", + "new_version_tip": "有可用的新版本,是否立即下载", + "no_update": "当前已是最新版", "refresh": "立即刷新", "uptime": "运行时间", "connected_clients": "已连客户端", diff --git a/frontend/src/stores/preferences.js b/frontend/src/stores/preferences.js index 958f234..7bb4cf6 100644 --- a/frontend/src/stores/preferences.js +++ b/frontend/src/stores/preferences.js @@ -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')) + } + } + }, }, })