aboutsummaryrefslogtreecommitdiff
path: root/src/webpack/index.ts
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-08-31 20:47:07 +0200
committerVendicated <vendicated@riseup.net>2022-08-31 20:47:07 +0200
commita7ccbcfca4f181790b86199a7f31d1ae19e0253f (patch)
tree56be6cef5437dff886dcefa04f930780d552c68c /src/webpack/index.ts
parent98cb301df53305f397ac6e1b4e603c930820f228 (diff)
downloadVencord-a7ccbcfca4f181790b86199a7f31d1ae19e0253f.tar.gz
Vencord-a7ccbcfca4f181790b86199a7f31d1ae19e0253f.tar.bz2
Vencord-a7ccbcfca4f181790b86199a7f31d1ae19e0253f.zip
Refactor webpack; Add ErrorBoundary
Diffstat (limited to 'src/webpack/index.ts')
-rw-r--r--src/webpack/index.ts106
1 files changed, 2 insertions, 104 deletions
diff --git a/src/webpack/index.ts b/src/webpack/index.ts
index 2c5a455..a388dbd 100644
--- a/src/webpack/index.ts
+++ b/src/webpack/index.ts
@@ -1,104 +1,2 @@
-import { startAll } from "../plugins";
-
-let webpackCache: typeof window.webpackChunkdiscord_app;
-
-export const subscriptions = new Map<FilterFn, CallbackFn>();
-export const listeners = new Set<CallbackFn>();
-
-type FilterFn = (mod: any) => boolean;
-type CallbackFn = (mod: any) => void;
-
-export let React: typeof import("react");
-export let FluxDispatcher: any;
-export let Forms: any;
-export let UserStore: any;
-
-export function _initWebpack(instance: typeof window.webpackChunkdiscord_app) {
- if (webpackCache !== void 0) throw "no.";
-
- webpackCache = instance.push([[Symbol()], {}, (r) => r.c]);
- instance.pop();
-
- // Abandon Hope All Ye Who Enter Here
-
- let started = false;
- waitFor("getCurrentUser", x => UserStore = x);
- waitFor(["dispatch", "subscribe"], x => {
- FluxDispatcher = x;
- const cb = () => {
- console.info("Connection open");
- x.unsubscribe("CONNECTION_OPEN", cb);
- startAll();
- };
- x.subscribe("CONNECTION_OPEN", cb);
- });
- waitFor("useState", x => (React = x));
- waitFor("FormSection", x => Forms = x);
-}
-
-export function find(filter: FilterFn, getDefault = true) {
- if (typeof filter !== "function")
- throw new Error("Invalid filter. Expected a function got", filter);
-
- for (const key in webpackCache) {
- const mod = webpackCache[key];
- if (mod?.exports && filter(mod.exports))
- return mod.exports;
- if (mod?.exports?.default && filter(mod.exports.default))
- return getDefault ? mod.exports.default : mod.exports;
- }
-
- return null;
-}
-
-export function findAll(filter: FilterFn, getDefault = true) {
- if (typeof filter !== "function") throw new Error("Invalid filter. Expected a function got", filter);
-
- const ret = [] as any[];
- for (const key in webpackCache) {
- const mod = webpackCache[key];
- if (mod?.exports && filter(mod.exports)) ret.push(mod.exports);
- if (mod?.exports?.default && filter(mod.exports.default)) ret.push(getDefault ? mod.exports.default : mod.exports);
- }
-
- return ret;
-}
-
-export const filters = {
- byProps: (props: string[]): FilterFn =>
- props.length === 1
- ? m => m[props[0]] !== void 0
- : m => props.every(p => m[p] !== void 0),
- byDisplayName: (deezNuts: string): FilterFn => m => m.default?.displayName === deezNuts
-};
-
-export function findByProps(...props: string[]) {
- return find(filters.byProps(props));
-}
-
-export function findAllByProps(...props: string[]) {
- return findAll(filters.byProps(props));
-}
-
-export function findByDisplayName(deezNuts: string) {
- return find(filters.byDisplayName(deezNuts));
-}
-
-export function waitFor(filter: string | string[] | FilterFn, callback: CallbackFn) {
- if (typeof filter === "string") filter = filters.byProps([filter]);
- else if (Array.isArray(filter)) filter = filters.byProps(filter);
- else if (typeof filter !== "function") throw new Error("filter must be a string, string[] or function, got", filter);
-
- const existing = find(filter!);
- if (existing) return void callback(existing);
-
- subscriptions.set(filter, callback);
-}
-
-export function addListener(callback: CallbackFn) {
- listeners.add(callback);
-}
-
-export function removeListener(callback: CallbackFn) {
- listeners.delete(callback);
-} \ No newline at end of file
+export * from "./webpack";
+export * as Common from "./common"; \ No newline at end of file