Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckyz committed Jan 28, 2025
1 parent cdc7561 commit 9dac8a6
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/plugins/fullSearchContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import { NoopComponent } from "@utils/react";
import definePlugin from "@utils/types";
import { filters, findByPropsLazy, waitFor } from "@webpack";
import { filters, findByCodeLazy, waitFor } from "@webpack";
import { ChannelStore, ContextMenuApi, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";

const { useMessageMenu } = findByPropsLazy("useMessageMenu");
const useMessageMenu = findByCodeLazy(".MESSAGE,commandTargetId:");

interface CopyIdMenuItemProps {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/gameActivityToggle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { findComponentByCodeLazy } from "@webpack";

import style from "./style.css?managed";

const Button = findComponentByCodeLazy("Button.Sizes.NONE,disabled:");
const Button = findComponentByCodeLazy(".NONE,disabled:", ".PANEL_BUTTON");

const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame")!;

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/messageLatency/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { isNonNullish } from "@utils/guards";
import definePlugin, { OptionType } from "@utils/types";
import { findExportedComponentLazy } from "@webpack";
import { findComponentByCodeLazy } from "@webpack";
import { SnowflakeUtils, Tooltip } from "@webpack/common";
import { Message } from "discord-types/general";

Expand All @@ -26,7 +26,7 @@ interface Diff {
}

const DISCORD_KT_DELAY = 1471228928;
const HiddenVisually = findExportedComponentLazy("HiddenVisually");
const HiddenVisually = findComponentByCodeLazy(".hiddenVisually]:");

export default definePlugin({
name: "MessageLatency",
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/pinDms/components/CreateCategoryModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { classNameFactory } from "@api/Styles";
import { ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModalLazy } from "@utils/modal";
import { extractAndLoadChunksLazy, findComponentByCodeLazy, findExportedComponentLazy } from "@webpack";
import { extractAndLoadChunksLazy, findComponentByCodeLazy } from "@webpack";
import { Button, Forms, Text, TextInput, Toasts, useMemo, useState } from "@webpack/common";

import { DEFAULT_COLOR, SWATCHES } from "../constants";
Expand All @@ -30,7 +30,7 @@ interface ColorPickerWithSwatchesProps {
}

const ColorPicker = findComponentByCodeLazy<ColorPickerProps>("#{intl::USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR}", ".BACKGROUND_PRIMARY)");
const ColorPickerWithSwatches = findExportedComponentLazy<ColorPickerWithSwatchesProps>("ColorPicker", "CustomColorPicker");
const ColorPickerWithSwatches = findComponentByCodeLazy<ColorPickerWithSwatchesProps>('id:"color-picker"');

export const requireSettingsMenu = extractAndLoadChunksLazy(['name:"UserSettings"'], /createPromise:.{0,20}(\i\.\i\("?.+?"?\).*?).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/);

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/platformIndicators/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy, findStoreLazy } from "@webpack";
import { findByCodeLazy, findStoreLazy } from "@webpack";
import { PresenceStore, Tooltip, UserStore } from "@webpack/common";
import { User } from "discord-types/general";

Expand Down Expand Up @@ -70,7 +70,7 @@ const Icons = {
};
type Platform = keyof typeof Icons;

const StatusUtils = findByPropsLazy("useStatusFillColor", "StatusTypes");
const useStatusFillColor = findByCodeLazy('"useStatusFillColor"');

const PlatformIcon = ({ platform, status, small }: { platform: Platform, status: string; small: boolean; }) => {
const tooltip = platform === "embedded"
Expand All @@ -79,7 +79,7 @@ const PlatformIcon = ({ platform, status, small }: { platform: Platform, status:

const Icon = Icons[platform] ?? Icons.desktop;

return <Icon color={StatusUtils.useStatusFillColor(status)} tooltip={tooltip} small={small} />;
return <Icon color={useStatusFillColor(status)} tooltip={tooltip} small={small} />;
};

function ensureOwnStatus(user: User) {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/typingIndicator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { findComponentByCodeLazy, findExportedComponentLazy, findStoreLazy } from "@webpack";
import { findComponentByCodeLazy, findStoreLazy } from "@webpack";
import { GuildMemberStore, RelationshipStore, SelectedChannelStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";

import { buildSeveralUsers } from "../typingTweaks";

const ThreeDots = findExportedComponentLazy("Dots", "AnimatedDots");
const ThreeDots = findComponentByCodeLazy(".dots,", "dotRadius:");
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");

const TypingStore = findStoreLazy("TypingStore");
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/userVoiceShow/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const VoiceStateStore = findStoreLazy("VoiceStateStore");

const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
const Avatar = findComponentByCodeLazy(".status)/2):0");
const GroupDMAvatars = findComponentByCodeLazy(".AvatarSizeSpecs[", "getAvatarURL");
const GroupDMAvatars = findComponentByCodeLazy("frontSrc:", "getAvatarURL");

const ActionButtonClasses = findByPropsLazy("actionButton", "highlight");

Expand Down
46 changes: 30 additions & 16 deletions src/webpack/patchWebpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,40 @@ function patchFactories(factories: Record<string, (module: any, exports: any, re

if (!exports) return;

// There are (at the time of writing) 11 modules exporting the window
// Make these non enumerable to improve webpack search performance
if (require.c) {
let foundWindow = false;

if (exports === window) {
foundWindow = true;
} else if (typeof exports === "object") {
if (exports?.default === window) {
foundWindow = true;
} else {
for (const nested in exports) if (nested.length <= 3) {
if (exports[nested] === window) {
foundWindow = true;
}
let shouldMakeNonEnumerable = false;

nonEnumerableChecking: {
// There are (at the time of writing) 11 modules exporting the window,
// and also modules exporting DOMTokenList, which breaks webpack finding
// Make these non enumerable to improve search performance and avoid erros
if (exports === window) {
shouldMakeNonEnumerable = true;
break nonEnumerableChecking;
}

if (typeof exports !== "object") {
break nonEnumerableChecking;
}

if (exports instanceof DOMTokenList) {
shouldMakeNonEnumerable = true;
break nonEnumerableChecking;
}

if (exports.default === window || exports.default instanceof DOMTokenList) {
shouldMakeNonEnumerable = true;
break nonEnumerableChecking;
}

for (const nested in exports) {
if (exports[nested] === window || exports[nested] instanceof DOMTokenList) {
shouldMakeNonEnumerable = true;
}
}
}

if (foundWindow) {
if (shouldMakeNonEnumerable) {
Object.defineProperty(require.c, id, {
value: require.c[id],
enumerable: false,
Expand Down Expand Up @@ -221,7 +235,7 @@ function patchFactories(factories: Record<string, (module: any, exports: any, re
subscriptions.delete(filter);
callback(exports.default, id);
} else {
for (const nested in exports) if (nested.length <= 3) {
for (const nested in exports) {
if (exports[nested] && filter(exports[nested])) {
subscriptions.delete(filter);
callback(exports[nested], id);
Expand Down
22 changes: 10 additions & 12 deletions src/webpack/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ export const find = traceFunction("find", function find(filter: FilterFn, { isIn
return isWaitFor ? [found, key] : found;
}

// the length check makes search about 20% faster
for (const nestedMod in mod.exports) if (nestedMod.length <= 3) {
for (const nestedMod in mod.exports) {
const nested = mod.exports[nestedMod];
if (nested && filter(nested)) {
return isWaitFor ? [nested, key] : nested;
Expand Down Expand Up @@ -163,7 +162,7 @@ export function findAll(filter: FilterFn) {

if (mod.exports.default && filter(mod.exports.default))
ret.push(mod.exports.default);
else for (const nestedMod in mod.exports) if (nestedMod.length <= 3) {
else for (const nestedMod in mod.exports) {
const nested = mod.exports[nestedMod];
if (nested && filter(nested)) ret.push(nested);
}
Expand Down Expand Up @@ -226,16 +225,15 @@ export const findBulk = traceFunction("findBulk", function findBulk(...filterFns
break;
}

for (const nestedMod in mod.exports)
if (nestedMod.length <= 3) {
const nested = mod.exports[nestedMod];
if (nested && filter(nested)) {
results[j] = nested;
filters[j] = undefined;
if (++found === length) break outer;
continue outer;
}
for (const nestedMod in mod.exports) {
const nested = mod.exports[nestedMod];
if (nested && filter(nested)) {
results[j] = nested;
filters[j] = undefined;
if (++found === length) break outer;
continue outer;
}
}
}
}

Expand Down

0 comments on commit 9dac8a6

Please sign in to comment.