From 962eaa9df77247cffcd4735f68afd6a0028be920 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 27 Jun 2024 18:57:57 -0300 Subject: [PATCH] this was too hacky and causing issues already --- src/utils/lazy.ts | 9 +-------- src/utils/proxyInner.ts | 11 ++--------- src/utils/types.ts | 4 ---- src/webpack/api.tsx | 21 ++++++++++----------- 4 files changed, 13 insertions(+), 32 deletions(-) diff --git a/src/utils/lazy.ts b/src/utils/lazy.ts index aa7bf4574..74e3cc6b8 100644 --- a/src/utils/lazy.ts +++ b/src/utils/lazy.ts @@ -4,13 +4,6 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -import { AnyObject } from "./types"; - -export type ProxyLazy = T & { - [SYM_LAZY_GET]: () => T; - [SYM_LAZY_CACHED]: T | undefined; -}; - export const SYM_LAZY_GET = Symbol.for("vencord.lazy.get"); export const SYM_LAZY_CACHED = Symbol.for("vencord.lazy.cached"); @@ -80,7 +73,7 @@ const handler: ProxyHandler = { * @param attempts How many times to try to evaluate the factory before giving up * @returns Result of factory function */ -export function proxyLazy(factory: () => T, attempts = 5): ProxyLazy { +export function proxyLazy(factory: () => T, attempts = 5): T { const get = makeLazy(factory, attempts, { isIndirect: true }); const proxyDummy = Object.assign(function () { }, { diff --git a/src/utils/proxyInner.ts b/src/utils/proxyInner.ts index 5b4659c3d..0840f397b 100644 --- a/src/utils/proxyInner.ts +++ b/src/utils/proxyInner.ts @@ -4,13 +4,6 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -import { AnyObject } from "./types"; - -export type ProxyInner = T & { - [SYM_PROXY_INNER_GET]?: () => T; - [SYM_PROXY_INNER_VALUE]?: T | undefined; -}; - export const SYM_PROXY_INNER_GET = Symbol.for("vencord.proxyInner.get"); export const SYM_PROXY_INNER_VALUE = Symbol.for("vencord.proxyInner.innerValue"); @@ -55,10 +48,10 @@ const handler: ProxyHandler = { * @param primitiveErr The error message to throw when the inner value is a primitive * @returns A proxy which will act like the inner value when accessed */ -export function proxyInner( +export function proxyInner( errMsg = "Proxy inner value is undefined, setInnerValue was never called.", primitiveErrMsg = "proxyInner called on a primitive value." -): [proxy: ProxyInner, setInnerValue: (innerValue: T) => void] { +): [proxy: T, setInnerValue: (innerValue: T) => void] { const proxyDummy = Object.assign(function () { }, { [SYM_PROXY_INNER_GET]: function () { if (proxyDummy[SYM_PROXY_INNER_VALUE] == null) { diff --git a/src/utils/types.ts b/src/utils/types.ts index 6360f93ac..8c24843f8 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -356,7 +356,3 @@ export type PluginNative Return extends Promise ? Return : Promise : never; }; - -export type AnyObject = Record & ((...args: any[]) => any) & { - new(...args: any[]): any; -}; diff --git a/src/webpack/api.tsx b/src/webpack/api.tsx index a30971541..11de0c1ea 100644 --- a/src/webpack/api.tsx +++ b/src/webpack/api.tsx @@ -8,8 +8,7 @@ import { lazyString, makeLazy, proxyLazy } from "@utils/lazy"; import { LazyComponent, LazyComponentType, SYM_LAZY_COMPONENT_INNER } from "@utils/lazyReact"; import { Logger } from "@utils/Logger"; import { canonicalizeMatch } from "@utils/patches"; -import { ProxyInner, proxyInner, SYM_PROXY_INNER_VALUE } from "@utils/proxyInner"; -import { AnyObject } from "@utils/types"; +import { proxyInner, SYM_PROXY_INNER_VALUE } from "@utils/proxyInner"; import type { WebpackInstance } from "discord-types/other"; import { traceFunction } from "../debug/Tracer"; @@ -194,7 +193,7 @@ export function waitFor(filter: FilterFn, callback: ModCallbackFn, { isIndirect * @param parse A function that takes the find result as its first argument and returns something to use as the proxy inner value. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself * @returns A proxy that has the parse function return value as its true value, or the plain parse function return value if it was called immediately. */ -export function find(filter: FilterFn, parse: (mod: any) => any = m => m, { isIndirect = false }: { isIndirect?: boolean; } = {}) { +export function find(filter: FilterFn, parse: (mod: any) => any = m => m, { isIndirect = false }: { isIndirect?: boolean; } = {}) { if (typeof filter !== "function") throw new Error("Invalid filter. Expected a function got " + typeof filter); if (typeof parse !== "function") @@ -207,7 +206,7 @@ export function find(filter: FilterFn, parse: (mod: any) => any = webpackSearchHistory.push(["find", [proxy, filter]]); } - if (proxy[SYM_PROXY_INNER_VALUE] != null) return proxy[SYM_PROXY_INNER_VALUE] as ProxyInner; + if (proxy[SYM_PROXY_INNER_VALUE] != null) return proxy[SYM_PROXY_INNER_VALUE] as T; return proxy; } @@ -328,7 +327,7 @@ export function findComponentByCode(...code: string[] | * @param props A list of props to search the module or exports for * @param parse A function that takes the find result as its first argument and returns something. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself */ -export function findByProps(...props: string[] | [...string[], (mod: any) => T]) { +export function findByProps(...props: string[] | [...string[], (mod: any) => T]) { const parse = (typeof props.at(-1) === "function" ? props.pop() : m => m) as (mod: any) => T; const newProps = props as string[]; @@ -349,7 +348,7 @@ export function findByProps(...props: string[] | [...string[], (m * @param props A list of props to search the module or exports for * @param parse A function that takes the find result as its first argument and returns something. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself */ -export function findByPropsAndExtract(...props: string[] | [...string[], (mod: any) => T]) { +export function findByPropsAndExtract(...props: string[] | [...string[], (mod: any) => T]) { const parse = (typeof props.at(-1) === "function" ? props.pop() : m => m) as (mod: any) => T; const newProps = props as string[]; @@ -368,7 +367,7 @@ export function findByPropsAndExtract(...props: string[] | [...st * @param code A list of code to search each export for * @param parse A function that takes the find result as its first argument and returns something. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself */ -export function findByCode(...code: string[] | [...string[], (mod: any) => T]) { +export function findByCode(...code: string[] | [...string[], (mod: any) => T]) { const parse = (typeof code.at(-1) === "function" ? code.pop() : m => m) as (mod: any) => T; const newCode = code as string[]; @@ -402,7 +401,7 @@ export function findStore(name: string) { * @param code A list of code to search each factory for * @param parse A function that takes the find result as its first argument and returns something. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself */ -export function findByFactoryCode(...code: string[] | [...string[], (mod: any) => T]) { +export function findByFactoryCode(...code: string[] | [...string[], (mod: any) => T]) { const parse = (typeof code.at(-1) === "function" ? code.pop() : m => m) as (mod: any) => T; const newCode = code as string[]; @@ -430,7 +429,7 @@ export function findByFactoryCode(...code: string[] | [...string[ * @returns Unmangled exports as specified in mappers */ export function mapMangledModule(code: string | string[], mappers: Record) { - const mapping = {} as Record>; + const mapping = {} as Record; const setters = {} as Record void>; for (const newName in mappers) { @@ -488,7 +487,7 @@ export function findModuleFactory(...code: string[]) { const [proxy, setInnerValue] = proxyInner(`Webpack module factory find matched no module. Filter: ${printFilter(filter)}`, "Webpack find with proxy called on a primitive value."); waitFor(filter, (_, { factory }) => setInnerValue(factory)); - if (proxy[SYM_PROXY_INNER_VALUE] != null) return proxy[SYM_PROXY_INNER_VALUE] as ProxyInner; + if (proxy[SYM_PROXY_INNER_VALUE] != null) return proxy[SYM_PROXY_INNER_VALUE] as ModuleFactory; return proxy; } @@ -503,7 +502,7 @@ export function findModuleFactory(...code: string[]) { * @param attempts How many times to try to evaluate the factory before giving up * @returns Result of factory function */ -export function webpackDependantLazy(factory: () => T, attempts?: number) { +export function webpackDependantLazy(factory: () => T, attempts?: number) { if (IS_REPORTER) webpackSearchHistory.push(["webpackDependantLazy", [factory]]); return proxyLazy(factory, attempts);