diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/Settings.tsx | 63 | ||||
-rw-r--r-- | src/components/Updater.tsx | 76 | ||||
-rw-r--r-- | src/components/index.ts | 1 |
3 files changed, 87 insertions, 53 deletions
diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx index dd23b73..54e6ddb 100644 --- a/src/components/Settings.tsx +++ b/src/components/Settings.tsx @@ -1,20 +1,50 @@ -import { classes, humanFriendlyJoin, lazy, useAwaiter } from "../utils/misc"; +import { classes, humanFriendlyJoin, useAwaiter } from "../utils/misc"; import Plugins from 'plugins'; import { useSettings } from "../api/settings"; import IpcEvents from "../utils/IpcEvents"; -import { Button, Switch, Forms, React, Margins } from "../webpack/common"; +import { Button, Switch, Forms, React, Margins, Toasts, Alerts, Parser } from "../webpack/common"; import ErrorBoundary from "./ErrorBoundary"; import { startPlugin } from "../plugins"; import { stopPlugin } from '../plugins/index'; import { Flex } from './Flex'; -import { isOutdated } from "../utils/updater"; -import { Updater } from "./Updater"; +import { ChangeList } from '../utils/ChangeList'; -export default ErrorBoundary.wrap(function Settings(props) { +function showErrorToast(message: string) { + Toasts.show({ + message, + type: Toasts.Type.FAILURE, + id: Toasts.genId(), + options: { + position: Toasts.Position.BOTTOM + } + }); +} + +export default ErrorBoundary.wrap(function Settings() { const [settingsDir, , settingsDirPending] = useAwaiter(() => VencordNative.ipc.invoke<string>(IpcEvents.GET_SETTINGS_DIR), "Loading..."); - const [outdated, setOutdated] = React.useState(isOutdated); const settings = useSettings(); + const changes = React.useMemo(() => new ChangeList<string>, []); + + React.useEffect(() => { + return () => void (changes.hasChanges && Alerts.show({ + title: "Restart required", + body: ( + <> + <p>The following plugins require a restart:</p> + <div>{changes.map((s, i) => ( + <> + {i > 0 && ", "} + {Parser.parse('`' + s + '`')} + </> + ))}</div> + </> + ), + confirmText: "Restart now", + cancelText: "Later!", + onConfirm: () => location.reload() + })); + }, []); const depMap = React.useMemo(() => { const o = {} as Record<string, string[]>; @@ -34,16 +64,7 @@ export default ErrorBoundary.wrap(function Settings(props) { return ( <Forms.FormSection tag="h1" title="Vencord"> - {outdated && ( - <> - <Forms.FormTitle tag="h5">Updater</Forms.FormTitle> - <Updater setIsOutdated={setOutdated} /> - </> - )} - - <Forms.FormDivider /> - - <Forms.FormTitle tag="h5" className={outdated ? `${Margins.marginTop20} ${Margins.marginBottom8}` : ""}> + <Forms.FormTitle tag="h5"> Settings </Forms.FormTitle> @@ -111,21 +132,19 @@ export default ErrorBoundary.wrap(function Settings(props) { p.dependencies?.forEach(d => { settings.plugins[d].enabled = true; if (!Plugins[d].started && !stopPlugin) { - // TODO show notification settings.plugins[p.name].enabled = false; + showErrorToast(`Failed to start dependency ${d}. Check the console for more info.`); } }); if (!p.started && !startPlugin(p)) { - // TODO show notification + showErrorToast(`Failed to start plugin ${p.name}. Check the console for more info.`); } } else { if (p.started && !stopPlugin(p)) { - // TODO show notification + showErrorToast(`Failed to stop plugin ${p.name}. Check the console for more info.`); } } - if (p.patches) { - // TODO show notification - } + if (p.patches) changes.handleChange(p.name); }} note={p.description} tooltipNote={ diff --git a/src/components/Updater.tsx b/src/components/Updater.tsx index e7b6d54..3d760f9 100644 --- a/src/components/Updater.tsx +++ b/src/components/Updater.tsx @@ -1,13 +1,11 @@ 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 { React, Forms, Button, Margins, Alerts, Card, Parser, Toasts } from '../webpack/common'; import { Flex } from "./Flex"; import { useAwaiter } from '../utils/misc'; import { Link } from "./Link"; +import ErrorBoundary from "./ErrorBoundary"; -interface Props { - setIsOutdated(b: boolean): void; -} function withDispatcher(dispatcher: React.Dispatch<React.SetStateAction<boolean>>, action: () => any) { return async () => { @@ -42,7 +40,7 @@ function withDispatcher(dispatcher: React.Dispatch<React.SetStateAction<boolean> }; }; -export function Updater(p: Props) { +export default ErrorBoundary.wrap(function Updater() { const [repo, err, repoPending] = useAwaiter(getRepo, "Loading..."); const [isChecking, setIsChecking] = React.useState(false); const [isUpdating, setIsUpdating] = React.useState(false); @@ -53,39 +51,48 @@ export function Updater(p: Props) { UpdateLogger.error("Failed to retrieve repo", err); }, [err]); + const isOutdated = updates.length > 0; + return ( - <> - <Forms.FormText>Repo: {repoPending ? repo : err ? "Failed to retrieve - check console" : ( + <Forms.FormSection tag="h1" title="Vencord Updater"> + <Forms.FormTitle tag="h5">Repo</Forms.FormTitle> + + <Forms.FormText>{repoPending ? repo : err ? "Failed to retrieve - check console" : ( <Link href={repo}> {repo.split("/").slice(-2).join("/")} </Link> )} ({gitHash})</Forms.FormText> + <Forms.FormDivider /> + + <Forms.FormTitle tag="h5">Updates</Forms.FormTitle> + <Forms.FormText className={Margins.marginBottom8}> - There are {updates.length} Updates + {updates.length ? `There are ${updates.length} Updates` : "Up to Date!"} </Forms.FormText> - <Card style={{ padding: ".5em" }}> - {updates.map(({ hash, author, message }) => ( - <div> - <Link href={`${repo}/commit/${hash}`} disabled={repoPending}> - <code>{hash}</code> - </Link> - <span style={{ - marginLeft: "0.5em", - color: "var(--text-normal)" - }}>{message} - {author}</span> - </div> - ))} - </Card> + {updates.length > 0 && ( + <Card style={{ padding: ".5em" }}> + {updates.map(({ hash, author, message }) => ( + <div> + <Link href={`${repo}/commit/${hash}`} disabled={repoPending}> + <code>{hash}</code> + </Link> + <span style={{ + marginLeft: "0.5em", + color: "var(--text-normal)" + }}>{message} - {author}</span> + </div> + ))} + </Card> + )} <Flex className={`${Margins.marginBottom8} ${Margins.marginTop8}`}> - <Button + {isOutdated && <Button size={Button.Sizes.SMALL} disabled={isUpdating || isChecking} onClick={withDispatcher(setIsUpdating, async () => { if (await update()) { - p.setIsOutdated(false); const needFullRestart = await rebuild(); await new Promise<void>(r => { Alerts.show({ @@ -106,23 +113,30 @@ export function Updater(p: Props) { } })} > - Update - </Button> + Update Now + </Button>} <Button size={Button.Sizes.SMALL} disabled={isUpdating || isChecking} onClick={withDispatcher(setIsChecking, async () => { - const res = await checkForUpdates(); - if (res) { + const outdated = await checkForUpdates(); + if (outdated) { setUpdates(changes); } else { - p.setIsOutdated(false); + Toasts.show({ + message: "No updates found!", + id: Toasts.genId(), + type: Toasts.Type.MESSAGE, + options: { + position: Toasts.Position.BOTTOM + } + }); } })} > - Refresh + Check for Updates </Button> </Flex> - </> + </Forms.FormSection> ); -} +}); diff --git a/src/components/index.ts b/src/components/index.ts index bf87b3e..de53489 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1 +1,2 @@ export { default as Settings } from "./Settings"; +export { default as Updater } from "./Updater"; |