From 8161a07dba401f04dac93f861e6b2cffe53ab7e3 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 1 Oct 2022 00:42:50 +0200 Subject: Add in client updater, Notices API --- src/components/Updater.tsx | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/components/Updater.tsx (limited to 'src/components/Updater.tsx') diff --git a/src/components/Updater.tsx b/src/components/Updater.tsx new file mode 100644 index 0000000..e7b6d54 --- /dev/null +++ b/src/components/Updater.tsx @@ -0,0 +1,128 @@ +import gitHash from "git-hash"; +import { changes, checkForUpdates, getRepo, rebuild, update, UpdateLogger } from "../utils/updater"; +import { React, Forms, Button, Margins, Alerts, Card, Parser } from '../webpack/common'; +import { Flex } from "./Flex"; +import { useAwaiter } from '../utils/misc'; +import { Link } from "./Link"; + +interface Props { + setIsOutdated(b: boolean): void; +} + +function withDispatcher(dispatcher: React.Dispatch>, action: () => any) { + return async () => { + dispatcher(true); + try { + await action(); + } catch (e: any) { + UpdateLogger.error("Failed to update", e); + if (!e) { + var err = "An unknown error occurred (error is undefined).\nPlease try again."; + } else if (e.code && e.cmd) { + const { code, path, cmd, stderr } = e; + + if (code === "ENOENT") + var err = `Command \`${path}\` not found.\nPlease install it and try again`; + else { + var err = `An error occured while running \`${cmd}\`:\n`; + err += stderr || `Code \`${code}\`. See the console for more info`; + } + + } else { + var err = "An unknown error occurred. See the console for more info."; + } + Alerts.show({ + title: "Oops!", + body: err.split("\n").map(line =>
{Parser.parse(line)}
) + }); + } + finally { + dispatcher(false); + } + }; +}; + +export function Updater(p: Props) { + const [repo, err, repoPending] = useAwaiter(getRepo, "Loading..."); + const [isChecking, setIsChecking] = React.useState(false); + const [isUpdating, setIsUpdating] = React.useState(false); + const [updates, setUpdates] = React.useState(changes); + + React.useEffect(() => { + if (err) + UpdateLogger.error("Failed to retrieve repo", err); + }, [err]); + + return ( + <> + Repo: {repoPending ? repo : err ? "Failed to retrieve - check console" : ( + + {repo.split("/").slice(-2).join("/")} + + )} ({gitHash}) + + + There are {updates.length} Updates + + + + {updates.map(({ hash, author, message }) => ( +
+ + {hash} + + {message} - {author} +
+ ))} +
+ + + + + + + ); +} -- cgit