more cleanie

This commit is contained in:
Nuckyz 2024-08-23 05:11:07 -03:00
parent 26a71caced
commit 7d4fc5e8e1
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 13 additions and 11 deletions

View file

@ -25,7 +25,7 @@ import { canonicalizeMatch, canonicalizeReplace, canonicalizeReplacement } from
import { SYM_PROXY_INNER_GET, SYM_PROXY_INNER_VALUE } from "@utils/proxyInner";
import definePlugin, { PluginNative, StartAt } from "@utils/types";
import * as Webpack from "@webpack";
import { _cacheFindAll, cacheFindAll, cacheFindModuleId, extract, filters, searchFactories } from "@webpack";
import { cacheFindAll, cacheFindModuleId, extract, filters, searchFactories } from "@webpack";
import * as Common from "@webpack/common";
import { loadLazyChunks } from "debug/loadLazyChunks";
import type { ComponentType } from "react";
@ -56,14 +56,14 @@ function makeShortcuts() {
const cacheKey = String(filterProps);
if (cache.has(cacheKey)) return cache.get(cacheKey);
const matches = _cacheFindAll(filterFactory(...filterProps));
const matches = cacheFindAll(filterFactory(...filterProps), shouldReturnFactory);
const result = (() => {
switch (matches.length) {
case 0: return null;
case 1: return shouldReturnFactory ? matches[0].factory : matches[0].result;
case 1: return matches[0];
default:
const uniqueMatches = [...new Set(shouldReturnFactory ? matches.map(m => m.factory) : matches.map(m => m.result))];
const uniqueMatches = [...new Set(matches)];
if (uniqueMatches.length > 1) {
console.warn(`Warning: This filter matches ${matches.length} modules. Make it more specific!\n`, uniqueMatches);
}
@ -113,7 +113,7 @@ function makeShortcuts() {
findByFactoryCode: newFindWrapper(filters.byFactoryCode),
findAllByFactoryCode: (...code: Webpack.CodeFilter) => cacheFindAll(filters.byFactoryCode(...code)),
findModuleFactory: newFindWrapper(filters.byFactoryCode, true),
findAllModuleFactories: (...code: Webpack.CodeFilter) => _cacheFindAll(filters.byFactoryCode(...code)).map(m => m.factory),
findAllModuleFactories: (...code: Webpack.CodeFilter) => cacheFindAll(filters.byFactoryCode(...code), true),
plugins: { getter: () => Vencord.Plugins.plugins },
PluginsApi: { getter: () => Vencord.Plugins },

View file

@ -716,10 +716,11 @@ export const _cacheFind = traceFunction("cacheFind", function _cacheFind(filter:
* Find the first export or module exports from an already required module that matches the filter.
*
* @param filter A function that takes an export or module exports and returns a boolean
* @returns The found export or module exports, or undefined
* @returns The found export, module exports, module factory, or undefined
*/
export function cacheFind(filter: FilterFn) {
return _cacheFind(filter).result;
export function cacheFind(filter: FilterFn, shouldReturnFactory: boolean = false) {
const { result, factory } = _cacheFind(filter);
return shouldReturnFactory ? factory : result;
}
/**
@ -777,10 +778,11 @@ export function _cacheFindAll(filter: FilterFn): Required<CacheFindResult>[] {
* Find the the export or module exports from an all the required modules that match the filter.
*
* @param filter A function that takes an export or module exports and returns a boolean
* @returns An array of found exports or module exports
* @returns An array of found exports, module exports, or module factories
*/
export function cacheFindAll(filter: FilterFn) {
return _cacheFindAll(filter).map(({ result }) => result);
export function cacheFindAll(filter: FilterFn, shouldReturnFactories: boolean = false) {
const cacheFindAllResults = _cacheFindAll(filter);
return cacheFindAllResults.map(({ result, factory }) => shouldReturnFactories ? factory : result);
}
/**