From 1d995e58f515dbeb908ba34bf70f829bfd3ccfac Mon Sep 17 00:00:00 2001 From: Ven Date: Fri, 10 Feb 2023 22:33:34 +0100 Subject: Notification API (#467) Co-authored-by: Ven Co-authored-by: afn Co-authored-by: afn --- src/components/VencordSettings/VencordTab.tsx | 149 ++++++++++++++++++-------- 1 file changed, 104 insertions(+), 45 deletions(-) (limited to 'src/components') diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx index 9f55d57..6ea1ca9 100644 --- a/src/components/VencordSettings/VencordTab.tsx +++ b/src/components/VencordSettings/VencordTab.tsx @@ -22,22 +22,63 @@ import { classNameFactory } from "@api/Styles"; import DonateButton from "@components/DonateButton"; import ErrorBoundary from "@components/ErrorBoundary"; import IpcEvents from "@utils/IpcEvents"; -import { useAwaiter } from "@utils/misc"; -import { Button, Card, Forms, Margins, React, Switch } from "@webpack/common"; +import { Margins } from "@utils/margins"; +import { identity, useAwaiter } from "@utils/misc"; +import { Button, Card, Forms, React, Select, Slider, Switch } from "@webpack/common"; const cl = classNameFactory("vc-settings-"); const DEFAULT_DONATE_IMAGE = "https://cdn.discordapp.com/emojis/1026533090627174460.png"; const SHIGGY_DONATE_IMAGE = "https://media.discordapp.net/stickers/1039992459209490513.png"; +type KeysOfType = { + [K in keyof Object]: Object[K] extends Type ? K : never; +}[keyof Object]; + function VencordSettings() { const [settingsDir, , settingsDirPending] = useAwaiter(() => VencordNative.ipc.invoke(IpcEvents.GET_SETTINGS_DIR), { fallbackValue: "Loading..." }); const settings = useSettings(); + const notifSettings = settings.notifications; const donateImage = React.useMemo(() => Math.random() > 0.5 ? DEFAULT_DONATE_IMAGE : SHIGGY_DONATE_IMAGE, []); + const isWindows = navigator.platform.toLowerCase().startsWith("win"); + + const Switches: Array; + title: string; + note: string; + }> = + [ + { + key: "useQuickCss", + title: "Enable Custom CSS", + note: "Loads your Custom CSS" + }, + !IS_WEB && { + key: "enableReactDevtools", + title: "Enable React Developer Tools", + note: "Requires a full restart" + }, + !IS_WEB && !isWindows && { + key: "frameless", + title: "Disable the window frame", + note: "Requires a full restart" + }, + !IS_WEB && { + key: "transparent", + title: "Enable window transparency", + note: "Requires a full restart" + }, + !IS_WEB && isWindows && { + key: "winCtrlQ", + title: "Register Ctrl+Q as shortcut to close Discord (Alternative to Alt+F4)", + note: "Requires a full restart" + } + ]; + return ( @@ -82,52 +123,70 @@ function VencordSettings() { - - + + Hint: You can change the position of this settings section in the settings of the "Settings" plugin! - settings.useQuickCss = v} - note="Loads styles from your QuickCSS file"> - Use QuickCSS - - {!IS_WEB && ( - - settings.enableReactDevtools = v} - note="Requires a full restart" - > - Enable React Developer Tools - - settings.frameless = v} - note="Requires a full restart" - > - Disable the window frame - - settings.transparent = v} - note="Requires a full restart" - > - Enable window transparency - - {navigator.platform.toLowerCase().startsWith("win") && ( - settings.winCtrlQ = v} - note="Requires a full restart" - > - Register Ctrl+Q as shortcut to close Discord (Alternative to Alt+F4) - - )} - - )} - + {Switches.map(s => s && ( + settings[s.key] = v} + note={s.note} + > + {s.title} + + ))} + + + Notification Style + + Some plugins may show you notifications. These come in two styles: +
    +
  • Vencord Notifications: These are in-app notifications
  • +
  • Desktop Notifications: Native Desktop notifications (like when you get a ping)
  • +
+
+ >} + select={v => notifSettings.position = v} + isSelected={v => v === notifSettings.position} + serialize={identity} + /> + + Notification Timeout + Set to 0s to never automatically time out + notifSettings.timeout = v} + onValueRender={v => (v / 1000).toFixed(2) + "s"} + onMarkerRender={v => (v / 1000) + "s"} + stickToMarkers={false} + />
); } -- cgit