Skip to content

Commit

Permalink
fix: constants's scope undefined, correct cssvariables module
Browse files Browse the repository at this point in the history
code cleanup
  • Loading branch information
FedeIlLeone committed Oct 17, 2024
1 parent 5015f75 commit 91306b4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
3 changes: 0 additions & 3 deletions src/renderer/coremods/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ type RPCMod = { commands: Commands };
let commands: Commands = {};

async function injectRpc(): Promise<void> {
//const rpcValidatorMod = await waitForProps<{
// fetchApplicationsRPC: (socket: Socket, client_id: string, origin: string) => Promise<void>;
//}>("fetchApplicationsRPC");
const rpcValidatorMod = await waitForModule<
Record<string, (socket: Socket, client_id: string, origin: string) => Promise<void>>
>(filters.bySource("Invalid Client ID"));
Expand Down
21 changes: 4 additions & 17 deletions src/renderer/modules/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { virtualMerge } from "src/renderer/util";
import { filters, getExportsForProps, waitForModule } from "../webpack";
import { filters, getExportsForProps, waitForModule, waitForProps } from "../webpack";

type StringConcat = (...rest: string[]) => string;

//const ConstantsCommon = await waitForProps<Record<string, unknown>>("Links", "RPCCommands");
const ConstantsCommon = await waitForModule<Record<string, unknown>>(
filters.bySource("dis.gd/request"),
);
//const Constants = await waitForProps<Record<string, unknown>>("Endpoints", "Routes");
const Constants = await waitForModule<Record<string, unknown>>(
filters.bySource("users/@me/relationships"),
);
Expand All @@ -18,10 +16,7 @@ export const Permissions = getExportsForProps<Record<string, bigint>>(ConstantsC
"MANAGE_GUILD",
]);
// OAuth2Scopes
export const Scopes = getExportsForProps<Record<string, string>>(ConstantsCommon, [
"BOT",
"GUILDS",
])!;
export const Scopes = await waitForProps<Record<string, string>>("BOT", "GUILDS");
// RPCCloseCodes
export const RPCErrors = getExportsForProps<Record<string, string | number>>(ConstantsCommon, [
"RATELIMITED",
Expand Down Expand Up @@ -72,16 +67,10 @@ export const UserFlags = getExportsForProps<Record<string, string | number>>(Con
])!;

// ThemeColor
//Ambiguous: should this be the just-dashed-names or --var(css-var-strings)?
// Go with the latter for now.
/*
export const CSSVariables = await waitForProps<Record<string, string>>(
"TEXT_NORMAL",
"BACKGROUND_PRIMARY",
);
*/
// We *should* be able to do props, but there's so much extra junk with the current search implementation.
export const CSSVariables = await waitForModule(filters.bySource('="var(--background-floating)"'));

interface ColorResponse {
hex: () => string;
Expand Down Expand Up @@ -127,11 +116,9 @@ interface ColorMod {
shadows: Record<string, ShadowColor>;
// eslint-disable-next-line @typescript-eslint/naming-convention
unsafe_rawColors: Record<string, UnsafeRawColor>;
layout: Record<string, string>;
}

// This could really be a search by props, for unsafe_rawColors.
export const ColorGenerator = await waitForModule<ColorMod>(
filters.bySource(/\w+\.unsafe_rawColors\[\w+\]\.resolve\(\w+\)/),
);
export const ColorGenerator = await waitForProps<ColorMod>("unsafe_rawColors", "layout");

export const Themes = ColorGenerator.themes;
30 changes: 16 additions & 14 deletions src/renderer/modules/common/fluxHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,32 @@ export interface FluxHooks {
) => T;
}

type EqualityComparer = (a: unknown[], b: unknown[]) => boolean;
type ShallowEqual = <T>(
a: T,
b: T,
excludeKeys?: string[],
callback?: (message: string) => void,
) => boolean;
type AreArraysShallowEqual = <T extends []>(a: T, b: T) => boolean;

const FluxEquatorMod = await waitForModule(filters.bySource("shallowEqual: unequal key"));
const isEqualObject = getFunctionBySource<EqualityComparer>(
FluxEquatorMod,
"shallowEqual: unequal key",
)!;
const isEqualArray = getFunctionBySource<EqualityComparer>(FluxEquatorMod, ".some")!;
const shallowEqualMod = await waitForModule(filters.bySource("shallowEqual: unequal key"));
const shallowEqual = getFunctionBySource<ShallowEqual>(shallowEqualMod, "shallowEqual")!;
const areArraysShallowEqual = getFunctionBySource<AreArraysShallowEqual>(shallowEqualMod, ".some")!;

//const fluxHooksMod = await waitForProps<FluxHooks>("useStateFromStores");
const fluxHooksMod = await waitForModule<Record<string, ValueOf<FluxHooks>>>(
const useStateFromStoresMod = await waitForModule<Record<string, ValueOf<FluxHooks>>>(
filters.bySource("useStateFromStores"),
);

const useStateFromStores: FluxHooks["useStateFromStores"] = getFunctionBySource(
fluxHooksMod,
const useStateFromStores = getFunctionBySource<FluxHooks["useStateFromStores"]>(
useStateFromStoresMod,
"useStateFromStores",
)!;

export default {
useStateFromStores,
statesWillNeverBeEqual: getFunctionBySource(fluxHooksMod, "return!1"),
statesWillNeverBeEqual: getFunctionBySource(useStateFromStoresMod, "return!1"),
useStateFromStoresArray: (stores, callback, deps) =>
useStateFromStores(stores, callback, deps, isEqualArray),
useStateFromStores(stores, callback, deps, areArraysShallowEqual),
useStateFromStoresObject: (stores, callback, deps) =>
useStateFromStores(stores, callback, deps, isEqualObject),
useStateFromStores(stores, callback, deps, shallowEqual),
} as FluxHooks;

0 comments on commit 91306b4

Please sign in to comment.