From 8bb0d8314db5cfc0542f496630d2ae27e4f3bd4e Mon Sep 17 00:00:00 2001 From: prism Date: Sun, 8 Feb 2026 15:10:39 +0100 Subject: [PATCH] some fixes (#745) * UserAreaAPI: fix shrink for buttons * ContextMenuAPI: fix * LoadLazyChunks: fix --- src/debug/loadLazyChunks.ts | 20 ++++++++++++++++---- src/equicordplugins/_api/userArea.ts | 17 ++++++++++++----- src/plugins/_api/contextMenu.ts | 12 +++++------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/debug/loadLazyChunks.ts b/src/debug/loadLazyChunks.ts index 94a9f6a3e..32ab77041 100644 --- a/src/debug/loadLazyChunks.ts +++ b/src/debug/loadLazyChunks.ts @@ -29,6 +29,18 @@ function getWebpackChunkMap() { return v; } +async function promiseAllSettledBatched(tasks: (() => Promise)[], batchSize = 8): Promise { + const results: T[] = []; + for (let i = 0; i < tasks.length; i += batchSize) { + const batch = tasks.slice(i, i + batchSize); + const settled = await Promise.allSettled(batch.map(t => t())); + for (const r of settled) { + if (r.status === "fulfilled") results.push(r.value); + } + } + return results; +} + export async function loadLazyChunks() { const LazyChunkLoaderLogger = new Logger("LazyChunkLoader"); @@ -59,7 +71,7 @@ export async function loadLazyChunks() { const shouldForceDefer = false; - await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => { + await promiseAllSettledBatched(Array.from(lazyChunks).map(([, rawChunkIds, entryPoint]) => async () => { const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Webpack.ChunkIdsRegex)).map(m => { const numChunkId = Number(m[1]); return Number.isNaN(numChunkId) ? m[1] : numChunkId; @@ -104,9 +116,9 @@ export async function loadLazyChunks() { })); // Loads all found valid chunk groups - await Promise.all( + await promiseAllSettledBatched( Array.from(validChunkGroups) - .map(([chunkIds]) => + .map(([chunkIds]) => () => Promise.all(chunkIds.map(id => wreq.e(id))) ) ); @@ -182,7 +194,7 @@ export async function loadLazyChunks() { return !(validChunks.has(id) || invalidChunks.has(id)); }); - await Promise.all(chunksLeft.map(async id => { + await promiseAllSettledBatched(chunksLeft.map(id => async () => { const isWorkerAsset = await fetch(wreq.p + wreq.u(id)) .then(r => r.text()) .then(t => /importScripts\(|self\.postMessage/.test(t)); diff --git a/src/equicordplugins/_api/userArea.ts b/src/equicordplugins/_api/userArea.ts index c273015d4..181edfd79 100644 --- a/src/equicordplugins/_api/userArea.ts +++ b/src/equicordplugins/_api/userArea.ts @@ -10,7 +10,7 @@ import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; import { findCssClassesLazy } from "@webpack"; -const { iconForeground } = findCssClassesLazy("iconForeground", "autocompleteRowContent"); +const { iconForeground } = findCssClassesLazy("iconForeground", "accountPopoutButtonWrapper"); export default definePlugin({ name: "UserAreaAPI", @@ -20,10 +20,17 @@ export default definePlugin({ patches: [ { find: "#{intl::ACCOUNT_SPEAKING_WHILE_MUTED}", - replacement: { - match: /(?<=className:(\i)\.\i,style:\i,)children:\[/, - replace: "children:[...$self.renderButtons(arguments[0],$1)," - } + replacement: [ + { + match: /(?<=className:(\i)\.\i,style:\i,)children:\[/, + replace: "children:[...$self.renderButtons(arguments[0],$1)," + }, + // fix discord weird shrink with extra buttons + { + match: /(?<=\{ref:\i,)style:(\i)(?=,onMouseEnter:\i,onMouseDown:\i,onClick)/, + replace: "style:{...$1,minWidth:0}" + } + ] } ], diff --git a/src/plugins/_api/contextMenu.ts b/src/plugins/_api/contextMenu.ts index debc55273..adcec76b0 100644 --- a/src/plugins/_api/contextMenu.ts +++ b/src/plugins/_api/contextMenu.ts @@ -40,13 +40,11 @@ export default definePlugin({ replacement: [ { match: /navId:(?=.+?([,}].*?\)))/g, - replace: (m, rest) => { - // Check if this navId: match is a destructuring statement, ignore it if it is - const destructuringMatch = rest.match(/}=.+/); - if (destructuringMatch == null) { - return `contextMenuAPIArguments:typeof arguments!=='undefined'?arguments:[],${m}`; - } - return m; + replace: (m, rest, ...args) => { + if (rest.match(/}=.+/)) return m; + const src = args[1]?.slice(Math.max(0, +args[0] - 2000), +args[0]); + if (src && Math.max(src.lastIndexOf("PureComponent{"), src.lastIndexOf("Component{")) > src.lastIndexOf("function")) return m; + return `contextMenuAPIArguments:typeof arguments!=='undefined'?arguments:[],${m}`; } } ]