From b8dbb345c4edfe0332e17e7d5748846e0bc6aa80 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Tue, 10 Feb 2026 18:14:25 -0500 Subject: [PATCH] Remove Old Section Pushes --- src/equicordplugins/components.dev/index.tsx | 26 +---- src/equicordplugins/iRememberYou/index.tsx | 28 ++--- src/equicordplugins/iconViewer/index.tsx | 26 +---- src/equicordplugins/loginWithQR/index.tsx | 29 +---- src/equicordplugins/themeLibrary/index.tsx | 26 +---- src/plugins/startupTimings/index.tsx | 5 +- src/utils/misc.ts | 5 + src/webpack/patchWebpack.ts | 117 ++++++++++--------- 8 files changed, 96 insertions(+), 166 deletions(-) diff --git a/src/equicordplugins/components.dev/index.tsx b/src/equicordplugins/components.dev/index.tsx index 5e97d073c..68f05fb63 100644 --- a/src/equicordplugins/components.dev/index.tsx +++ b/src/equicordplugins/components.dev/index.tsx @@ -6,8 +6,9 @@ import "./styles.css"; -import SettingsPlugin, { settingsSectionMap } from "@plugins/_core/settings"; +import SettingsPlugin from "@plugins/_core/settings"; import { Devs } from "@utils/constants"; +import { removeFromArray } from "@utils/misc"; import definePlugin, { StartAt } from "@utils/types"; import { SettingsRouter } from "@webpack/common"; @@ -49,32 +50,17 @@ export default definePlugin({ }, }, start() { - const { customEntries, customSections } = SettingsPlugin; - - customEntries.push({ + SettingsPlugin.customEntries.push({ key: "equicord_components", title: "Components", Component: ComponentsTab, Icon: ComponentsIcon }); - customSections.push(() => ({ - section: "EquicordDiscordComponents", - label: "Components", - element: ComponentsTab, - className: "vc-discord-components", - id: "EquicordDiscordComponents" - })); - - settingsSectionMap.push(["EquicordDiscordComponents", "equicord_components"]); + SettingsPlugin.settingsSectionMap.push(["EquicordDiscordComponents", "equicord_components"]); }, stop() { - const { customEntries, customSections } = SettingsPlugin; - const entryIdx = customEntries.findIndex(e => e.key === "equicord_components"); - if (entryIdx !== -1) customEntries.splice(entryIdx, 1); - const sectionIdx = customSections.findIndex(s => s({} as any).id === "EquicordDiscordComponents"); - if (sectionIdx !== -1) customSections.splice(sectionIdx, 1); - const map = settingsSectionMap.findIndex(entry => entry[1] === "equicord_components"); - if (map !== -1) settingsSectionMap.splice(map, 1); + removeFromArray(SettingsPlugin.customEntries, e => e.key === "equicord_components"); + removeFromArray(SettingsPlugin.settingsSectionMap, entry => entry[1] === "equicord_components"); }, }); diff --git a/src/equicordplugins/iRememberYou/index.tsx b/src/equicordplugins/iRememberYou/index.tsx index e2056414b..8b4614331 100644 --- a/src/equicordplugins/iRememberYou/index.tsx +++ b/src/equicordplugins/iRememberYou/index.tsx @@ -8,8 +8,9 @@ import "./styles.css"; import { addMessagePreSendListener, removeMessagePreSendListener } from "@api/MessageEvents"; import { EyeIcon } from "@components/Icons"; -import SettingsPlugin, { settingsSectionMap } from "@plugins/_core/settings"; +import SettingsPlugin from "@plugins/_core/settings"; import { EquicordDevs } from "@utils/constants"; +import { removeFromArray } from "@utils/misc"; import definePlugin from "@utils/types"; import { Data } from "./components/data"; @@ -24,23 +25,13 @@ export default definePlugin({ patches: [], async start() { - const { customEntries, customSections } = SettingsPlugin; - - customEntries.push({ + SettingsPlugin.customEntries.push({ key: "equicord_i_remember_you", title: "I Remember You", Component: () => , Icon: EyeIcon }); - - customSections.push(() => ({ - section: "EquicordIRememberYou", - label: "IRememberYou", - element: () => , - id: "EquicordIRememberYou" - })); - - settingsSectionMap.push(["EquicordIRememberYou", "equicord_i_remember_you"]); + SettingsPlugin.settingsSectionMap.push(["EquicordIRememberYou", "equicord_i_remember_you"]); const data = (this.dataManager = await new Data().withStart()); @@ -54,15 +45,10 @@ export default definePlugin({ }, stop() { - const dataManager = this.dataManager as Data; - const { customEntries, customSections } = SettingsPlugin; - const entry = customEntries.findIndex(entry => entry.key === "equicord_i_remember_you"); - if (entry !== -1) customEntries.splice(entry, 1); - const section = customSections.findIndex(section => section({} as any).id === "EquicordIRememberYou"); - if (section !== -1) customSections.splice(section, 1); - const map = settingsSectionMap.findIndex(entry => entry[1] === "equicord_i_remember_you"); - if (map !== -1) settingsSectionMap.splice(map, 1); + removeFromArray(SettingsPlugin.customEntries, e => e.key === "equicord_i_remember_you"); + removeFromArray(SettingsPlugin.settingsSectionMap, entry => entry[1] === "equicord_i_remember_you"); + const dataManager = this.dataManager as Data; removeMessagePreSendListener(dataManager._onMessagePreSend_preSend); clearInterval(dataManager._storageAutoSaveProtocol_interval); }, diff --git a/src/equicordplugins/iconViewer/index.tsx b/src/equicordplugins/iconViewer/index.tsx index 5c4871526..f2135cbf2 100644 --- a/src/equicordplugins/iconViewer/index.tsx +++ b/src/equicordplugins/iconViewer/index.tsx @@ -7,8 +7,9 @@ import "./styles.css"; import { MagnifyingGlassIcon } from "@components/Icons"; -import SettingsPlugin, { settingsSectionMap } from "@plugins/_core/settings"; +import SettingsPlugin from "@plugins/_core/settings"; import { EquicordDevs } from "@utils/constants"; +import { removeFromArray } from "@utils/misc"; import definePlugin, { StartAt } from "@utils/types"; import { SettingsRouter } from "@webpack/common"; @@ -28,32 +29,17 @@ export default definePlugin({ }, settingsAboutComponent: SettingsAbout, start() { - const { customEntries, customSections } = SettingsPlugin; - - customEntries.push({ + SettingsPlugin.customEntries.push({ key: "equicord_icon_viewer", title: "Icon Finder", Component: IconsTab, Icon: MagnifyingGlassIcon }); - customSections.push(() => ({ - section: "EquicordDiscordIcons", - label: "Icon Finder", - element: IconsTab, - className: "vc-discord-icons", - id: "EquicordIconViewer" - })); - - settingsSectionMap.push(["EquicordDiscordIcons", "equicord_icon_viewer"]); + SettingsPlugin.settingsSectionMap.push(["EquicordDiscordIcons", "equicord_icon_viewer"]); }, stop() { - const { customEntries, customSections } = SettingsPlugin; - const entryIdx = customEntries.findIndex(e => e.key === "equicord_icon_viewer"); - if (entryIdx !== -1) customEntries.splice(entryIdx, 1); - const sectionIdx = customSections.findIndex(s => s({} as any).id === "EquicordIconViewer"); - if (sectionIdx !== -1) customSections.splice(sectionIdx, 1); - const map = settingsSectionMap.findIndex(entry => entry[1] === "equicord_icon_viewer"); - if (map !== -1) settingsSectionMap.splice(map, 1); + removeFromArray(SettingsPlugin.customEntries, e => e.key === "equicord_icon_viewer"); + removeFromArray(SettingsPlugin.settingsSectionMap, entry => entry[1] === "equicord_icon_viewer"); }, }); diff --git a/src/equicordplugins/loginWithQR/index.tsx b/src/equicordplugins/loginWithQR/index.tsx index be35d1f87..54d15387b 100644 --- a/src/equicordplugins/loginWithQR/index.tsx +++ b/src/equicordplugins/loginWithQR/index.tsx @@ -7,9 +7,10 @@ import { plugins } from "@api/PluginManager"; import { definePluginSettings } from "@api/Settings"; import { Paragraph } from "@components/Paragraph"; -import SettingsPlugin, { settingsSectionMap } from "@plugins/_core/settings"; +import SettingsPlugin from "@plugins/_core/settings"; import { EquicordDevs } from "@utils/constants"; import { getIntlMessage } from "@utils/discord"; +import { removeFromArray } from "@utils/misc"; import definePlugin, { OptionType } from "@utils/types"; import { Button } from "@webpack/common"; @@ -59,37 +60,19 @@ export default definePlugin({ qrModalOpen: false, start() { - const { customEntries, customSections } = SettingsPlugin; - - customEntries.push({ + SettingsPlugin.customEntries.push({ key: "equicord_login_with_qr", title: getIntlMessage("USER_SETTINGS_SCAN_QR_CODE"), Component: openQrModal, Icon: QrCodeIcon }); - - customSections.push(() => ({ - section: "EquicordLoginWithQR", - label: getIntlMessage("USER_SETTINGS_SCAN_QR_CODE"), - searchableTitles: [getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")], - element: openQrModal, - id: "EquicordLoginWithQR", - })); - - settingsSectionMap.push(["EquicordLoginWithQR", "equicord_login_with_qr"]); - + SettingsPlugin.settingsSectionMap.push(["EquicordLoginWithQR", "equicord_login_with_qr"]); preload(); }, stop() { - const { customEntries, customSections } = SettingsPlugin; - const entry = customEntries.findIndex(entry => entry.key === "equicord_login_with_qr"); - if (entry !== -1) customEntries.splice(entry, 1); - const section = customSections.findIndex(section => section({} as any).id === "EquicordLoginWithQR"); - if (section !== -1) customSections.splice(section, 1); - const map = settingsSectionMap.findIndex(entry => entry[1] === "equicord_login_with_qr"); - if (map !== -1) settingsSectionMap.splice(map, 1); - + removeFromArray(SettingsPlugin.customEntries, e => e.key === "equicord_login_with_qr"); + removeFromArray(SettingsPlugin.settingsSectionMap, entry => entry[1] === "equicord_login_with_qr"); unload(); }, }); diff --git a/src/equicordplugins/themeLibrary/index.tsx b/src/equicordplugins/themeLibrary/index.tsx index c561ba04c..befdadca0 100644 --- a/src/equicordplugins/themeLibrary/index.tsx +++ b/src/equicordplugins/themeLibrary/index.tsx @@ -5,8 +5,9 @@ */ import { ColorPaletteIcon } from "@components/Icons"; -import SettingsPlugin, { settingsSectionMap } from "@plugins/_core/settings"; +import SettingsPlugin from "@plugins/_core/settings"; import { EquicordDevs } from "@utils/constants"; +import { removeFromArray } from "@utils/misc"; import definePlugin from "@utils/types"; import { SettingsRouter } from "@webpack/common"; @@ -24,33 +25,18 @@ export default definePlugin({ }, start() { - const { customEntries, customSections } = SettingsPlugin; - - customEntries.push({ + SettingsPlugin.customEntries.push({ key: "theme_library", title: "Theme Library", Component: require("./components/ThemeTab").default, Icon: ColorPaletteIcon }); - customSections.push(() => ({ - section: "EquicordThemeLibrary", - label: "Theme Library", - searchableTitles: ["Theme Library"], - element: require("./components/ThemeTab").default, - id: "EquicordThemeLibrary", - })); - - settingsSectionMap.push(["EquicordThemeLibrary", "equicord_theme_library"]); + SettingsPlugin.settingsSectionMap.push(["EquicordThemeLibrary", "equicord_theme_library"]); }, stop() { - const { customEntries, customSections } = SettingsPlugin; - const entry = customEntries.findIndex(entry => entry.key === "equicord_theme_library"); - if (entry !== -1) customEntries.splice(entry, 1); - const section = customSections.findIndex(section => section({} as any).id === "EquicordThemeLibrary"); - if (section !== -1) customSections.splice(section, 1); - const map = settingsSectionMap.findIndex(entry => entry[1] === "equicord_theme_library"); - if (map !== -1) settingsSectionMap.splice(map, 1); + removeFromArray(SettingsPlugin.customEntries, e => e.key === "equicord_theme_library"); + removeFromArray(SettingsPlugin.settingsSectionMap, entry => entry[1] === "equicord_theme_library"); }, }); diff --git a/src/plugins/startupTimings/index.tsx b/src/plugins/startupTimings/index.tsx index 2a8eac3c0..3b92c5f04 100644 --- a/src/plugins/startupTimings/index.tsx +++ b/src/plugins/startupTimings/index.tsx @@ -19,6 +19,7 @@ import { ClockIcon } from "@components/Icons"; import SettingsPlugin from "@plugins/_core/settings"; import { Devs } from "@utils/constants"; +import { removeFromArray } from "@utils/misc"; import definePlugin from "@utils/types"; import StartupTimingPage from "./StartupTimingPage"; @@ -37,10 +38,6 @@ export default definePlugin({ SettingsPlugin.settingsSectionMap.push(["VencordStartupTimings", "vencord_startup_timings"]); }, stop() { - function removeFromArray(arr: T[], predicate: (e: T) => boolean) { - const idx = arr.findIndex(predicate); - if (idx !== -1) arr.splice(idx, 1); - } removeFromArray(SettingsPlugin.customEntries, e => e.key === "vencord_startup_timings"); removeFromArray(SettingsPlugin.settingsSectionMap, entry => entry[1] === "vencord_startup_timings"); }, diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 0c27b15da..28582ddd1 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -123,3 +123,8 @@ export function isEquicordSupport(userId: string | null | undefined): boolean { const member = GuildMemberStore.getMember(GUILD_ID, userId); return member?.roles?.includes(EQUICORD_HELPERS) || false; } + +export function removeFromArray(arr: T[], predicate: (e: T) => boolean) { + const idx = arr.findIndex(predicate); + if (idx !== -1) arr.splice(idx, 1); +} diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 66247fc5b..fb31cbc23 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -627,71 +627,72 @@ function patchFactory(moduleId: PropertyKey, originalFactory: AnyModuleFactory): if (IS_DEV) { diffErroredPatch(code, lastCode, lastCode.match(replacement.match)!); } - - if (markedAsPatched) { - patchedBy.delete(patch.plugin); - } - - if (patch.group) { - logger.warn(`Undoing patch group ${patch.find} by ${patch.plugin} because replacement ${replacement.match} errored`); - if (IS_COMPANION_TEST) - reporterData.failedPatches.undoingPatchGroup.push({ - ...patch, - id: moduleId - }); - code = previousCode; - patchedFactory = previousFactory; - break; - } - - code = lastCode; - patchedFactory = lastFactory; } - } - if (!patch.all) { - patches.splice(i--, 1); + if (markedAsPatched) { + patchedBy.delete(patch.plugin); + } + + if (patch.group) { + logger.warn(`Undoing patch group ${patch.find} by ${patch.plugin} because replacement ${replacement.match} errored`); + if (IS_COMPANION_TEST) + reporterData.failedPatches.undoingPatchGroup.push({ + ...patch, + id: moduleId + }); + code = previousCode; + patchedFactory = previousFactory; + break; + } + + code = lastCode; + patchedFactory = lastFactory; } } - patchedFactory[SYM_ORIGINAL_FACTORY] = originalFactory; - - if (IS_DEV && patchedFactory !== originalFactory) { - originalFactory[SYM_PATCHED_SOURCE] = patchedSource; - originalFactory[SYM_PATCHED_BY] = patchedBy; + if (!patch.all) { + patches.splice(i--, 1); } - - return patchedFactory as PatchedModuleFactory; } - function diffErroredPatch(code: string, lastCode: string, match: RegExpMatchArray) { - const changeSize = code.length - lastCode.length; + patchedFactory[SYM_ORIGINAL_FACTORY] = originalFactory; - // Use 200 surrounding characters of context - const start = Math.max(0, match.index! - 200); - const end = Math.min(lastCode.length, match.index! + match[0].length + 200); - // (changeSize may be negative) - const endPatched = end + changeSize; - - const context = lastCode.slice(start, end); - const patchedContext = code.slice(start, endPatched); - - // Inline require to avoid including it in !IS_DEV builds - const diff = (require("diff") as typeof import("diff")).diffWordsWithSpace(context, patchedContext); - let fmt = "%c %s "; - const elements: string[] = []; - for (const d of diff) { - const color = d.removed - ? "red" - : d.added - ? "lime" - : "grey"; - fmt += "%c%s"; - elements.push("color:" + color, d.value); - } - - logger.errorCustomFmt(...Logger.makeTitle("white", "Before"), context); - logger.errorCustomFmt(...Logger.makeTitle("white", "After"), patchedContext); - const [titleFmt, ...titleElements] = Logger.makeTitle("white", "Diff"); - logger.errorCustomFmt(titleFmt + fmt, ...titleElements, ...elements); + if (IS_DEV && patchedFactory !== originalFactory) { + originalFactory[SYM_PATCHED_SOURCE] = patchedSource; + originalFactory[SYM_PATCHED_BY] = patchedBy; } + + return patchedFactory as PatchedModuleFactory; +} + +function diffErroredPatch(code: string, lastCode: string, match: RegExpMatchArray) { + const changeSize = code.length - lastCode.length; + + // Use 200 surrounding characters of context + const start = Math.max(0, match.index! - 200); + const end = Math.min(lastCode.length, match.index! + match[0].length + 200); + // (changeSize may be negative) + const endPatched = end + changeSize; + + const context = lastCode.slice(start, end); + const patchedContext = code.slice(start, endPatched); + + // Inline require to avoid including it in !IS_DEV builds + const diff = (require("diff") as typeof import("diff")).diffWordsWithSpace(context, patchedContext); + let fmt = "%c %s "; + const elements: string[] = []; + for (const d of diff) { + const color = d.removed + ? "red" + : d.added + ? "lime" + : "grey"; + fmt += "%c%s"; + elements.push("color:" + color, d.value); + } + + logger.errorCustomFmt(...Logger.makeTitle("white", "Before"), context); + logger.errorCustomFmt(...Logger.makeTitle("white", "After"), patchedContext); + const [titleFmt, ...titleElements] = Logger.makeTitle("white", "Diff"); + logger.errorCustomFmt(titleFmt + fmt, ...titleElements, ...elements); +}