From 7415367d6cb5341b5f333bf73e0f2c7cc2da5e98 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 29 Jan 2025 10:09:05 -0300 Subject: [PATCH 1/4] Add missing MenuSearchControl webpack find --- src/webpack/common/menu.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/webpack/common/menu.ts b/src/webpack/common/menu.ts index b4df183b0..c45b69964 100644 --- a/src/webpack/common/menu.ts +++ b/src/webpack/common/menu.ts @@ -36,6 +36,7 @@ waitFor(m => m.name === "MenuCheckboxItem", (_, id) => { waitFor(filters.componentByCode('path:["empty"]'), m => Menu.Menu = m); waitFor(filters.componentByCode("sliderContainer", "slider", "handleSize:16", "=100"), m => Menu.MenuSliderControl = m); +waitFor(filters.componentByCode('role:"searchbox', "top:2", "query:"), m => Menu.MenuSearchControl = m); export const ContextMenuApi: t.ContextMenuApi = mapMangledModuleLazy('type:"CONTEXT_MENU_OPEN', { closeContextMenu: filters.byCode("CONTEXT_MENU_CLOSE"), From 81dda2ce33762ee2f84f8684816d2829563074d2 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:52:49 -0300 Subject: [PATCH 2/4] Make more finds not depend on non mangled keys --- src/plugins/betterFolders/FolderSideBar.tsx | 5 ++--- src/plugins/reviewDB/auth.tsx | 5 +---- src/plugins/webContextMenus.web/index.ts | 7 +++++-- src/webpack/common/components.ts | 5 +++++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/plugins/betterFolders/FolderSideBar.tsx b/src/plugins/betterFolders/FolderSideBar.tsx index 53d24ed93..5203b14d2 100644 --- a/src/plugins/betterFolders/FolderSideBar.tsx +++ b/src/plugins/betterFolders/FolderSideBar.tsx @@ -17,14 +17,13 @@ */ import ErrorBoundary from "@components/ErrorBoundary"; -import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; -import { useStateFromStores } from "@webpack/common"; +import { findComponentByCodeLazy, findStoreLazy } from "@webpack"; +import { Animations, useStateFromStores } from "@webpack/common"; import type { CSSProperties } from "react"; import { ExpandedGuildFolderStore, settings } from "."; const ChannelRTCStore = findStoreLazy("ChannelRTCStore"); -const Animations = findByPropsLazy("a", "animated", "useTransition"); const GuildsBar = findComponentByCodeLazy('("guildsnav")'); export default ErrorBoundary.wrap(guildsBarProps => { diff --git a/src/plugins/reviewDB/auth.tsx b/src/plugins/reviewDB/auth.tsx index 4cd81f2ea..8d9789dd7 100644 --- a/src/plugins/reviewDB/auth.tsx +++ b/src/plugins/reviewDB/auth.tsx @@ -7,15 +7,12 @@ import { DataStore } from "@api/index"; import { Logger } from "@utils/Logger"; import { openModal } from "@utils/modal"; -import { findByPropsLazy } from "@webpack"; -import { showToast, Toasts, UserStore } from "@webpack/common"; +import { OAuth2AuthorizeModal, showToast, Toasts, UserStore } from "@webpack/common"; import { ReviewDBAuth } from "./entities"; const DATA_STORE_KEY = "rdb-auth"; -const { OAuth2AuthorizeModal } = findByPropsLazy("OAuth2AuthorizeModal"); - export let Auth: ReviewDBAuth = {}; export async function initAuth() { diff --git a/src/plugins/webContextMenus.web/index.ts b/src/plugins/webContextMenus.web/index.ts index 661238052..0af47ded8 100644 --- a/src/plugins/webContextMenus.web/index.ts +++ b/src/plugins/webContextMenus.web/index.ts @@ -20,10 +20,13 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { saveFile } from "@utils/web"; -import { findByPropsLazy } from "@webpack"; +import { filters, mapMangledModuleLazy } from "@webpack"; import { Clipboard, ComponentDispatch } from "@webpack/common"; -const ctxMenuCallbacks = findByPropsLazy("contextMenuCallbackNative"); +const ctxMenuCallbacks = mapMangledModuleLazy('.tagName)==="TEXTAREA"||', { + contextMenuCallbackWeb: filters.byCode('.tagName)==="INPUT"||'), + contextMenuCallbackNative: filters.byCode('.tagName)==="TEXTAREA"||') +}); async function fetchImage(url: string) { const res = await fetch(url); diff --git a/src/webpack/common/components.ts b/src/webpack/common/components.ts index 7f5c86498..dfe00e337 100644 --- a/src/webpack/common/components.ts +++ b/src/webpack/common/components.ts @@ -95,3 +95,8 @@ export const MaskedLink = waitForComponent("MaskedLink", filters.c export const Timestamp = waitForComponent("Timestamp", filters.componentByCode("#{intl::MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL}")); export const Flex = waitForComponent("Flex", ["Justify", "Align", "Wrap"]); export const OAuth2AuthorizeModal = waitForComponent("OAuth2AuthorizeModal", filters.componentByCode(".authorize),children:", ".contentBackground")); + +export const Animations = mapMangledModuleLazy(".assign({colorNames:", { + Transition: filters.componentByCode('["items","children"]', ",null,"), + animated: filters.byProps("div", "text") +}); From a2213d4febefe8444c602df63ff7bbb5f0c8e24a Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 29 Jan 2025 13:42:24 -0300 Subject: [PATCH 3/4] Re-export Modals --- src/utils/modal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/modal.tsx b/src/utils/modal.tsx index 0df8c6a59..d06e58036 100644 --- a/src/utils/modal.tsx +++ b/src/utils/modal.tsx @@ -101,7 +101,7 @@ interface Modals { }>; } -const Modals: Modals = mapMangledModuleLazy(':"thin")', { +export const Modals: Modals = mapMangledModuleLazy(':"thin")', { ModalRoot: filters.componentByCode('.MODAL,"aria-labelledby":'), ModalHeader: filters.componentByCode(",id:"), ModalContent: filters.componentByCode(".content,"), From 5ad35c36e458fb49532da199fcee2e01ac640e44 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:34:44 -0300 Subject: [PATCH 4/4] Make Option.Component not require description Also correctly infers the type from "default" --- src/components/PluginSettings/PluginModal.tsx | 3 ++- .../components/SettingCustomComponent.tsx | 4 +-- .../PluginSettings/components/index.ts | 5 +++- src/plugins/clientTheme/index.tsx | 5 +--- src/plugins/decor/settings.tsx | 1 - src/plugins/ignoreActivities/index.tsx | 4 +-- src/plugins/messageLinkEmbeds/index.tsx | 4 +-- src/plugins/reviewDB/settings.tsx | 2 -- src/plugins/textReplace/index.tsx | 1 - src/utils/types.ts | 25 +++++++++++-------- 10 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/components/PluginSettings/PluginModal.tsx b/src/components/PluginSettings/PluginModal.tsx index 3f7965d58..7baeba081 100644 --- a/src/components/PluginSettings/PluginModal.tsx +++ b/src/components/PluginSettings/PluginModal.tsx @@ -37,6 +37,7 @@ import { Constructor } from "type-fest"; import { PluginMeta } from "~plugins"; import { + ISettingCustomElementProps, ISettingElementProps, SettingBooleanComponent, SettingCustomComponent, @@ -74,7 +75,7 @@ function makeDummyUser(user: { username: string; id?: string; avatar?: string; } return newUser; } -const Components: Record>> = { +const Components: Record | ISettingCustomElementProps>> = { [OptionType.STRING]: SettingTextComponent, [OptionType.NUMBER]: SettingNumericComponent, [OptionType.BIGINT]: SettingNumericComponent, diff --git a/src/components/PluginSettings/components/SettingCustomComponent.tsx b/src/components/PluginSettings/components/SettingCustomComponent.tsx index af7192f3f..25e8c9c6a 100644 --- a/src/components/PluginSettings/components/SettingCustomComponent.tsx +++ b/src/components/PluginSettings/components/SettingCustomComponent.tsx @@ -18,8 +18,8 @@ import { PluginOptionComponent } from "@utils/types"; -import { ISettingElementProps } from "."; +import { ISettingCustomElementProps } from "."; -export function SettingCustomComponent({ option, onChange, onError }: ISettingElementProps) { +export function SettingCustomComponent({ option, onChange, onError }: ISettingCustomElementProps) { return option.component({ setValue: onChange, setError: onError, option }); } diff --git a/src/components/PluginSettings/components/index.ts b/src/components/PluginSettings/components/index.ts index d307b4e68..c38f209b7 100644 --- a/src/components/PluginSettings/components/index.ts +++ b/src/components/PluginSettings/components/index.ts @@ -18,7 +18,7 @@ import { DefinedSettings, PluginOptionBase } from "@utils/types"; -export interface ISettingElementProps { +interface ISettingElementPropsBase { option: T; onChange(newValue: any): void; pluginSettings: { @@ -30,6 +30,9 @@ export interface ISettingElementProps { definedSettings?: DefinedSettings; } +export type ISettingElementProps = ISettingElementPropsBase; +export type ISettingCustomElementProps> = ISettingElementPropsBase; + export * from "../../Badge"; export * from "./SettingBooleanComponent"; export * from "./SettingCustomComponent"; diff --git a/src/plugins/clientTheme/index.tsx b/src/plugins/clientTheme/index.tsx index 4c1668aae..2dc7ccf6c 100644 --- a/src/plugins/clientTheme/index.tsx +++ b/src/plugins/clientTheme/index.tsx @@ -91,15 +91,12 @@ function ThemeSettings() { const settings = definePluginSettings({ color: { - description: "Color your Discord client theme will be based around. Light mode isn't supported", type: OptionType.COMPONENT, default: "313338", - component: () => + component: ThemeSettings }, resetColor: { - description: "Reset Theme Color", type: OptionType.COMPONENT, - default: "313338", component: () => ( + ) } }); diff --git a/src/plugins/reviewDB/settings.tsx b/src/plugins/reviewDB/settings.tsx index eeebd0aa1..2b58d080c 100644 --- a/src/plugins/reviewDB/settings.tsx +++ b/src/plugins/reviewDB/settings.tsx @@ -27,7 +27,6 @@ import { cl } from "./utils"; export const settings = definePluginSettings({ authorize: { type: OptionType.COMPONENT, - description: "Authorize with ReviewDB", component: () => ( diff --git a/src/plugins/textReplace/index.tsx b/src/plugins/textReplace/index.tsx index 3d1e891d1..4bec9b6f9 100644 --- a/src/plugins/textReplace/index.tsx +++ b/src/plugins/textReplace/index.tsx @@ -45,7 +45,6 @@ const makeEmptyRuleArray = () => [makeEmptyRule()]; const settings = definePluginSettings({ replace: { type: OptionType.COMPONENT, - description: "", component: () => { const { stringRules, regexRules } = settings.use(["stringRules", "regexRules"]); diff --git a/src/utils/types.ts b/src/utils/types.ts index 54de59e34..8f0ec3860 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -198,15 +198,16 @@ export type SettingsChecks = { (IsDisabled> & IsValid, DefinedSettings>); }; -export type PluginSettingDef = (PluginSettingCustomDef & Pick) | (( - | PluginSettingStringDef - | PluginSettingNumberDef - | PluginSettingBooleanDef - | PluginSettingSelectDef - | PluginSettingSliderDef - | PluginSettingComponentDef - | PluginSettingBigIntDef -) & PluginSettingCommon); +export type PluginSettingDef = + (PluginSettingCustomDef & Pick) | + (PluginSettingComponentDef & Omit) | (( + | PluginSettingStringDef + | PluginSettingNumberDef + | PluginSettingBooleanDef + | PluginSettingSelectDef + | PluginSettingSliderDef + | PluginSettingBigIntDef + ) & PluginSettingCommon); export interface PluginSettingCommon { description: string; @@ -226,12 +227,14 @@ export interface PluginSettingCommon { */ target?: "WEB" | "DESKTOP" | "BOTH"; } + interface IsDisabled { /** * Checks if this setting should be disabled */ disabled?(this: D): boolean; } + interface IsValid { /** * Prevents the user from saving settings if this is false or a string @@ -320,7 +323,7 @@ type PluginSettingType = O extends PluginSettingStri O extends PluginSettingBooleanDef ? boolean : O extends PluginSettingSelectDef ? O["options"][number]["value"] : O extends PluginSettingSliderDef ? number : - O extends PluginSettingComponentDef ? any : + O extends PluginSettingComponentDef ? O extends { default: infer Default; } ? Default : any : O extends PluginSettingCustomDef ? O extends { default: infer Default; } ? Default : any : never; @@ -382,7 +385,7 @@ export type PluginOptionNumber = (PluginSettingNumberDef | PluginSettingBigIntDe export type PluginOptionBoolean = PluginSettingBooleanDef & PluginSettingCommon & IsDisabled & IsValid; export type PluginOptionSelect = PluginSettingSelectDef & PluginSettingCommon & IsDisabled & IsValid; export type PluginOptionSlider = PluginSettingSliderDef & PluginSettingCommon & IsDisabled & IsValid; -export type PluginOptionComponent = PluginSettingComponentDef & PluginSettingCommon; +export type PluginOptionComponent = PluginSettingComponentDef & Omit; export type PluginOptionCustom = PluginSettingCustomDef & Pick; export type PluginNative any>> = {