From 405d0bbdb21dd19d7c90ccbe2d50f8d65eca1330 Mon Sep 17 00:00:00 2001 From: putyy Date: Mon, 7 Jul 2025 14:40:41 +0800 Subject: [PATCH] feat: Add version update detection --- frontend/components.d.ts | 2 -- frontend/src/components/layout/Sider.vue | 36 ++++++++++++++++++++++-- frontend/src/func.ts | 29 +++++++++++++++++++ frontend/src/views/index.vue | 1 - frontend/src/views/setting.vue | 13 +-------- 5 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 frontend/src/func.ts diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 940b9fa..55cc01c 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -9,8 +9,6 @@ declare module 'vue' { export interface GlobalComponents { Action: typeof import('./src/components/Action.vue')['default'] ActionDesc: typeof import('./src/components/ActionDesc.vue')['default'] - DescriptionHeader: typeof import('./src/components/DescriptionHeader.vue')['default'] - DescriptionSearch: typeof import('./src/components/DescriptionSearch.vue')['default'] Footer: typeof import('./src/components/Footer.vue')['default'] ImportJson: typeof import('./src/components/ImportJson.vue')['default'] Index: typeof import('./src/components/layout/Index.vue')['default'] diff --git a/frontend/src/components/layout/Sider.vue b/frontend/src/components/layout/Sider.vue index 280f7b3..7ed5fd3 100644 --- a/frontend/src/components/layout/Sider.vue +++ b/frontend/src/components/layout/Sider.vue @@ -2,7 +2,12 @@
- res-downloader logo +
+ res-downloader logo + + New + +
@@ -66,6 +71,8 @@ import Footer from "@/components/Footer.vue" import Screen from "@/components/Screen.vue" import {BrowserOpenURL} from "../../../wailsjs/runtime" import {useI18n} from "vue-i18n" +import request from "@/api/request" +import {compareVersions} from "@/func" const {t} = useI18n() const route = useRoute() @@ -77,6 +84,7 @@ const showAppInfo = ref(false) const menuValue = ref(route.fullPath.substring(1)) const store = useIndexStore() const is = ref(false) +const showUpdate = ref(false) const envInfo = store.envInfo @@ -98,6 +106,13 @@ onMounted(()=>{ collapsed.value = JSON.parse(collapsedCache).collapsed } is.value = true + + request({ + url: 'https://res.putyy.com/version.json', + method: 'get', + }).then((res)=>{ + showUpdate.value = compareVersions(res.version, store.appInfo.Version) === 1 + }) }) const renderIcon = (icon: any) => { @@ -182,4 +197,21 @@ const collapsedChange = (value: boolean)=>{ collapsed.value = value localStorage.setItem("collapsed", JSON.stringify({collapsed: value})) } - \ No newline at end of file + + \ No newline at end of file diff --git a/frontend/src/func.ts b/frontend/src/func.ts new file mode 100644 index 0000000..f61df0d --- /dev/null +++ b/frontend/src/func.ts @@ -0,0 +1,29 @@ +const ipv4Regex = /^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}$/ +const domainRegex = /^(?!:\/\/)([a-zA-Z0-9-_]+\.)*[a-zA-Z0-9][a-zA-Z0-9-_]+\.[a-zA-Z]{2,11}?$/ +const localhostRegex = /^localhost$/ + +export const compareVersions = (v1: string, v2: string) => { + const parts1 = v1.split('.').map(Number) + const parts2 = v2.split('.').map(Number) + + const maxLength = Math.max(parts1.length, parts2.length) + + for (let i = 0; i < maxLength; i++) { + const num1 = parts1[i] || 0 + const num2 = parts2[i] || 0 + + if (num1 < num2) return -1 + if (num1 > num2) return 1 + } + + return 0 +} + +export const isValidHost = (host: string) => { + return ipv4Regex.test(host) || domainRegex.test(host) || localhostRegex.test(host) +} + +export const isValidPort = (port: number) => { + const portNumber = Number(port) + return Number.isInteger(portNumber) && portNumber > 1024 && portNumber < 65535 +} \ No newline at end of file diff --git a/frontend/src/views/index.vue b/frontend/src/views/index.vue index 1f53836..1384512 100644 --- a/frontend/src/views/index.vue +++ b/frontend/src/views/index.vue @@ -97,7 +97,6 @@ import { DownloadOutline, ArrowRedoCircleOutline, ServerOutline, - HelpCircleOutline, SearchOutline, TrashOutline } from "@vicons/ionicons5" diff --git a/frontend/src/views/setting.vue b/frontend/src/views/setting.vue index dd42c2c..206f99e 100644 --- a/frontend/src/views/setting.vue +++ b/frontend/src/views/setting.vue @@ -204,6 +204,7 @@ import type {appType} from "@/types/app" import appApi from "@/api/app" import {computed} from "vue" import {useI18n} from 'vue-i18n' +import {isValidHost, isValidPort} from '@/func' const {t} = useI18n() const store = useIndexStore() @@ -221,9 +222,6 @@ const renderKey = ref(999) const hostValidationFeedback = ref("") const portValidationFeedback = ref("") -const ipv4Regex = /^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}$/ -const domainRegex = /^(?!:\/\/)([a-zA-Z0-9-_]+\.)*[a-zA-Z0-9][a-zA-Z0-9-_]+\.[a-zA-Z]{2,11}?$/ -const localhostRegex = /^localhost$/ watch(formValue.value, () => { formValue.value.Port = formValue.value.Port.trim() @@ -262,15 +260,6 @@ watch(() => store.globalConfig.Locale, () => { renderKey.value++ }) -const isValidPort = (port: number) => { - const portNumber = Number(port) - return Number.isInteger(portNumber) && portNumber > 1024 && portNumber < 65535 -} - -const isValidHost = (host: string) => { - return ipv4Regex.test(host) || domainRegex.test(host) || localhostRegex.test(host) -} - const selectDir = () => { appApi.openDirectoryDialog().then((res: any) => { if (res.code === 1) {