From 76f8b0e38ecba705f331d9340695c58cf78ece49 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 3 Aug 2024 13:27:46 -0300 Subject: [PATCH] Make getUserSetting not return undefined --- src/api/UserSettings.ts | 4 +++- src/plugins/_core/supportHelper.tsx | 2 +- src/plugins/betterRoleContext/index.tsx | 2 +- src/plugins/customRPC/index.tsx | 2 +- src/plugins/gameActivityToggle/index.tsx | 2 +- src/plugins/ignoreActivities/index.tsx | 2 +- src/plugins/messageLinkEmbeds/index.tsx | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/api/UserSettings.ts b/src/api/UserSettings.ts index 788d2e091..18d360485 100644 --- a/src/api/UserSettings.ts +++ b/src/api/UserSettings.ts @@ -50,7 +50,7 @@ export const UserSettings = findByFactoryCode(group: string, name: string): UserSettingDefinition | undefined { +export function getUserSetting(group: string, name: string): UserSettingDefinition { if (!Vencord.Plugins.isPluginEnabled("UserSettingsAPI")) throw new Error("Cannot use UserSettingsAPI without setting as dependency."); for (const key in UserSettings) { @@ -60,6 +60,8 @@ export function getUserSetting(group: string, name: string): UserSettin return userSetting; } } + + throw new Error(`UserSettingsAPI: Setting ${group}.${name} not found.`); } /** diff --git a/src/plugins/_core/supportHelper.tsx b/src/plugins/_core/supportHelper.tsx index de8e37c79..fff6d44e7 100644 --- a/src/plugins/_core/supportHelper.tsx +++ b/src/plugins/_core/supportHelper.tsx @@ -59,7 +59,7 @@ const TrustedRolesIds = [ const AsyncFunction = async function () { }.constructor; -const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame")!; +const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame"); async function forceUpdate() { const outdated = await checkForUpdates(); diff --git a/src/plugins/betterRoleContext/index.tsx b/src/plugins/betterRoleContext/index.tsx index 1bd193cfc..ae7419af2 100644 --- a/src/plugins/betterRoleContext/index.tsx +++ b/src/plugins/betterRoleContext/index.tsx @@ -15,7 +15,7 @@ import { Clipboard, GuildStore, Menu, PermissionStore } from "@webpack/common"; const GuildSettingsActions = findByProps("open", "selectRole", "updateGuild"); -const DeveloperMode = getUserSettingLazy("appearance", "developerMode")!; +const DeveloperMode = getUserSettingLazy("appearance", "developerMode"); function PencilIcon() { return ( diff --git a/src/plugins/customRPC/index.tsx b/src/plugins/customRPC/index.tsx index 478f797f7..eac338171 100644 --- a/src/plugins/customRPC/index.tsx +++ b/src/plugins/customRPC/index.tsx @@ -33,7 +33,7 @@ const useProfileThemeStyle = findByCode("profileThemeStyle:", "--profile-gradien const ActivityComponent = findComponentByCode("onOpenGameProfile"); const ActivityClassName = findByProps("activity", "buttonColor"); -const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame")!; +const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame"); async function getApplicationAsset(key: string): Promise { if (/https?:\/\/(cdn|media)\.discordapp\.(com|net)\/attachments\//.test(key)) return "mp:" + key.replace(/https?:\/\/(cdn|media)\.discordapp\.(com|net)\//, ""); diff --git a/src/plugins/gameActivityToggle/index.tsx b/src/plugins/gameActivityToggle/index.tsx index 8b08b251d..37acac730 100644 --- a/src/plugins/gameActivityToggle/index.tsx +++ b/src/plugins/gameActivityToggle/index.tsx @@ -28,7 +28,7 @@ import style from "./style.css?managed"; const Button = findComponentByCode("Button.Sizes.NONE,disabled:"); -const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame")!; +const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame"); function makeIcon(showCurrentGame?: boolean) { const { oldIcon } = settings.use(["oldIcon"]); diff --git a/src/plugins/ignoreActivities/index.tsx b/src/plugins/ignoreActivities/index.tsx index aab496f4d..34ce22660 100644 --- a/src/plugins/ignoreActivities/index.tsx +++ b/src/plugins/ignoreActivities/index.tsx @@ -28,7 +28,7 @@ interface IgnoredActivity { const RunningGameStore = findStore("RunningGameStore"); -const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame")!; +const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame"); function ToggleIcon(activity: IgnoredActivity, tooltipText: string, path: string, fill: string) { return ( diff --git a/src/plugins/messageLinkEmbeds/index.tsx b/src/plugins/messageLinkEmbeds/index.tsx index 311e48b0e..9efed0643 100644 --- a/src/plugins/messageLinkEmbeds/index.tsx +++ b/src/plugins/messageLinkEmbeds/index.tsx @@ -54,7 +54,7 @@ const ChannelMessage = findComponentByCode("childrenExecutedCommand:", ".hideAcc const SearchResultClasses = findByProps("message", "searchResult"); const EmbedClasses = findByProps("embedAuthorIcon", "embedAuthor", "embedAuthor"); -const MessageDisplayCompact = getUserSettingLazy("textAndImages", "messageDisplayCompact")!; +const MessageDisplayCompact = getUserSettingLazy("textAndImages", "messageDisplayCompact"); const messageLinkRegex = /(?