fix the hacky requireNativeComponent double register
This commit is contained in:
parent
2fae29620a
commit
e1e5560eb8
2 changed files with 21 additions and 23 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { MetroModules, PropsFinder, PropsFinderAll } from "@types";
|
||||
import { instead } from "@lib/patcher";
|
||||
|
||||
// Metro require
|
||||
declare const __r: (moduleId: number) => any;
|
||||
|
|
@ -25,6 +26,22 @@ for (const key in window.modules) {
|
|||
}
|
||||
}
|
||||
|
||||
const checked = new WeakSet();
|
||||
const onModuleCheck = (exports: any) => {
|
||||
if (typeof exports !== "object" || checked.has(exports)) return;
|
||||
checked.add(exports);
|
||||
|
||||
if (exports?.default?.name === "requireNativeComponent") {
|
||||
instead("default", exports, (args, orig) => {
|
||||
try {
|
||||
return orig(...args);
|
||||
} catch {
|
||||
return args[0];
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Function to filter through modules
|
||||
const filterModules = (modules: MetroModules, single = false) => (filter: (m: any) => boolean) => {
|
||||
const found = [];
|
||||
|
|
@ -33,19 +50,19 @@ 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 {}
|
||||
} catch { }
|
||||
|
||||
if (!module) {
|
||||
blacklist(id);
|
||||
continue;
|
||||
}
|
||||
|
||||
onModuleCheck(module);
|
||||
|
||||
if (module.default && module.__esModule && filter(module.default)) {
|
||||
if (single) return module.default;
|
||||
found.push(module.default);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
import { initThemes } from "@lib/themes";
|
||||
import { instead } from "@lib/patcher";
|
||||
|
||||
// Hoist required modules
|
||||
// This used to be in filters.ts, but things became convoluted
|
||||
|
||||
const basicFind = (filter: (m: any) => any | string) => {
|
||||
for (const key in window.modules) {
|
||||
const exp = window.modules[key]?.publicModule.exports;
|
||||
|
|
@ -11,21 +7,6 @@ const basicFind = (filter: (m: any) => any | string) => {
|
|||
}
|
||||
}
|
||||
|
||||
const requireNativeComponent = basicFind(m => m?.default?.name === "requireNativeComponent");
|
||||
|
||||
if (requireNativeComponent) {
|
||||
// > "Tried to register two views with the same name DCDVisualEffectView"
|
||||
// This serves as a workaround for the crashing You tab on Android starting from version 192.x
|
||||
// How? We simply ignore it.
|
||||
instead("default", requireNativeComponent, (args, orig) => {
|
||||
try {
|
||||
return orig(...args);
|
||||
} catch {
|
||||
return args[0];
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Hoist React on window
|
||||
window.React = basicFind(m => m.createElement) as typeof import("react");
|
||||
|
||||
|
|
@ -38,7 +19,7 @@ export const chroma = basicFind(m => m.brewer) as typeof import("chroma-js");
|
|||
// Themes
|
||||
if (window.__vendetta_loader?.features.themes) {
|
||||
try {
|
||||
initThemes();
|
||||
require("@lib/themes").initThemes();
|
||||
} catch (e) {
|
||||
console.error("[Vendetta] Failed to initialize themes...", e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue