GoonCord/src/lib/preinit.ts

26 lines
826 B
TypeScript
Raw Normal View History

2023-01-16 22:52:23 +00:00
// 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;
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
if (window.__vendetta_loader?.features.themes) {
try {
require("@lib/themes").initThemes();
} catch (e) {
console.error("[Vendetta] Failed to initialize themes...", e);
}
}