From 29de95739511cadffbe147fdbbeaea898344598e Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Thu, 23 Mar 2023 16:01:00 +0000 Subject: [PATCH] feat: add check update --- app/components/home.tsx | 6 +- app/components/settings.tsx | 47 +- app/constant.ts | 3 + app/layout.tsx | 11 +- app/locales/cn.ts | 8 + app/locales/en.ts | 8 + app/styles/globals.scss | 13 + app/styles/markdown.scss | 36 +- app/utils.ts | 39 + next.config.js | 2 +- package-lock.json | 5221 ----------------------------------- package.json | 14 +- yarn.lock | 50 +- 13 files changed, 201 insertions(+), 5257 deletions(-) create mode 100644 app/constant.ts delete mode 100644 package-lock.json diff --git a/app/components/home.tsx b/app/components/home.tsx index ad832d5b8..28f39e749 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -26,6 +26,7 @@ import { copyToClipboard, downloadAs, isIOS, selectOrCopy } from "../utils"; import Locale from "../locales"; import dynamic from "next/dynamic"; +import { REPO_URL } from "../constant"; export function Loading(props: { noLogo?: boolean }) { return ( @@ -466,10 +467,7 @@ export function Home() { />
- + } />
diff --git a/app/components/settings.tsx b/app/components/settings.tsx index f5db18b17..4966e9c4e 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import EmojiPicker, { Theme as EmojiTheme } from "emoji-picker-react"; @@ -15,6 +15,9 @@ import { SubmitKey, useChatStore, Theme, ALL_MODELS } from "../store"; import { Avatar } from "./home"; import Locale, { changeLang, getLang } from "../locales"; +import { checkUpstreamLatestCommitId, getCurrentCommitId } from "../utils"; +import Link from "next/link"; +import { UPDATE_URL } from "../constant"; function SettingItem(props: { title: string; @@ -45,6 +48,23 @@ export function Settings(props: { closeSettings: () => void }) { ] ); + const currentId = getCurrentCommitId(); + const [checkingUpdate, setCheckingUpdate] = useState(false); + const [remoteId, setRemoteId] = useState(); + const hasNewVersion = currentId !== remoteId; + + function checkUpdate(force = false) { + setCheckingUpdate(true); + checkUpstreamLatestCommitId(force).then((id) => { + setRemoteId(id); + setCheckingUpdate(false); + }); + } + + useEffect(() => { + checkUpdate(); + }, []); + return ( <>
@@ -109,6 +129,31 @@ export function Settings(props: { closeSettings: () => void }) { + + {checkingUpdate ? ( +
+ ) : hasNewVersion ? ( + + {Locale.Settings.Update.GoToUpdate} + + ) : ( + } + text={Locale.Settings.Update.CheckUpdate} + onClick={() => checkUpdate(true)} + /> + )} + +