Fix testing factory filters on non factories

This commit is contained in:
Nuckyz 2024-07-11 17:32:36 -03:00
parent aa35602827
commit 56477d4e96
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 25 additions and 11 deletions

View file

@ -631,8 +631,12 @@ export const _cacheFind = traceFunction("cacheFind", function _cacheFind(filter:
const mod = cache[key]; const mod = cache[key];
if (!mod?.loaded || mod?.exports == null) continue; if (!mod?.loaded || mod?.exports == null) continue;
if (filter.$$vencordIsFactoryFilter && filter(wreq.m[key])) { if (filter.$$vencordIsFactoryFilter) {
return { result: mod.exports, id: key, exportKey: null, factory: wreq.m[key] }; if (filter(wreq.m[key])) {
return { result: mod.exports, id: key, exportKey: null, factory: wreq.m[key] };
}
continue;
} }
if (filter(mod.exports)) { if (filter(mod.exports)) {
@ -686,8 +690,12 @@ export function cacheFindAll(filter: FilterFn) {
const mod = cache[key]; const mod = cache[key];
if (!mod?.loaded || mod?.exports == null) continue; if (!mod?.loaded || mod?.exports == null) continue;
if (filter.$$vencordIsFactoryFilter && filter(wreq.m[key])) { if (filter.$$vencordIsFactoryFilter) {
ret.push(mod.exports); if (filter(wreq.m[key])) {
ret.push(mod.exports);
}
continue;
} }
if (filter(mod.exports)) { if (filter(mod.exports)) {
@ -754,11 +762,14 @@ export const cacheFindBulk = traceFunction("cacheFindBulk", function cacheFindBu
const filter = filters[i]; const filter = filters[i];
if (filter == null) continue; if (filter == null) continue;
if (filter.$$vencordIsFactoryFilter && filter(wreq.m[key])) { if (filter.$$vencordIsFactoryFilter) {
results[i] = mod.exports; if (filter(wreq.m[key])) {
filters[i] = undefined; results[i] = mod.exports;
filters[i] = undefined;
if (++found === length) break outer;
}
if (++found === length) break outer;
break; break;
} }

View file

@ -202,9 +202,12 @@ function patchFactories(factories: Record<string, (module: any, exports: any, re
for (const [filter, callback] of waitForSubscriptions) { for (const [filter, callback] of waitForSubscriptions) {
try { try {
if (filter.$$vencordIsFactoryFilter && filter(originalMod)) { if (filter.$$vencordIsFactoryFilter) {
waitForSubscriptions.delete(filter); if (filter(originalMod)) {
callback(exports, { id, exportKey: null, factory: originalMod }); waitForSubscriptions.delete(filter);
callback(exports, { id, exportKey: null, factory: originalMod });
}
continue; continue;
} }