diff options
author | Nuckyz <61953774+Nuckyz@users.noreply.github.com> | 2023-03-08 01:59:50 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-08 01:59:50 -0300 |
commit | 1b199ec5d8e0ca3805a9960323ddd267561b4cf6 (patch) | |
tree | ccc2bdc72a70e0c0ca220953fa881af1f52a4751 /src/webpack/webpack.ts | |
parent | 40395d562aeadaeaa88c5bc106797ea5a4ee51e4 (diff) | |
download | Vencord-1b199ec5d8e0ca3805a9960323ddd267561b4cf6.tar.gz Vencord-1b199ec5d8e0ca3805a9960323ddd267561b4cf6.tar.bz2 Vencord-1b199ec5d8e0ca3805a9960323ddd267561b4cf6.zip |
feat: Context Menu API (#496)
Diffstat (limited to 'src/webpack/webpack.ts')
-rw-r--r-- | src/webpack/webpack.ts | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 98a0ea8..0d95587 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -57,7 +57,7 @@ export const filters = { export const subscriptions = new Map<FilterFn, CallbackFn>(); export const listeners = new Set<CallbackFn>(); -export type CallbackFn = (mod: any) => void; +export type CallbackFn = (mod: any, id: number) => void; export function _initWebpack(instance: typeof window.webpackChunkdiscord_app) { if (cache !== void 0) throw "no."; @@ -86,18 +86,23 @@ export const find = traceFunction("find", function find(filter: FilterFn, getDef const mod = cache[key]; if (!mod?.exports) continue; - if (filter(mod.exports)) - return mod.exports; + if (filter(mod.exports)) { + return isWaitFor ? [mod.exports, Number(key)] : mod.exports; + } if (typeof mod.exports !== "object") continue; - if (mod.exports.default && filter(mod.exports.default)) - return getDefault ? mod.exports.default : mod.exports; + if (mod.exports.default && filter(mod.exports.default)) { + const found = getDefault ? mod.exports.default : mod.exports; + return isWaitFor ? [found, Number(key)] : found; + } // the length check makes search about 20% faster for (const nestedMod in mod.exports) if (nestedMod.length <= 3) { const nested = mod.exports[nestedMod]; - if (nested && filter(nested)) return nested; + if (nested && filter(nested)) { + return isWaitFor ? [nested, Number(key)] : nested; + } } } @@ -112,7 +117,7 @@ export const find = traceFunction("find", function find(filter: FilterFn, getDef } } - return null; + return isWaitFor ? [null, null] : null; }); /** @@ -347,8 +352,8 @@ export function waitFor(filter: string | string[] | FilterFn, callback: Callback else if (typeof filter !== "function") throw new Error("filter must be a string, string[] or function, got " + typeof filter); - const existing = find(filter!, true, true); - if (existing) return void callback(existing); + const [existing, id] = find(filter!, true, true); + if (existing) return void callback(existing, id); subscriptions.set(filter, callback); } |