fix(metro): uncached not founds
This commit is contained in:
parent
945955dce8
commit
c89dc175e3
8 changed files with 29 additions and 35 deletions
|
|
@ -14,7 +14,7 @@ export const PyoncordIcon = _PyoncordIcon as string;
|
||||||
|
|
||||||
export default function initSettings() {
|
export default function initSettings() {
|
||||||
registerSection({
|
registerSection({
|
||||||
name: "Bunny" + (__DEV__ ? " (DEV)" : ""),
|
name: "Bunny",
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
key: "BUNNY",
|
key: "BUNNY",
|
||||||
|
|
|
||||||
|
|
@ -29,18 +29,10 @@ export const initVendettaObject = (): any => {
|
||||||
metro: {
|
metro: {
|
||||||
modules: window.modules,
|
modules: window.modules,
|
||||||
find: (filter: (m: any) => boolean) => {
|
find: (filter: (m: any) => boolean) => {
|
||||||
const { stack } = new Error();
|
return metro.find(metro.createSimpleFilter(filter, SparkMD5.hash(new Error().stack!)));
|
||||||
return metro.find(metro.createSimpleFilter(
|
|
||||||
filter,
|
|
||||||
SparkMD5.hash(stack!)
|
|
||||||
));
|
|
||||||
},
|
},
|
||||||
findAll: (filter: (m: any) => boolean) => {
|
findAll: (filter: (m: any) => boolean) => {
|
||||||
const { stack } = new Error();
|
return metro.findAll(metro.createSimpleFilter(filter, SparkMD5.hash(new Error().stack!)));
|
||||||
return metro.findAll(metro.createSimpleFilter(
|
|
||||||
filter,
|
|
||||||
SparkMD5.hash(stack!)
|
|
||||||
));
|
|
||||||
},
|
},
|
||||||
findByProps: (...props: any) => {
|
findByProps: (...props: any) => {
|
||||||
// Decor fix hack
|
// Decor fix hack
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { View } from "react-native";
|
||||||
|
|
||||||
const bySingularProp = createFilterDefinition<[string]>(
|
const bySingularProp = createFilterDefinition<[string]>(
|
||||||
([prop], m) => m[prop] && Object.keys(m).length === 1,
|
([prop], m) => m[prop] && Object.keys(m).length === 1,
|
||||||
prop => `pyoncord.makldlksdjks(${prop})`
|
prop => `bunny.ui.bySingularProp(${prop})`
|
||||||
);
|
);
|
||||||
|
|
||||||
const findSingular = (prop: string) => find(bySingularProp(prop))?.[prop];
|
const findSingular = (prop: string) => find(bySingularProp(prop))?.[prop];
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,12 @@ const saveCache = throttle(() => {
|
||||||
|
|
||||||
export function registerModuleFindCacheId(uniqueId: string, moduleId: number, all: boolean) {
|
export function registerModuleFindCacheId(uniqueId: string, moduleId: number, all: boolean) {
|
||||||
(metroCache.findIndex[uniqueId] ??= { _: undefined })[moduleId] = 1;
|
(metroCache.findIndex[uniqueId] ??= { _: undefined })[moduleId] = 1;
|
||||||
if (all) metroCache.findIndex[uniqueId]!._ ||= 1;
|
if (all) metroCache.findIndex[uniqueId]!._ = 1;
|
||||||
|
saveCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerModuleFindFinished(uniqueId: string) {
|
||||||
|
metroCache.findIndex[uniqueId] ??= { _: undefined };
|
||||||
saveCache();
|
saveCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export const commands = findByProps("getBuiltInCommands");
|
||||||
export const navigation = findByProps("pushLazy");
|
export const navigation = findByProps("pushLazy");
|
||||||
export const toasts = find(createSimpleFilter(
|
export const toasts = find(createSimpleFilter(
|
||||||
m => m.open && m.close && !m.startDrag && !m.init && !m.openReplay && !m.setAlwaysOnTop && !m.setAccountFlag,
|
m => m.open && m.close && !m.startDrag && !m.init && !m.openReplay && !m.setAlwaysOnTop && !m.setAccountFlag,
|
||||||
"pyoncord.metro.common.toasts"
|
"bunny.metro.common.toasts"
|
||||||
));
|
));
|
||||||
export const messageUtil = findByProps("sendBotMessage");
|
export const messageUtil = findByProps("sendBotMessage");
|
||||||
export const navigationStack = findByProps("createStackNavigator");
|
export const navigationStack = findByProps("createStackNavigator");
|
||||||
|
|
|
||||||
|
|
@ -61,30 +61,30 @@ export function createSimpleFilter(
|
||||||
|
|
||||||
export const byProps = createFilterDefinition<string[]>(
|
export const byProps = createFilterDefinition<string[]>(
|
||||||
(props, m) => props.length === 0 ? m[props[0]] : props.every(p => m[p]),
|
(props, m) => props.length === 0 ? m[props[0]] : props.every(p => m[p]),
|
||||||
props => `pyoncord.metro.byProps(${props.join(",")})`
|
props => `bunny.metro.byProps(${props.join(",")})`
|
||||||
);
|
);
|
||||||
|
|
||||||
export const byName = createFilterDefinition<[string]>(
|
export const byName = createFilterDefinition<[string]>(
|
||||||
([name], m) => m.name === name,
|
([name], m) => m.name === name,
|
||||||
name => `pyoncord.metro.byName(${name})`
|
name => `bunny.metro.byName(${name})`
|
||||||
);
|
);
|
||||||
|
|
||||||
export const byDisplayName = createFilterDefinition<[string]>(
|
export const byDisplayName = createFilterDefinition<[string]>(
|
||||||
([displayName], m) => m.displayName === displayName,
|
([displayName], m) => m.displayName === displayName,
|
||||||
name => `pyoncord.metro.byDisplayName(${name})`
|
name => `bunny.metro.byDisplayName(${name})`
|
||||||
);
|
);
|
||||||
|
|
||||||
export const byTypeName = createFilterDefinition<[string]>(
|
export const byTypeName = createFilterDefinition<[string]>(
|
||||||
([typeName], m) => m.type?.name === typeName,
|
([typeName], m) => m.type?.name === typeName,
|
||||||
name => `pyoncord.metro.byTypeName(${name})`
|
name => `bunny.metro.byTypeName(${name})`
|
||||||
);
|
);
|
||||||
|
|
||||||
export const byStoreName = createFilterDefinition<[string]>(
|
export const byStoreName = createFilterDefinition<[string]>(
|
||||||
([name], m) => m.getName?.length === 0 && m.getName() === name,
|
([name], m) => m.getName?.length === 0 && m.getName() === name,
|
||||||
name => `pyoncord.metro.byStoreName(${name})`
|
name => `bunny.metro.byStoreName(${name})`
|
||||||
);
|
);
|
||||||
|
|
||||||
export const byMutableProp = createFilterDefinition<[string]>(
|
export const byMutableProp = createFilterDefinition<[string]>(
|
||||||
([prop], m) => m?.[prop] && !Object.getOwnPropertyDescriptor(m, prop)?.get,
|
([prop], m) => m?.[prop] && !Object.getOwnPropertyDescriptor(m, prop)?.get,
|
||||||
prop => `pyoncord.metro.byMutableProp(${prop})`
|
prop => `bunny.metro.byMutableProp(${prop})`
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { getFuncUniqCall, registerModuleFindCacheId } from "./caches";
|
import { registerModuleFindCacheId, registerModuleFindFinished } from "./caches";
|
||||||
import { FilterFn } from "./filters";
|
import { FilterFn } from "./filters";
|
||||||
import { getModules } from "./modules";
|
import { getModules } from "./modules";
|
||||||
|
|
||||||
|
|
@ -14,15 +14,15 @@ function testExports<A extends unknown[]>(moduleExports: any, filter: FilterFn<A
|
||||||
* @param filter find calls filter once for each enumerable module's exports until it finds one where filter returns a thruthy value.
|
* @param filter find calls filter once for each enumerable module's exports until it finds one where filter returns a thruthy value.
|
||||||
*/
|
*/
|
||||||
export function find<A extends unknown[]>(filter: FilterFn<A>) {
|
export function find<A extends unknown[]>(filter: FilterFn<A>) {
|
||||||
const uniq = filter.serialized || getFuncUniqCall();
|
for (const [id, moduleExports] of getModules(filter.serialized, false)) {
|
||||||
|
|
||||||
for (const [id, moduleExports] of getModules(uniq, false)) {
|
|
||||||
const testedExports = testExports(moduleExports, filter);
|
const testedExports = testExports(moduleExports, filter);
|
||||||
if (testedExports !== undefined) {
|
if (testedExports !== undefined) {
|
||||||
registerModuleFindCacheId(uniq, id, false);
|
registerModuleFindCacheId(filter.serialized, id, false);
|
||||||
return testedExports;
|
return testedExports;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerModuleFindFinished(filter.serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -31,14 +31,15 @@ export function find<A extends unknown[]>(filter: FilterFn<A>) {
|
||||||
*/
|
*/
|
||||||
export function findAll<A extends unknown[]>(filter: FilterFn<A>) {
|
export function findAll<A extends unknown[]>(filter: FilterFn<A>) {
|
||||||
const foundExports: any[] = [];
|
const foundExports: any[] = [];
|
||||||
const uniq = filter.serialized || getFuncUniqCall();
|
|
||||||
|
|
||||||
for (const [id, moduleExports] of getModules(uniq, true)) {
|
for (const [id, moduleExports] of getModules(filter.serialized, true)) {
|
||||||
const testedExports = testExports(moduleExports, filter);
|
const testedExports = testExports(moduleExports, filter);
|
||||||
if (testedExports !== undefined) {
|
if (testedExports !== undefined) {
|
||||||
foundExports.push(testedExports);
|
foundExports.push(testedExports);
|
||||||
registerModuleFindCacheId(uniq, id, true);
|
registerModuleFindCacheId(filter.serialized, id, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerModuleFindFinished(filter.serialized);
|
||||||
return foundExports;
|
return foundExports;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,15 +151,11 @@ export function requireModule(id: Metro.ModuleID) {
|
||||||
return moduleExports;
|
return moduleExports;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* getModules(uniqueId: string | null, all = false) {
|
export function* getModules(uniqueId: string, all = false) {
|
||||||
yield [-1, require("@metro/polyfills/redesign")];
|
yield [-1, require("@metro/polyfills/redesign")];
|
||||||
|
|
||||||
let cache = null;
|
let cache = getMetroCache().findIndex[uniqueId];
|
||||||
|
if (all && !cache?._) cache = undefined;
|
||||||
if (uniqueId) {
|
|
||||||
cache = getMetroCache().findIndex[uniqueId];
|
|
||||||
if (all && !cache?._) cache = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const id in cache ?? modules) {
|
for (const id in cache ?? modules) {
|
||||||
const exports = requireModule(id);
|
const exports = requireModule(id);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue