diff --git a/src/apis/index.ts b/src/apis/index.ts index 150c1ab..48e336f 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -1,4 +1,5 @@ -import { createSignal, ResourceActions } from 'solid-js' +import ky from 'ky' +import { ResourceActions, createSignal } from 'solid-js' import { toast } from 'solid-toast' import { useRequest } from '~/signals' import { @@ -181,3 +182,46 @@ export const updateRuleProviderAPI = (providerName: string) => { return request.put(`providers/rules/${providerName}`) } + +export const isUpdateAvailableAPI = async (versionResponse: string) => { + const match = /(alpha|beta|meta)-?(\w+)/.exec(versionResponse) + + if (!match) { + return false + } + + const channel = match[1], + version = match[2] + + if (channel === 'meta') { + const { assets } = await ky + .get('https://api.github.com/repos/MetaCubeX/Clash.Meta/releases/latest') + .json<{ + assets: { + name: string + }[] + }>() + + const alreadyLatest = assets.some(({ name }) => name.includes(version)) + + return !alreadyLatest + } + + if (channel === 'alpha') { + const { assets } = await ky + .get( + 'https://api.github.com/repos/MetaCubeX/Clash.Meta/releases/tags/Prerelease-Alpha', + ) + .json<{ + assets: { + name: string + }[] + }>() + + const alreadyLatest = assets.some(({ name }) => name.includes(version)) + + return !alreadyLatest + } + + return false +} diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index e5684ec..1cdc6dd 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -15,6 +15,7 @@ import { fetchBackendVersionAPI, flushFakeIPDataAPI, flushingFakeIPData, + isUpdateAvailableAPI, reloadConfigFileAPI, reloadingConfigFile, restartBackendAPI, @@ -448,17 +449,28 @@ const ConfigForXd = () => { const Versions = () => { const [backendVersion, setBackendVersion] = createSignal('') + const [isUpdateAvailable, setIsUpdateAvailable] = createSignal(false) onMount(async () => { const version = await fetchBackendVersionAPI() - setBackendVersion(version) + setIsUpdateAvailable(await isUpdateAvailableAPI(version)) }) return (
{import.meta.env.version} - {backendVersion()} + +
+ + + + + + + + {backendVersion()} +
) }