Make getUserSetting not return undefined

This commit is contained in:
Nuckyz 2024-08-03 13:27:46 -03:00
parent e24bdc2b6f
commit 76f8b0e38e
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
7 changed files with 9 additions and 7 deletions

View file

@ -50,7 +50,7 @@ export const UserSettings = findByFactoryCode<Record<PropertyKey, UserSettingDef
* @param group The setting group
* @param name The name of the setting
*/
export function getUserSetting<T = any>(group: string, name: string): UserSettingDefinition<T> | undefined {
export function getUserSetting<T = any>(group: string, name: string): UserSettingDefinition<T> {
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<T = any>(group: string, name: string): UserSettin
return userSetting;
}
}
throw new Error(`UserSettingsAPI: Setting ${group}.${name} not found.`);
}
/**

View file

@ -59,7 +59,7 @@ const TrustedRolesIds = [
const AsyncFunction = async function () { }.constructor;
const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame")!;
const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame");
async function forceUpdate() {
const outdated = await checkForUpdates();

View file

@ -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 (

View file

@ -33,7 +33,7 @@ const useProfileThemeStyle = findByCode("profileThemeStyle:", "--profile-gradien
const ActivityComponent = findComponentByCode("onOpenGameProfile");
const ActivityClassName = findByProps("activity", "buttonColor");
const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame")!;
const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame");
async function getApplicationAsset(key: string): Promise<string> {
if (/https?:\/\/(cdn|media)\.discordapp\.(com|net)\/attachments\//.test(key)) return "mp:" + key.replace(/https?:\/\/(cdn|media)\.discordapp\.(com|net)\//, "");

View file

@ -28,7 +28,7 @@ import style from "./style.css?managed";
const Button = findComponentByCode("Button.Sizes.NONE,disabled:");
const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame")!;
const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame");
function makeIcon(showCurrentGame?: boolean) {
const { oldIcon } = settings.use(["oldIcon"]);

View file

@ -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 (

View file

@ -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 = /(?<!<)https?:\/\/(?:\w+\.)?discord(?:app)?\.com\/channels\/(?:\d{17,20}|@me)\/(\d{17,20})\/(\d{17,20})/g;
const tenorRegex = /^https:\/\/(?:www\.)?tenor\.com\//;