GoonCord/src/lib/preinit.ts

29 lines
850 B
TypeScript
Raw Normal View History

2023-01-16 22:52:23 +00:00
// Hoist required modules
2024-02-23 00:33:40 +08:00
import { isThemeSupported } from "./loader";
2023-01-16 22:52:23 +00:00
// 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;
if (exp && filter(exp)) return exp;
}
}
2023-01-16 22:52:23 +00:00
// Hoist React on window
window.React = basicFind(m => m.createElement) as typeof import("react");
2023-01-16 22:52:23 +00:00
// Export ReactNative
export const ReactNative = basicFind(m => m.AppRegistry) as typeof import("react-native");
2023-01-16 22:52:23 +00:00
// Export chroma.js
export const chroma = basicFind(m => m.brewer) as typeof import("chroma-js");
// Themes
2024-02-23 00:33:40 +08:00
if (isThemeSupported()) {
try {
require("@lib/themes").initThemes();
} catch (e) {
console.error("[Vendetta] Failed to initialize themes...", e);
}
}