2023-04-15 19:54:23 +01:00
|
|
|
import { initThemes } from "@lib/themes";
|
2023-08-28 08:36:19 +08:00
|
|
|
import { instead } from "spitroast";
|
2023-04-15 19:54:23 +01:00
|
|
|
|
2023-01-16 22:52:23 +00:00
|
|
|
// Hoist required modules
|
|
|
|
|
// This used to be in filters.ts, but things became convoluted
|
|
|
|
|
|
2023-08-28 08:36:19 +08:00
|
|
|
const basicFind = (filter: (m: any) => any | string) => {
|
|
|
|
|
for (const key in window.modules) {
|
|
|
|
|
const exp = window.modules[key]?.publicModule.exports;
|
|
|
|
|
if (exp && filter(exp)) return exp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 () => null;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-01-16 22:52:23 +00:00
|
|
|
|
|
|
|
|
// Hoist React on window
|
2023-08-28 08:36:19 +08:00
|
|
|
window.React = basicFind(m => m.createElement) as typeof import("react");
|
2023-01-16 22:52:23 +00:00
|
|
|
|
|
|
|
|
// Export ReactNative
|
2023-08-28 08:36:19 +08:00
|
|
|
export const ReactNative = basicFind(m => m.AppRegistry) as typeof import("react-native");
|
2023-01-16 22:52:23 +00:00
|
|
|
|
2023-03-23 05:02:53 +08:00
|
|
|
// Export chroma.js
|
2023-08-28 08:36:19 +08:00
|
|
|
export const chroma = basicFind(m => m.brewer) as typeof import("chroma-js");
|
2023-03-23 05:02:53 +08:00
|
|
|
|
2023-03-17 21:58:37 +00:00
|
|
|
// Themes
|
|
|
|
|
if (window.__vendetta_loader?.features.themes) {
|
|
|
|
|
try {
|
2023-03-23 05:02:53 +08:00
|
|
|
initThemes();
|
2023-03-17 21:58:37 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error("[Vendetta] Failed to initialize themes...", e);
|
|
|
|
|
}
|
|
|
|
|
}
|