DevCompaion: fix bug where extracting via find will sometimes search for [object Object] (#1173)

This commit is contained in:
sadan4 2026-06-12 22:49:41 -04:00 • committed by GitHub
parent 90b4eb14ba
commit e215e7230c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 17 deletions

View file

@ -17,7 +17,7 @@ import { React, Toasts, useState } from "@webpack/common";
import { CLIENT_VERSION, logger, PORT, settings } from ".";
import { Recieve } from "./types";
import { FullOutgoingMessage, OutgoingMessage } from "./types/send";
import { extractModule, extractOrThrow, findModuleId, getModulePatchedBy, mkRegexFind, parseNode, toggleEnabled, } from "./util";
import { extractModule, extractOrThrow, findAllModuleIds, findModuleId, getModulePatchedBy, mkRegexFind, parseNode, toggleEnabled, } from "./util";
export function stopWs() {
socket?.close(1000, "Plugin Stopped");
@ -256,47 +256,47 @@ export function initWs(isManual = false) {
}
try {
let results: any[];
let moduleIds: string[];
switch (m.findType.replace("find", "").replace("Lazy", "")) {
case "":
case "Component":
results = findAll(parsedArgs[0]);
moduleIds = findAllModuleIds(parsedArgs[0]);
break;
case "CssClasses":
results = findAll(filters.byClassNames(...parsedArgs), { topLevelOnly: true });
moduleIds = findAllModuleIds(filters.byClassNames(...parsedArgs), { topLevelOnly: true });
break;
case "ByProps":
results = findAll(filters.byProps(...parsedArgs));
moduleIds = findAllModuleIds(filters.byProps(...parsedArgs));
break;
case "Store":
results = findAll(filters.byStoreName(parsedArgs[0]));
moduleIds = findAllModuleIds(filters.byStoreName(parsedArgs[0]));
break;
case "ByCode":
results = findAll(filters.byCode(...parsedArgs));
moduleIds = findAllModuleIds(filters.byCode(...parsedArgs));
break;
case "ModuleId":
results = Object.keys(search(parsedArgs[0]));
moduleIds = Object.keys(search(parsedArgs[0]));
break;
case "ComponentByCode":
results = findAll(filters.componentByCode(...parsedArgs));
moduleIds = findAllModuleIds(filters.componentByCode(...parsedArgs));
break;
default:
return reply("Unknown Find Type " + m.findType);
}
const uniqueResultsCount = new Set(results).size;
if (uniqueResultsCount === 0) throw "No results";
if (uniqueResultsCount > 1) throw "Found more than one result! Make this filter more specific";
const uniqueModuleIds = new Set(moduleIds).size;
if (uniqueModuleIds === 0) throw "No results";
if (uniqueModuleIds > 1) throw "Found more than one result! Make this filter more specific";
// best name ever
const foundFind: string = [...results][0].toString();
const [foundId] = moduleIds;
replyData({
type: "extract",
ok: true,
data: {
module: foundFind,
module: extractModule(foundId),
find: true,
moduleNumber: +findModuleId([foundFind]),
patchedBy: getModulePatchedBy(foundFind)
moduleNumber: +foundId,
patchedBy: getModulePatchedBy(foundId)
},
});
} catch (err) {

View file

@ -8,7 +8,8 @@ import { showNotice } from "@api/Notices";
import { plugins, startDependenciesRecursive, startPlugin, stopPlugin } from "@api/PluginManager";
import { Settings } from "@api/Settings";
import { canonicalizeMatch } from "@utils/patches";
import { CodeFilter, stringMatches, wreq } from "@webpack";
import { Module } from "@vencord/discord-types/webpack";
import { CodeFilter, FilterFn, stringMatches, wreq } from "@webpack";
import { Toasts } from "@webpack/common";
import { WebpackPatcher } from "../../Vencord";
@ -193,3 +194,31 @@ export function toggleEnabled(name: string, beforeReload: (error?: string) => vo
settings.enabled = !wasEnabled;
beforeReturn();
}
export function findAllModuleIds(filter: FilterFn, { topLevelOnly = false }: { topLevelOnly?: boolean; } = {}): string[] {
const { c } = wreq;
const ret: string[] = [];
outer: for (const key in c) {
const mod: Module | undefined = c[key];
if (!mod?.loaded || mod.exports == null) {
continue;
}
if (filter(mod.exports)) {
ret.push(key);
continue;
}
if (typeof mod.exports !== "object" || topLevelOnly) {
continue;
}
for (const nestedMod in mod.exports) {
const nested = mod.exports[nestedMod];
if (nested && filter(nested)) {
ret.push(key);
continue outer;
}
}
}
return ret;
}