Clean up all finds; Make common components NoopComponents by default

I went through every single find and made sure every component find is using the proper method
This commit is contained in:
Nuckyz 2024-05-08 04:48:48 -03:00
parent 4cc6789b5b
commit fa948e8639
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
15 changed files with 61 additions and 58 deletions

View file

@ -18,7 +18,7 @@
import { find } from "@webpack"; import { find } from "@webpack";
const NoticesModule = find(m => m.show && m.dismiss && !m.suppressAll, m => m); const NoticesModule = find(m => m.show && m.dismiss && !m.suppressAll);
export const noticesQueue = [] as any[]; export const noticesQueue = [] as any[];
export let currentNotice: any = null; export let currentNotice: any = null;

View file

@ -29,7 +29,7 @@ import { classes } from "@utils/misc";
import { openModal } from "@utils/modal"; import { openModal } from "@utils/modal";
import { showItemInFolder } from "@utils/native"; import { showItemInFolder } from "@utils/native";
import { useAwaiter } from "@utils/react"; import { useAwaiter } from "@utils/react";
import { find, findComponent } from "@webpack"; import { findByProps, findComponent } from "@webpack";
import { Button, Card, Forms, React, showToast, TabBar, TextArea, useEffect, useRef, useState } from "@webpack/common"; import { Button, Card, Forms, React, showToast, TabBar, TextArea, useEffect, useRef, useState } from "@webpack/common";
import type { Ref, SyntheticEvent } from "react"; import type { Ref, SyntheticEvent } from "react";
@ -44,7 +44,7 @@ type FileInputProps = {
}; };
const FileInput = findComponent<FileInputProps>(m => m.prototype?.activateUploadDialogue && m.prototype.setRef); const FileInput = findComponent<FileInputProps>(m => m.prototype?.activateUploadDialogue && m.prototype.setRef);
const TextAreaProps = find(m => typeof m.textarea === "string"); const TextAreaProps = findByProps("textarea");
const cl = classNameFactory("vc-settings-theme-"); const cl = classNameFactory("vc-settings-theme-");

View file

@ -21,11 +21,11 @@ import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByCode, findByProps } from "@webpack"; import { findByProps, findComponentByCode } from "@webpack";
type AnonUpload = Upload & { anonymise?: boolean; }; type AnonUpload = Upload & { anonymise?: boolean; };
const ActionBarIcon = findByCode(".actionBarIcon)"); const ActionBarIcon = findComponentByCode(".actionBarIcon)");
const UploadDraft = findByProps("popFirstFile", "update"); const UploadDraft = findByProps("popFirstFile", "update");
const enum Methods { const enum Methods {

View file

@ -5,7 +5,7 @@
*/ */
import { Flex } from "@components/Flex"; import { Flex } from "@components/Flex";
import { findByCode } from "@webpack"; import { findComponentByCode } from "@webpack";
import { Button, useEffect } from "@webpack/common"; import { Button, useEffect } from "@webpack/common";
import { useAuthorizationStore } from "../../lib/stores/AuthorizationStore"; import { useAuthorizationStore } from "../../lib/stores/AuthorizationStore";
@ -13,7 +13,7 @@ import { useCurrentUserDecorationsStore } from "../../lib/stores/CurrentUserDeco
import { cl } from "../"; import { cl } from "../";
import { openChangeDecorationModal } from "../modals/ChangeDecorationModal"; import { openChangeDecorationModal } from "../modals/ChangeDecorationModal";
const CustomizationSection = findByCode(".customizationSectionBackground"); const CustomizationSection = findComponentByCode(".customizationSectionBackground");
interface DecorSectionProps { interface DecorSectionProps {
hideTitle?: boolean; hideTitle?: boolean;

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import { NoopComponent } from "@utils/react";
import { filters, findComponent } from "@webpack"; import { filters, findComponent } from "@webpack";
import { React } from "@webpack/common"; import { React } from "@webpack/common";
import type { ComponentType, HTMLProps, PropsWithChildren } from "react"; import type { ComponentType, HTMLProps, PropsWithChildren } from "react";
@ -15,7 +16,7 @@ type DecorationGridItemComponent = ComponentType<PropsWithChildren<HTMLProps<HTM
isSelected: boolean, isSelected: boolean,
}>; }>;
export let DecorationGridItem: DecorationGridItemComponent; export let DecorationGridItem: DecorationGridItemComponent = NoopComponent;
export const setDecorationGridItem = v => DecorationGridItem = v; export const setDecorationGridItem = v => DecorationGridItem = v;
export const AvatarDecorationModalPreview = findComponent(filters.componentByCode(".shopPreviewBanner"), component => { export const AvatarDecorationModalPreview = findComponent(filters.componentByCode(".shopPreviewBanner"), component => {
@ -28,5 +29,5 @@ type DecorationGridDecorationComponent = React.ComponentType<HTMLProps<HTMLDivEl
isSelected: boolean, isSelected: boolean,
}>; }>;
export let DecorationGridDecoration: DecorationGridDecorationComponent; export let DecorationGridDecoration: DecorationGridDecorationComponent = NoopComponent;
export const setDecorationGridDecoration = v => DecorationGridDecoration = v; export const setDecorationGridDecoration = v => DecorationGridDecoration = v;

View file

@ -21,19 +21,17 @@ import { Flex } from "@components/Flex";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { find, findByProps } from "@webpack"; import { findByProps, findComponentByCode } from "@webpack";
import { Card, ChannelStore, Forms, GuildStore, PermissionsBits, Switch, TextInput, Tooltip, useState } from "@webpack/common"; import { Card, ChannelStore, Forms, GuildStore, PermissionsBits, Switch, TextInput, Tooltip, useState, UtilTypes } from "@webpack/common";
import { Channel, Message, User } from "discord-types/general"; import { Channel, Message, User } from "discord-types/general";
type PermissionName = "CREATE_INSTANT_INVITE" | "KICK_MEMBERS" | "BAN_MEMBERS" | "ADMINISTRATOR" | "MANAGE_CHANNELS" | "MANAGE_GUILD" | "CHANGE_NICKNAME" | "MANAGE_NICKNAMES" | "MANAGE_ROLES" | "MANAGE_WEBHOOKS" | "MANAGE_GUILD_EXPRESSIONS" | "CREATE_GUILD_EXPRESSIONS" | "VIEW_AUDIT_LOG" | "VIEW_CHANNEL" | "VIEW_GUILD_ANALYTICS" | "VIEW_CREATOR_MONETIZATION_ANALYTICS" | "MODERATE_MEMBERS" | "SEND_MESSAGES" | "SEND_TTS_MESSAGES" | "MANAGE_MESSAGES" | "EMBED_LINKS" | "ATTACH_FILES" | "READ_MESSAGE_HISTORY" | "MENTION_EVERYONE" | "USE_EXTERNAL_EMOJIS" | "ADD_REACTIONS" | "USE_APPLICATION_COMMANDS" | "MANAGE_THREADS" | "CREATE_PUBLIC_THREADS" | "CREATE_PRIVATE_THREADS" | "USE_EXTERNAL_STICKERS" | "SEND_MESSAGES_IN_THREADS" | "CONNECT" | "SPEAK" | "MUTE_MEMBERS" | "DEAFEN_MEMBERS" | "MOVE_MEMBERS" | "USE_VAD" | "PRIORITY_SPEAKER" | "STREAM" | "USE_EMBEDDED_ACTIVITIES" | "USE_SOUNDBOARD" | "USE_EXTERNAL_SOUNDS" | "REQUEST_TO_SPEAK" | "MANAGE_EVENTS" | "CREATE_EVENTS";
interface Tag { interface Tag {
// name used for identifying, must be alphanumeric + underscores // name used for identifying, must be alphanumeric + underscores
name: string; name: string;
// name shown on the tag itself, can be anything probably; automatically uppercase'd // name shown on the tag itself, can be anything probably; automatically uppercase'd
displayName: string; displayName: string;
description: string; description: string;
permissions?: PermissionName[]; permissions?: UtilTypes.Permissions[];
condition?(message: Message | null, user: User, channel: Channel): boolean; condition?(message: Message | null, user: User, channel: Channel): boolean;
} }
@ -57,7 +55,7 @@ const PermissionUtil = findByProps("computePermissions", "canEveryoneRole") as {
computePermissions({ ...args }): bigint; computePermissions({ ...args }): bigint;
}; };
const Tag = find(m => m.Types?.[0] === "BOT") as React.ComponentType<{ type?: number, className?: string, useRemSizes?: boolean; }> & { Types: Record<string, number>; }; const Tag = findComponentByCode(".DISCORD_SYSTEM_MESSAGE_BOT_TAG_TOOLTIP,") as React.ComponentType<{ type?: number, className?: string, useRemSizes?: boolean; }> & { Types: Record<string, number>; };
const isWebhook = (message: Message, user: User) => !!message?.webhookId && user.isNonUserBot(); const isWebhook = (message: Message, user: User) => !!message?.webhookId && user.isNonUserBot();

View file

@ -19,9 +19,8 @@
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { findByProps } from "@webpack"; import { findByProps } from "@webpack";
import { GuildStore, RestAPI } from "@webpack/common"; import { GuildStore, i18n, RestAPI } from "@webpack/common";
const Messages = findByProps("GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION");
const { InvitesDisabledExperiment } = findByProps("InvitesDisabledExperiment"); const { InvitesDisabledExperiment } = findByProps("InvitesDisabledExperiment");
export default definePlugin({ export default definePlugin({
@ -63,7 +62,7 @@ export default definePlugin({
renderInvitesLabel(guildId: string, setChecked: Function) { renderInvitesLabel(guildId: string, setChecked: Function) {
return ( return (
<div> <div>
{Messages.GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION} {i18n.Messages.GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION}
{this.showDisableInvites(guildId) && <a role="button" onClick={() => { {this.showDisableInvites(guildId) && <a role="button" onClick={() => {
setChecked(true); setChecked(true);
this.disableInvites(guildId); this.disableInvites(guildId);

View file

@ -7,14 +7,14 @@
import { DataStore } from "@api/index"; import { DataStore } from "@api/index";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import { openModal } from "@utils/modal"; import { openModal } from "@utils/modal";
import { findByProps } from "@webpack"; import { findExportedComponent } from "@webpack";
import { showToast, Toasts, UserStore } from "@webpack/common"; import { showToast, Toasts, UserStore } from "@webpack/common";
import { ReviewDBAuth } from "./entities"; import { ReviewDBAuth } from "./entities";
const DATA_STORE_KEY = "rdb-auth"; const DATA_STORE_KEY = "rdb-auth";
const { OAuth2AuthorizeModal } = findByProps("OAuth2AuthorizeModal"); const OAuth2AuthorizeModal = findExportedComponent("OAuth2AuthorizeModal");
export let Auth: ReviewDBAuth = {}; export let Auth: ReviewDBAuth = {};

View file

@ -19,7 +19,7 @@
import { Settings } from "@api/Settings"; import { Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { formatDuration } from "@utils/text"; import { formatDuration } from "@utils/text";
import { findByProps, findComponent, findComponentByCode } from "@webpack"; import { findByProps, findComponentByCode } from "@webpack";
import { EmojiStore, FluxDispatcher, GuildMemberStore, GuildStore, Parser, PermissionsBits, PermissionStore, SnowflakeUtils, Text, Timestamp, Tooltip, useEffect, useState } from "@webpack/common"; import { EmojiStore, FluxDispatcher, GuildMemberStore, GuildStore, Parser, PermissionsBits, PermissionStore, SnowflakeUtils, Text, Timestamp, Tooltip, useEffect, useState } from "@webpack/common";
import type { Channel } from "discord-types/general"; import type { Channel } from "discord-types/general";
@ -81,13 +81,7 @@ const enum ChannelFlags {
const ChatScrollClasses = findByProps("auto", "content", "scrollerBase"); const ChatScrollClasses = findByProps("auto", "content", "scrollerBase");
const ChatClasses = findByProps("chat", "content", "noChat", "chatContent"); const ChatClasses = findByProps("chat", "content", "noChat", "chatContent");
const ChannelBeginHeader = findComponentByCode(".Messages.ROLE_REQUIRED_SINGLE_USER_MESSAGE"); const ChannelBeginHeader = findComponentByCode(".Messages.ROLE_REQUIRED_SINGLE_USER_MESSAGE");
const TagComponent = findComponent(m => { const TagComponent = findComponentByCode(".Messages.FORUM_TAG_A11Y_FILTER_BY_TAG");
if (typeof m !== "function") return false;
const code = Function.prototype.toString.call(m);
// Get the component which doesn't include increasedActivity
return code.includes(".Messages.FORUM_TAG_A11Y_FILTER_BY_TAG") && !code.includes("increasedActivityPill");
});
const EmojiParser = findByProps("convertSurrogateToName"); const EmojiParser = findByProps("convertSurrogateToName");
const EmojiUtils = findByProps("getURL", "getEmojiColors"); const EmojiUtils = findByProps("getURL", "getEmojiColors");

View file

@ -18,12 +18,12 @@
import "./VoiceChannelSection.css"; import "./VoiceChannelSection.css";
import { findByCode, findByProps } from "@webpack"; import { findByProps, findComponentByCode } from "@webpack";
import { Button, Forms, PermissionStore, Toasts } from "@webpack/common"; import { Button, Forms, PermissionStore, Toasts } from "@webpack/common";
import { Channel } from "discord-types/general"; import { Channel } from "discord-types/general";
const ChannelActions = findByProps("selectChannel", "selectVoiceChannel"); const ChannelActions = findByProps("selectChannel", "selectVoiceChannel");
const UserPopoutSection = findByCode(".lastSection", "children:"); const UserPopoutSection = findComponentByCode(".lastSection", "children:");
const CONNECT = 1n << 20n; const CONNECT = 1n << 20n;

View file

@ -19,6 +19,8 @@
import { filters, find, findByProps, findExportedComponent } from "@webpack"; import { filters, find, findByProps, findExportedComponent } from "@webpack";
import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react"; import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react";
import { NoopComponent } from "./react";
export const enum ModalSize { export const enum ModalSize {
SMALL = "small", SMALL = "small",
MEDIUM = "medium", MEDIUM = "medium",
@ -100,11 +102,11 @@ type Modals = {
}; };
export let ModalRoot: Modals["ModalRoot"]; export let ModalRoot: Modals["ModalRoot"] = NoopComponent;
export let ModalHeader: Modals["ModalHeader"]; export let ModalHeader: Modals["ModalHeader"] = NoopComponent;
export let ModalContent: Modals["ModalContent"]; export let ModalContent: Modals["ModalContent"] = NoopComponent;
export let ModalFooter: Modals["ModalFooter"]; export let ModalFooter: Modals["ModalFooter"] = NoopComponent;
export let ModalCloseButton: Modals["ModalCloseButton"]; export let ModalCloseButton: Modals["ModalCloseButton"] = NoopComponent;
export const Modals = find<Modals>(filters.byProps("ModalRoot", "ModalCloseButton"), m => { export const Modals = find<Modals>(filters.byProps("ModalRoot", "ModalCloseButton"), m => {
({ ModalRoot, ModalHeader, ModalContent, ModalFooter, ModalCloseButton } = m); ({ ModalRoot, ModalHeader, ModalContent, ModalFooter, ModalCloseButton } = m);

View file

@ -16,30 +16,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { NoopComponent } from "@utils/react";
// eslint-disable-next-line path-alias/no-relative // eslint-disable-next-line path-alias/no-relative
import { filters, find, findComponent, findExportedComponent } from "../webpack"; import { filters, find, findComponent, findExportedComponent } from "../webpack";
import * as t from "./types/components"; import * as t from "./types/components";
export let Card: t.Card; export let Card: t.Card = NoopComponent as any;
export let Button: t.Button; export let Button: t.Button = NoopComponent as any;
export let Switch: t.Switch; export let Switch: t.Switch = NoopComponent;
export let Tooltip: t.Tooltip; export let Tooltip: t.Tooltip = NoopComponent as any;
export let TextInput: t.TextInput; export let TextInput: t.TextInput = NoopComponent as any;
export let TextArea: t.TextArea; export let TextArea: t.TextArea = NoopComponent;
export let Text: t.Text; export let Text: t.Text = NoopComponent;
export let Heading: t.Heading; export let Heading: t.Heading = NoopComponent;
export let Select: t.Select; export let Select: t.Select = NoopComponent;
export let SearchableSelect: t.SearchableSelect; export let SearchableSelect: t.SearchableSelect = NoopComponent;
export let Slider: t.Slider; export let Slider: t.Slider = NoopComponent;
export let ButtonLooks: t.ButtonLooks; export let ButtonLooks: t.ButtonLooks;
export let Popout: t.Popout; export let Popout: t.Popout = NoopComponent as any;
export let Dialog: t.Dialog; export let Dialog: t.Dialog = NoopComponent;
export let TabBar: any; export let TabBar: t.TabBar = NoopComponent as any;
export let Paginator: t.Paginator; export let Paginator: t.Paginator = NoopComponent;
export let ScrollerThin: t.ScrollerThin; export let ScrollerThin: t.ScrollerThin = NoopComponent;
export let Clickable: t.Clickable; export let Clickable: t.Clickable = NoopComponent;
export let Avatar: t.Avatar; export let Avatar: t.Avatar = NoopComponent;
export let FocusLock: t.FocusLock; export let FocusLock: t.FocusLock = NoopComponent;
// token lagger real // token lagger real
/** css colour resolver stuff, no clue what exactly this does, just copied usage from Discord */ /** css colour resolver stuff, no clue what exactly this does, just copied usage from Discord */
export let useToken: t.useToken; export let useToken: t.useToken;

View file

@ -37,7 +37,7 @@ export const MessageStore = findStore("MessageStore") as Omit<Stores.MessageStor
getMessages(chanId: string): any; getMessages(chanId: string): any;
}; };
// this is not actually a FluxStore // This is not actually a FluxStore
export const PrivateChannelsStore = findByProps("openPrivateChannel"); export const PrivateChannelsStore = findByProps("openPrivateChannel");
export const PermissionStore = findStore<GenericStore>("PermissionStore"); export const PermissionStore = findStore<GenericStore>("PermissionStore");
export const GuildChannelStore = findStore<GenericStore>("GuildChannelStore"); export const GuildChannelStore = findStore<GenericStore>("GuildChannelStore");

View file

@ -377,6 +377,13 @@ export type Popout = ComponentType<{
export type Dialog = ComponentType<PropsWithChildren<any>>; export type Dialog = ComponentType<PropsWithChildren<any>>;
export type TabBar = ComponentType<PropsWithChildren<any>> & {
Header: ComponentType<PropsWithChildren<any>>;
Item: ComponentType<PropsWithChildren<any>>;
Separator: ComponentType<PropsWithChildren<any>>;
Panel: ComponentType<PropsWithChildren<any>>;
};
type Resolve = (data: { theme: "light" | "dark", saturation: number; }) => { type Resolve = (data: { theme: "light" | "dark", saturation: number; }) => {
hex(): string; hex(): string;
hsl(): string; hsl(): string;

View file

@ -35,7 +35,7 @@ export const FluxDispatcher = find<t.FluxDispatcher>(filters.byProps("dispatch",
return m; return m;
}); });
export const { ComponentDispatch } = findByProps("ComponentDispatch", "ComponentDispatcher"); export const ComponentDispatch = find(filters.byProps("ComponentDispatch", "ComponentDispatcher"), m => m.ComponentDispatch);
export const Constants = findByProps("Endpoints"); export const Constants = findByProps("Endpoints");
@ -123,12 +123,12 @@ export const NavigationRouter = findByProps<t.NavigationRouter>("transitionTo",
export const SettingsRouter = findByProps("open", "saveAccountChanges"); export const SettingsRouter = findByProps("open", "saveAccountChanges");
export const { Permissions: PermissionsBits } = find(m => typeof m.Permissions?.ADMINISTRATOR === "bigint") as { Permissions: t.PermissionsBits; }; export const PermissionsBits = find<t.PermissionsBits>(m => typeof m.Permissions?.ADMINISTRATOR === "bigint", m => m.Permissions);
export const zustandCreate = findByCode<typeof import("zustand").default>("will be removed in v4"); export const zustandCreate = findByCode<typeof import("zustand").default>("will be removed in v4");
const persistFilter = filters.byCode("[zustand persist middleware]"); const persistFilter = filters.byCode("[zustand persist middleware]");
export const { persist: zustandPersist } = find<typeof import("zustand/middleware")>(m => m.persist && persistFilter(m.persist)); export const zustandPersist = find<typeof import("zustand/middleware").persist>(m => m.persist && persistFilter(m.persist), m => m.persist);
export const MessageActions = findByProps("editMessage", "sendMessage"); export const MessageActions = findByProps("editMessage", "sendMessage");
export const UserProfileActions = findByProps("openUserProfileModal", "closeUserProfileModal"); export const UserProfileActions = findByProps("openUserProfileModal", "closeUserProfileModal");