diff --git a/src/api/Settings.ts b/src/api/Settings.ts index bdc2d418d..66f77e439 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -82,7 +82,7 @@ const DefaultSettings: Settings = { autoUpdateNotification: true, useQuickCss: true, themeLinks: [], - eagerPatches: false, + eagerPatches: IS_REPORTER, enabledThemes: [], enableReactDevtools: false, frameless: false, diff --git a/src/debug/loadLazyChunks.ts b/src/debug/loadLazyChunks.ts index d8f84335c..91946c373 100644 --- a/src/debug/loadLazyChunks.ts +++ b/src/debug/loadLazyChunks.ts @@ -69,7 +69,7 @@ export async function loadLazyChunks() { await Promise.all( Array.from(validChunkGroups) .map(([chunkIds]) => - Promise.all(chunkIds.map(id => wreq.e(id as any).catch(() => { }))) + Promise.all(chunkIds.map(id => wreq.e(id))) ) ); @@ -81,7 +81,7 @@ export async function loadLazyChunks() { continue; } - if (wreq.m[entryPoint]) wreq(entryPoint as any); + if (wreq.m[entryPoint]) wreq(entryPoint); } catch (err) { console.error(err); } @@ -127,14 +127,14 @@ export async function loadLazyChunks() { // Require deferred entry points for (const deferredRequire of deferredRequires) { - wreq!(deferredRequire as any); + wreq(deferredRequire); } // All chunks Discord has mapped to asset files, even if they are not used anymore const allChunks = [] as string[]; // Matches "id" or id: - for (const currentMatch of wreq!.u.toString().matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) { + for (const currentMatch of String(wreq.u).matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) { const id = currentMatch[1] ?? currentMatch[2]; if (id == null) continue; @@ -155,8 +155,8 @@ export async function loadLazyChunks() { // Loads and requires a chunk if (!isWasm) { - await wreq.e(id as any); - if (wreq.m[id]) wreq(id as any); + await wreq.e(id); + if (wreq.m[id]) wreq(id); } })); diff --git a/src/debug/runReporter.ts b/src/debug/runReporter.ts index 8c2635d8a..9135b5e81 100644 --- a/src/debug/runReporter.ts +++ b/src/debug/runReporter.ts @@ -7,7 +7,7 @@ import { Logger } from "@utils/Logger"; import { SYM_PROXY_INNER_GET, SYM_PROXY_INNER_VALUE } from "@utils/proxyInner"; import * as Webpack from "@webpack"; -import { patches } from "plugins"; +import { addPatch, patches } from "plugins"; import { loadLazyChunks } from "./loadLazyChunks"; @@ -20,7 +20,24 @@ async function runReporter() { let loadLazyChunksResolve: (value: void | PromiseLike) => void; const loadLazyChunksDone = new Promise(r => loadLazyChunksResolve = r); - Webpack.beforeInitListeners.add(() => loadLazyChunks().then((loadLazyChunksResolve))); + // The main patch for starting the reporter chunk loading + addPatch({ + find: '"Could not find app-mount"', + replacement: { + match: /(?<="use strict";)/, + replace: "Vencord.Webpack._initReporter();" + } + }, "Vencord Reporter"); + + // @ts-ignore + Vencord.Webpack._initReporter = function () { + // initReporter is called in the patched entry point of Discord + // setImmediate to only start searching for lazy chunks after Discord initialized the app + setTimeout(async () => { + loadLazyChunks().then(loadLazyChunksResolve); + }, 0); + }; + await loadLazyChunksDone; for (const patch of patches) {