import gitHash from "git-hash"; import { changes, checkForUpdates, getRepo, rebuild, update, UpdateLogger, updateError, isOutdated, isNewer } from "../utils/updater"; import { React, Forms, Button, Margins, Alerts, Card, Parser, Toasts } from "../webpack/common"; import { Flex } from "./Flex"; import { classes, useAwaiter } from "../utils/misc"; import { Link } from "./Link"; import ErrorBoundary from "./ErrorBoundary"; import { ErrorCard } from "./ErrorCard"; 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); } }; } interface CommonProps { repo: string; repoPending: boolean; } function Changes({ updates, repo, repoPending }: CommonProps & { updates: typeof changes; }) { return ( {updates.map(({ hash, author, message }) => (
{hash} {message} - {author}
))}
); } function Updatable(props: CommonProps) { const [updates, setUpdates] = React.useState(changes); const [isChecking, setIsChecking] = React.useState(false); const [isUpdating, setIsUpdating] = React.useState(false); const isOutdated = updates.length > 0; return ( <> {!updates && updateError ? ( <> Failed to check updates. Check the console for more info

{updateError.stderr || updateError.stdout || "An unknown error occurred"}

) : ( {isOutdated ? `There are ${updates.length} Updates` : "Up to Date!"} )} {isOutdated && } {isOutdated && } ); } function Newer(props: CommonProps) { return ( <> Your local copy has more recent commits. Please stash or reset them. ); } export default ErrorBoundary.wrap(function Updater() { const [repo, err, repoPending] = useAwaiter(getRepo, "Loading..."); React.useEffect(() => { if (err) UpdateLogger.error("Failed to retrieve repo", err); }, [err]); const commonProps: CommonProps = { repo, repoPending }; return ( Repo {repoPending ? repo : err ? "Failed to retrieve - check console" : ( {repo.split("/").slice(-2).join("/")} )} ({gitHash}) Updates {isNewer ? : } ); });