[Metro] Fix for 191.3, courtesy of pylix

Co-authored-by: Amsyar Rasyiq <82711525+amsyarasyiq@users.noreply.github.com>
This commit is contained in:
Beef 2023-08-04 02:12:52 +01:00
parent cf09dbc1ac
commit 06dee4cefc

View file

@ -1,8 +1,12 @@
import { MetroModules, PropsFinder, PropsFinderAll } from "@types";
import { instead } from "@lib/patcher";
// Metro require
declare const __r: (moduleId: number) => any;
// Internal Metro error reporting logic
const originalHandler = window.ErrorUtils.getGlobalHandler();
// Function to blacklist a module, preventing it from being searched again
const blacklist = (id: number) => Object.defineProperty(window.modules, id, {
value: window.modules[id],
@ -30,8 +34,12 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
const id = Number(key);
const module = modules[id]?.publicModule?.exports;
// HACK: Override the function used to report fatal JavaScript errors (that crash the app) to prevent module-requiring side effects
// Credit to @pylixonly (492949202121261067) for the initial version of this fix
if (!modules[id].isInitialized) try {
window.ErrorUtils.setGlobalHandler(() => {});
__r(id);
window.ErrorUtils.setGlobalHandler(originalHandler);
} catch {}
if (!module) {
@ -71,4 +79,4 @@ export const findByDisplayName = (displayName: string, defaultExp = true) => fin
export const findByDisplayNameAll = (displayName: string, defaultExp = true) => findAll(dNameFilter(displayName, defaultExp));
export const findByTypeName = (typeName: string, defaultExp = true) => find(tNameFilter(typeName, defaultExp));
export const findByTypeNameAll = (typeName: string, defaultExp = true) => findAll(tNameFilter(typeName, defaultExp));
export const findByStoreName = (name: string) => find(storeFilter(name));
export const findByStoreName = (name: string) => find(storeFilter(name));