feat: add check update

This commit is contained in:
Yifei Zhang
2023-03-23 16:01:00 +00:00
parent e55520e93c
commit 29de957395
13 changed files with 201 additions and 5257 deletions

View File

@@ -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() {
/>
</div>
<div className={styles["sidebar-action"]}>
<a
href="https://github.com/Yidadaa/ChatGPT-Next-Web"
target="_blank"
>
<a href={REPO_URL} target="_blank">
<IconButton icon={<GithubIcon />} />
</a>
</div>

View File

@@ -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<string>();
const hasNewVersion = currentId !== remoteId;
function checkUpdate(force = false) {
setCheckingUpdate(true);
checkUpstreamLatestCommitId(force).then((id) => {
setRemoteId(id);
setCheckingUpdate(false);
});
}
useEffect(() => {
checkUpdate();
}, []);
return (
<>
<div className={styles["window-header"]}>
@@ -109,6 +129,31 @@ export function Settings(props: { closeSettings: () => void }) {
</Popover>
</SettingItem>
<SettingItem
title={Locale.Settings.Update.Version(currentId)}
subTitle={
checkingUpdate
? Locale.Settings.Update.IsChecking
: hasNewVersion
? Locale.Settings.Update.FoundUpdate(remoteId ?? "ERROR")
: Locale.Settings.Update.IsLatest
}
>
{checkingUpdate ? (
<div />
) : hasNewVersion ? (
<Link href={UPDATE_URL} target="_blank" className="link">
{Locale.Settings.Update.GoToUpdate}
</Link>
) : (
<IconButton
icon={<ResetIcon></ResetIcon>}
text={Locale.Settings.Update.CheckUpdate}
onClick={() => checkUpdate(true)}
/>
)}
</SettingItem>
<SettingItem title={Locale.Settings.SendKey}>
<select
value={config.submitKey}