Simplify some components finds; Make undo of patch groups more clear

This commit is contained in:
Nuckyz 2023-11-24 23:14:18 -03:00
parent 6573c4757c
commit 1b179f3c6d
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
3 changed files with 6 additions and 14 deletions

View file

@ -20,17 +20,12 @@ import { definePluginSettings, Settings } 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 { find, findStoreLazy, LazyComponentWebpack } from "@webpack"; import { findExportedComponentLazy, findStoreLazy } from "@webpack";
import { ChannelStore, GuildMemberStore, i18n, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; import { ChannelStore, GuildMemberStore, i18n, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
import { buildSeveralUsers } from "../typingTweaks"; import { buildSeveralUsers } from "../typingTweaks";
const ThreeDots = LazyComponentWebpack(() => { const ThreeDots = findExportedComponentLazy("Dots", "AnimatedDots");
// This doesn't really need to explicitly find Dots' own module, but it's fine
const res = find(m => m.Dots && !m.Menu);
return res?.Dots;
});
const TypingStore = findStoreLazy("TypingStore"); const TypingStore = findStoreLazy("TypingStore");
const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore"); const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore");

View file

@ -23,14 +23,11 @@ import { Settings } 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 from "@utils/types"; import definePlugin from "@utils/types";
import { filters, find, LazyComponentWebpack } from "@webpack"; import { findExportedComponentLazy } from "@webpack";
import { Menu, Popout, useState } from "@webpack/common"; import { Menu, Popout, useState } from "@webpack/common";
import type { ReactNode } from "react"; import type { ReactNode } from "react";
const HeaderBarIcon = LazyComponentWebpack(() => { const HeaderBarIcon = findExportedComponentLazy("Icon", "Divider");
const filter = filters.byCode(".HEADER_BAR_BADGE");
return find(m => m.Icon && filter(m.Icon))?.Icon;
});
function VencordPopout(onClose: () => void) { function VencordPopout(onClose: () => void) {
const pluginEntries = [] as ReactNode[]; const pluginEntries = [] as ReactNode[];

View file

@ -212,7 +212,7 @@ function patchFactories(factories: Record<string | number, (module: { exports: a
} }
if (patch.group) { if (patch.group) {
logger.warn(`Undoing patch ${patch.find} by ${patch.plugin} because replacement ${replacement.match} had no effect`); logger.warn(`Undoing patch group ${patch.find} by ${patch.plugin} because replacement ${replacement.match} had no effect`);
code = previousCode; code = previousCode;
mod = previousMod; mod = previousMod;
patchedBy.delete(patch.plugin); patchedBy.delete(patch.plugin);
@ -260,7 +260,7 @@ function patchFactories(factories: Record<string | number, (module: { exports: a
patchedBy.delete(patch.plugin); patchedBy.delete(patch.plugin);
if (patch.group) { if (patch.group) {
logger.warn(`Undoing patch ${patch.find} by ${patch.plugin} because replacement ${replacement.match} errored`); logger.warn(`Undoing patch group ${patch.find} by ${patch.plugin} because replacement ${replacement.match} errored`);
code = previousCode; code = previousCode;
mod = previousMod; mod = previousMod;
break; break;