From ca5d24385f78e8021cb4d2099177ec63fb0c5af2 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Mon, 17 Apr 2023 00:21:49 +0200 Subject: [PATCH] Fix errors on setups with no Notifications/SpeechSynthesis support --- src/api/Notifications/Notifications.tsx | 2 + src/components/VencordSettings/VencordTab.tsx | 42 +++++++++++-------- src/plugins/vcNarrator.tsx | 11 +++-- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/api/Notifications/Notifications.tsx b/src/api/Notifications/Notifications.tsx index c842ec8..600ea63 100644 --- a/src/api/Notifications/Notifications.tsx +++ b/src/api/Notifications/Notifications.tsx @@ -77,6 +77,8 @@ function _showNotification(notification: NotificationData, id: number) { } function shouldBeNative() { + if (typeof Notification === "undefined") return false; + const { useNative } = Settings.notifications; if (useNative === "always") return true; if (useNative === "not-focused") return !document.hasFocus(); diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx index 7bb5353..7512208 100644 --- a/src/components/VencordSettings/VencordTab.tsx +++ b/src/components/VencordSettings/VencordTab.tsx @@ -18,7 +18,7 @@ import { openNotificationLogModal } from "@api/Notifications/notificationLog"; -import { useSettings } from "@api/settings"; +import { Settings, useSettings } from "@api/settings"; import { classNameFactory } from "@api/Styles"; import DonateButton from "@components/DonateButton"; import ErrorBoundary from "@components/ErrorBoundary"; @@ -43,7 +43,6 @@ function VencordSettings() { fallbackValue: "Loading..." }); const settings = useSettings(); - const notifSettings = settings.notifications; const donateImage = React.useMemo(() => Math.random() > 0.5 ? DEFAULT_DONATE_IMAGE : SHIGGY_DONATE_IMAGE, []); @@ -158,8 +157,16 @@ function VencordSettings() { + {typeof Notification !== "undefined" && } + + ); +} + +function NotificationSection({ settings }: { settings: typeof Settings["notifications"]; }) { + return ( + <> Notification Style - {notifSettings.useNative !== "never" && Notification.permission === "denied" && ( + {settings.useNative !== "never" && Notification?.permission === "denied" && ( Desktop Notification Permission denied You have denied Notification Permissions. Thus, Desktop notifications will not work! @@ -178,35 +185,35 @@ function VencordSettings() { { label: "Only use Desktop notifications when Discord is not focused", value: "not-focused", default: true }, { label: "Always use Desktop notifications", value: "always" }, { label: "Always use Vencord notifications", value: "never" }, - ] satisfies Array<{ value: typeof settings["notifications"]["useNative"]; } & Record>} + ] satisfies Array<{ value: typeof settings["useNative"]; } & Record>} closeOnSelect={true} - select={v => notifSettings.useNative = v} - isSelected={v => v === notifSettings.useNative} + select={v => settings.useNative = v} + isSelected={v => v === settings.useNative} serialize={identity} /> Notification Position