[Metro] Fixups and tidying
This commit is contained in:
parent
97176f9d3f
commit
eb90b0a21d
3 changed files with 10 additions and 8 deletions
2
src/def.d.ts
vendored
2
src/def.d.ts
vendored
|
@ -280,7 +280,7 @@ interface VendettaObject {
|
||||||
findByPropsAll: PropsFinderAll;
|
findByPropsAll: PropsFinderAll;
|
||||||
findByDisplayName: (name: string, defaultExp?: boolean) => any;
|
findByDisplayName: (name: string, defaultExp?: boolean) => any;
|
||||||
findByDisplayNameAll: (name: string, defaultExp?: boolean) => any[];
|
findByDisplayNameAll: (name: string, defaultExp?: boolean) => any[];
|
||||||
findByStoreName: (storeName: string) => any;
|
findByStoreName: (name: string) => any;
|
||||||
common: {
|
common: {
|
||||||
constants: PropIntellisense<"API_HOST">;
|
constants: PropIntellisense<"API_HOST">;
|
||||||
channels: PropIntellisense<"getVoiceChannelId">;
|
channels: PropIntellisense<"getVoiceChannelId">;
|
||||||
|
|
|
@ -17,7 +17,7 @@ function blacklist(id: number) {
|
||||||
// Blacklist any "bad-actor" modules, e.g. the dreaded null proxy, the window itself, or undefined modules
|
// Blacklist any "bad-actor" modules, e.g. the dreaded null proxy, the window itself, or undefined modules
|
||||||
for (const key in window.modules) {
|
for (const key in window.modules) {
|
||||||
const id = Number(key);
|
const id = Number(key);
|
||||||
const module = window.modules[id].publicModule.exports;
|
const module = window.modules[id]?.publicModule?.exports;
|
||||||
|
|
||||||
if (!module || module === window || module["proxygone"] === null) {
|
if (!module || module === window || module["proxygone"] === null) {
|
||||||
blacklist(id);
|
blacklist(id);
|
||||||
|
@ -34,7 +34,7 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
|
||||||
|
|
||||||
for (const key in modules) {
|
for (const key in modules) {
|
||||||
const id = Number(key);
|
const id = Number(key);
|
||||||
const module = modules[id].publicModule.exports;
|
const module = modules[id]?.publicModule?.exports;
|
||||||
|
|
||||||
if (!modules[id].isInitialized) try {
|
if (!modules[id].isInitialized) try {
|
||||||
__r(id);
|
__r(id);
|
||||||
|
@ -58,7 +58,7 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
|
||||||
else found.push(module);
|
else found.push(module);
|
||||||
}
|
}
|
||||||
} catch (e: Error | any) {
|
} catch (e: Error | any) {
|
||||||
console.error(`Failed to getModule... ${e.stack || e.toString()}`);
|
console.error(`Failed to filter modules... ${e.stack || e.toString()}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,10 +70,12 @@ export const find = filterModules(modules, true);
|
||||||
export const findAll = filterModules(modules);
|
export const findAll = filterModules(modules);
|
||||||
|
|
||||||
const propsFilter = (props: (string | symbol)[]) => (m: any) => props.every((p) => m[p] !== undefined);
|
const propsFilter = (props: (string | symbol)[]) => (m: any) => props.every((p) => m[p] !== undefined);
|
||||||
const dNameFilter = (name: string, defaultExp: boolean) => (defaultExp ? (m: any) => m.name === name : (m: any) => m?.default?.name === name);
|
// TODO: This uses .name, not .displayName. We should fix this SOON. Changing it directly WILL break plugins, though.
|
||||||
|
const dNameFilter = (name: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.name === name : (m: any) => m?.default?.name === name);
|
||||||
|
const storeFilter = (name: string) => (m: any) => m.getName && m.getName.length === 0 && m.getName() === name;
|
||||||
|
|
||||||
export const findByProps: PropsFinder = (...props) => find(propsFilter(props));
|
export const findByProps: PropsFinder = (...props) => find(propsFilter(props));
|
||||||
export const findByPropsAll: PropsFinderAll = (...props) => findAll(propsFilter(props));
|
export const findByPropsAll: PropsFinderAll = (...props) => findAll(propsFilter(props));
|
||||||
export const findByDisplayName = (name: string, defaultExp = true) => find(dNameFilter(name, defaultExp));
|
export const findByDisplayName = (name: string, defaultExp = true) => find(dNameFilter(name, defaultExp));
|
||||||
export const findByDisplayNameAll = (name: string, defaultExp = true) => findAll(dNameFilter(name, defaultExp));
|
export const findByDisplayNameAll = (name: string, defaultExp = true) => findAll(dNameFilter(name, defaultExp));
|
||||||
export const findByStoreName = (storeName: string) => find((m: any) => m.getName?.() === storeName);
|
export const findByStoreName = (name: string) => find(storeFilter(name));
|
|
@ -2,7 +2,7 @@
|
||||||
// This used to be in filters.ts, but things became convoluted
|
// This used to be in filters.ts, but things became convoluted
|
||||||
|
|
||||||
// Early find logic
|
// Early find logic
|
||||||
const basicFind = (prop: string) => Object.values(window.modules).find(m => m.publicModule.exports?.[prop]).publicModule.exports;
|
const basicFind = (prop: string) => Object.values(window.modules).find(m => m?.publicModule.exports?.[prop])?.publicModule?.exports;
|
||||||
|
|
||||||
// Hoist React on window
|
// Hoist React on window
|
||||||
window.React = basicFind("createElement") as typeof import("react");;
|
window.React = basicFind("createElement") as typeof import("react");;
|
||||||
|
@ -11,7 +11,7 @@ window.React = basicFind("createElement") as typeof import("react");;
|
||||||
export const ReactNative = basicFind("Text") as typeof import("react-native");
|
export const ReactNative = basicFind("Text") as typeof import("react-native");
|
||||||
|
|
||||||
// Export Discord's constants
|
// Export Discord's constants
|
||||||
export const constants = basicFind("ThemeColorMap");
|
export const constants = basicFind("AbortCodes");
|
||||||
|
|
||||||
// Export moment
|
// Export moment
|
||||||
export const moment = basicFind("isMoment");
|
export const moment = basicFind("isMoment");
|
||||||
|
|
Loading…
Reference in a new issue