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

View file

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