Merge branch 'dev' into main

This commit is contained in:
byeoon 2024-05-24 12:32:42 -04:00 committed by GitHub
commit de2598a87a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 126 additions and 62 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "vencord", "name": "vencord",
"private": "true", "private": "true",
"version": "1.8.5", "version": "1.8.6",
"description": "The cutest Discord client mod", "description": "The cutest Discord client mod",
"homepage": "https://github.com/Vendicated/Vencord#readme", "homepage": "https://github.com/Vendicated/Vencord#readme",
"bugs": { "bugs": {

View file

@ -243,19 +243,27 @@ page.on("console", async e => {
} }
} }
if (isDebug) { async function getText() {
console.error(e.text()); try {
} else if (level === "error") { return await Promise.all(
const text = await Promise.all( e.args().map(async a => {
e.args().map(async a => {
try {
return await maybeGetError(a) || await a.jsonValue(); return await maybeGetError(a) || await a.jsonValue();
} catch (e) { })
return a.toString(); ).then(a => a.join(" ").trim());
} } catch {
}) return e.text();
).then(a => a.join(" ").trim()); }
}
if (isDebug) {
const text = await getText();
console.error(text);
if (text.includes("A fatal error occurred:")) {
process.exit(1);
}
} else if (level === "error") {
const text = await getText();
if (text.length && !text.startsWith("Failed to load resource: the server responded with a status of") && !text.includes("Webpack")) { if (text.length && !text.startsWith("Failed to load resource: the server responded with a status of") && !text.includes("Webpack")) {
console.error("[Unexpected Error]", text); console.error("[Unexpected Error]", text);
@ -322,22 +330,31 @@ async function runtime(token: string) {
const validChunks = new Set<string>(); const validChunks = new Set<string>();
const invalidChunks = new Set<string>(); const invalidChunks = new Set<string>();
const deferredRequires = new Set<string>();
let chunksSearchingResolve: (value: void | PromiseLike<void>) => void; let chunksSearchingResolve: (value: void | PromiseLike<void>) => void;
const chunksSearchingDone = new Promise<void>(r => chunksSearchingResolve = r); const chunksSearchingDone = new Promise<void>(r => chunksSearchingResolve = r);
// True if resolved, false otherwise // True if resolved, false otherwise
const chunksSearchPromises = [] as Array<() => boolean>; const chunksSearchPromises = [] as Array<() => boolean>;
const lazyChunkRegex = canonicalizeMatch(/Promise\.all\((\[\i\.\i\(".+?"\).+?\])\).then\(\i\.bind\(\i,"(.+?)"\)\)/g);
const chunkIdsRegex = canonicalizeMatch(/\("(.+?)"\)/g); const LazyChunkRegex = canonicalizeMatch(/(?:Promise\.all\(\[(\i\.\i\("[^)]+?"\)[^\]]+?)\]\)|(\i\.\i\("[^)]+?"\)))\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/g);
async function searchAndLoadLazyChunks(factoryCode: string) { async function searchAndLoadLazyChunks(factoryCode: string) {
const lazyChunks = factoryCode.matchAll(lazyChunkRegex); const lazyChunks = factoryCode.matchAll(LazyChunkRegex);
const validChunkGroups = new Set<[chunkIds: string[], entryPoint: string]>(); const validChunkGroups = new Set<[chunkIds: string[], entryPoint: string]>();
await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => { // Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before
const chunkIds = Array.from(rawChunkIds.matchAll(chunkIdsRegex)).map(m => m[1]); // the chunk containing the component
if (chunkIds.length === 0) return; const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT");
await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIdsArray, rawChunkIdsSingle, entryPoint]) => {
const rawChunkIds = rawChunkIdsArray ?? rawChunkIdsSingle;
const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Vencord.Webpack.ChunkIdsRegex)).map(m => m[1]) : [];
if (chunkIds.length === 0) {
return;
}
let invalidChunkGroup = false; let invalidChunkGroup = false;
@ -373,6 +390,11 @@ async function runtime(token: string) {
// Requires the entry points for all valid chunk groups // Requires the entry points for all valid chunk groups
for (const [, entryPoint] of validChunkGroups) { for (const [, entryPoint] of validChunkGroups) {
try { try {
if (shouldForceDefer) {
deferredRequires.add(entryPoint);
continue;
}
if (wreq.m[entryPoint]) wreq(entryPoint as any); if (wreq.m[entryPoint]) wreq(entryPoint as any);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@ -435,6 +457,11 @@ async function runtime(token: string) {
await chunksSearchingDone; await chunksSearchingDone;
// Require deferred entry points
for (const deferredRequire of deferredRequires) {
wreq!(deferredRequire as any);
}
// All chunks Discord has mapped to asset files, even if they are not used anymore // All chunks Discord has mapped to asset files, even if they are not used anymore
const allChunks = [] as string[]; const allChunks = [] as string[];
@ -514,7 +541,6 @@ async function runtime(token: string) {
setTimeout(() => console.log("[PUPPETEER_TEST_DONE_SIGNAL]"), 1000); setTimeout(() => console.log("[PUPPETEER_TEST_DONE_SIGNAL]"), 1000);
} catch (e) { } catch (e) {
console.log("[PUP_DEBUG]", "A fatal error occurred:", e); console.log("[PUP_DEBUG]", "A fatal error occurred:", e);
process.exit(1);
} }
} }

View file

@ -73,6 +73,9 @@ if (!IS_VANILLA) {
const original = options.webPreferences.preload; const original = options.webPreferences.preload;
options.webPreferences.preload = join(__dirname, IS_DISCORD_DESKTOP ? "preload.js" : "vencordDesktopPreload.js"); options.webPreferences.preload = join(__dirname, IS_DISCORD_DESKTOP ? "preload.js" : "vencordDesktopPreload.js");
options.webPreferences.sandbox = false; options.webPreferences.sandbox = false;
// work around discord unloading when in background
options.webPreferences.backgroundThrottling = false;
if (settings.frameless) { if (settings.frameless) {
options.frame = false; options.frame = false;
} else if (process.platform === "win32" && settings.winNativeTitleBar) { } else if (process.platform === "win32" && settings.winNativeTitleBar) {
@ -136,6 +139,9 @@ if (!IS_VANILLA) {
} }
return originalAppend.apply(this, args); return originalAppend.apply(this, args);
}; };
// Work around discord unloading when in background
app.commandLine.appendSwitch("disable-renderer-backgrounding");
} else { } else {
console.log("[Vencord] Running in vanilla mode. Not loading Vencord"); console.log("[Vencord] Running in vanilla mode. Not loading Vencord");
} }

View file

@ -29,7 +29,7 @@ export default definePlugin({
find: '"NoticeStore"', find: '"NoticeStore"',
replacement: [ replacement: [
{ {
match: /\i=null;(?=.{0,80}getPremiumSubscription\(\))/g, match: /(?<=!1;)\i=null;(?=.{0,80}getPremiumSubscription\(\))/g,
replace: "if(Vencord.Api.Notices.currentNotice)return false;$&" replace: "if(Vencord.Api.Notices.currentNotice)return false;$&"
}, },
{ {

View file

@ -56,6 +56,26 @@ export default definePlugin({
} }
] ]
}, },
// Discord Stable
// FIXME: remove once change merged to stable
{
find: "Messages.ACTIVITY_SETTINGS",
replacement: {
get match() {
switch (Settings.plugins.Settings.settingsLocation) {
case "top": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.USER_SETTINGS/;
case "aboveNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.BILLING_SETTINGS/;
case "belowNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.APP_SETTINGS/;
case "belowActivity": return /(?<=\{section:(\i\.\i)\.DIVIDER},)\{section:"changelog"/;
case "bottom": return /\{section:(\i\.\i)\.CUSTOM,\s*element:.+?}/;
case "aboveActivity":
default:
return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.ACTIVITY_SETTINGS/;
}
},
replace: "...$self.makeSettingsCategories($1),$&"
}
},
{ {
find: "Messages.ACTIVITY_SETTINGS", find: "Messages.ACTIVITY_SETTINGS",
replacement: { replacement: {

View file

@ -31,10 +31,10 @@ export default definePlugin({
// Some modules match the find but the replacement is returned untouched // Some modules match the find but the replacement is returned untouched
noWarn: true, noWarn: true,
replacement: { replacement: {
match: /canAnimate:.+?(?=([,}].*?\)))/g, match: /canAnimate:.+?([,}].*?\))/g,
replace: (m, rest) => { replace: (m, rest) => {
const destructuringMatch = rest.match(/}=.+/); const destructuringMatch = rest.match(/}=.+/);
if (destructuringMatch == null) return "canAnimate:!0"; if (destructuringMatch == null) return `canAnimate:!0${rest}`;
return m; return m;
} }
} }

View file

@ -73,13 +73,13 @@ export default definePlugin({
{ {
find: "instantBatchUpload:function", find: "instantBatchUpload:function",
replacement: { replacement: {
match: /uploadFiles:(.{1,2}),/, match: /uploadFiles:(\i),/,
replace: replace:
"uploadFiles:(...args)=>(args[0].uploads.forEach(f=>f.filename=$self.anonymise(f)),$1(...args)),", "uploadFiles:(...args)=>(args[0].uploads.forEach(f=>f.filename=$self.anonymise(f)),$1(...args)),",
}, },
}, },
{ {
find: "message.attachments", find: 'addFilesTo:"message.attachments"',
replacement: { replacement: {
match: /(\i.uploadFiles\((\i),)/, match: /(\i.uploadFiles\((\i),)/,
replace: "$2.forEach(f=>f.filename=$self.anonymise(f)),$1" replace: "$2.forEach(f=>f.filename=$self.anonymise(f)),$1"

View file

@ -112,8 +112,8 @@ export default definePlugin({
replacement: [ replacement: [
// Create the isBetterFolders variable in the GuildsBar component // Create the isBetterFolders variable in the GuildsBar component
{ {
match: /(?<=let{disableAppDownload:\i=\i\.isPlatformEmbedded,isOverlay:.+?)(?=}=\i,)/, match: /let{disableAppDownload:\i=\i\.isPlatformEmbedded,isOverlay:.+?(?=}=\i,)/,
replace: ",isBetterFolders" replace: "$&,isBetterFolders"
}, },
// If we are rendering the Better Folders sidebar, we filter out guilds that are not in folders and unexpanded folders // If we are rendering the Better Folders sidebar, we filter out guilds that are not in folders and unexpanded folders
{ {

View file

@ -111,8 +111,8 @@ export default definePlugin({
{ // Load menu TOC eagerly { // Load menu TOC eagerly
find: "Messages.USER_SETTINGS_WITH_BUILD_OVERRIDE.format", find: "Messages.USER_SETTINGS_WITH_BUILD_OVERRIDE.format",
replacement: { replacement: {
match: /(?<=(\i)\(this,"handleOpenSettingsContextMenu",.{0,100}?openContextMenuLazy.{0,100}?(await Promise\.all[^};]*?\)\)).*?,)(?=\1\(this)/, match: /(\i)\(this,"handleOpenSettingsContextMenu",.{0,100}?openContextMenuLazy.{0,100}?(await Promise\.all[^};]*?\)\)).*?,(?=\1\(this)/,
replace: "(async ()=>$2)()," replace: "$&(async ()=>$2)(),"
}, },
predicate: () => settings.store.eagerLoad predicate: () => settings.store.eagerLoad
}, },

View file

@ -34,9 +34,9 @@ export default definePlugin({
{ {
find: ".AVATAR_STATUS_MOBILE_16;", find: ".AVATAR_STATUS_MOBILE_16;",
replacement: { replacement: {
match: /(?<=fromIsMobile:\i=!0,.+?)status:(\i)/, match: /(fromIsMobile:\i=!0,.+?)status:(\i)/,
// Rename field to force it to always use "online" // Rename field to force it to always use "online"
replace: 'status_$:$1="online"' replace: '$1status_$:$2="online"'
} }
} }
] ]

View file

@ -344,8 +344,8 @@ export default definePlugin({
{ {
// Patch the stickers array to add fake nitro stickers // Patch the stickers array to add fake nitro stickers
predicate: () => settings.store.transformStickers, predicate: () => settings.store.transformStickers,
match: /(?<=renderStickersAccessories\((\i)\){let (\i)=\(0,\i\.\i\)\(\i\).+?;)/, match: /renderStickersAccessories\((\i)\){let (\i)=\(0,\i\.\i\)\(\i\).+?;/,
replace: (_, message, stickers) => `${stickers}=$self.patchFakeNitroStickers(${stickers},${message});` replace: (m, message, stickers) => `${m}${stickers}=$self.patchFakeNitroStickers(${stickers},${message});`
}, },
{ {
// Filter attachments to remove fake nitro stickers or emojis // Filter attachments to remove fake nitro stickers or emojis

View file

@ -228,15 +228,15 @@ export default definePlugin({
{ {
find: ".activityTitleText,variant", find: ".activityTitleText,variant",
replacement: { replacement: {
match: /(?<=\i\.activityTitleText.+?children:(\i)\.name.*?}\),)/, match: /\.activityTitleText.+?children:(\i)\.name.*?}\),/,
replace: (_, props) => `$self.renderToggleActivityButton(${props}),` replace: (m, props) => `${m}$self.renderToggleActivityButton(${props}),`
}, },
}, },
{ {
find: ".activityCardDetails,children", find: ".activityCardDetails,children",
replacement: { replacement: {
match: /(?<=\i\.activityCardDetails.+?children:(\i\.application)\.name.*?}\),)/, match: /\.activityCardDetails.+?children:(\i\.application)\.name.*?}\),/,
replace: (_, props) => `$self.renderToggleActivityButton(${props}),` replace: (m, props) => `${m}$self.renderToggleActivityButton(${props}),`
} }
} }
], ],

View file

@ -70,8 +70,8 @@ export default definePlugin({
{ {
find: ".invitesDisabledTooltip", find: ".invitesDisabledTooltip",
replacement: { replacement: {
match: /(?<=\.VIEW_AS_ROLES_MENTIONS_WARNING.{0,100})]/, match: /\.VIEW_AS_ROLES_MENTIONS_WARNING.{0,100}(?=])/,
replace: ",$self.renderTooltip(arguments[0].guild)]" replace: "$&,$self.renderTooltip(arguments[0].guild)"
}, },
predicate: () => settings.store.toolTip predicate: () => settings.store.toolTip
} }

View file

@ -376,6 +376,9 @@ export default definePlugin({
if (!messageLinkRegex.test(props.message.content)) if (!messageLinkRegex.test(props.message.content))
return null; return null;
// need to reset the regex because it's global
messageLinkRegex.lastIndex = 0;
return ( return (
<ErrorBoundary> <ErrorBoundary>
<MessageEmbedAccessory <MessageEmbedAccessory

View file

@ -295,12 +295,9 @@ export default definePlugin({
// }, // },
{ {
// Pass through editHistory & deleted & original attachments to the "edited message" transformer // Pass through editHistory & deleted & original attachments to the "edited message" transformer
match: /interactionData:(\i)\.interactionData/, match: /(?<=null!=\i\.edited_timestamp\)return )\i\(\i,\{reactions:(\i)\.reactions.{0,50}\}\)/,
replace: replace:
"interactionData:$1.interactionData," + "Object.assign($&,{ deleted:$1.deleted, editHistory:$1.editHistory, attachments:$1.attachments })"
"deleted:$1.deleted," +
"editHistory:$1.editHistory," +
"attachments:$1.attachments"
}, },
// { // {

View file

@ -111,8 +111,8 @@ export default definePlugin({
replace: "$self.getScrollOffset(arguments[0],$1,this.props.padding,this.state.preRenderedChildren,$&)" replace: "$self.getScrollOffset(arguments[0],$1,this.props.padding,this.state.preRenderedChildren,$&)"
}, },
{ {
match: /(?<=scrollToChannel\(\i\){.{1,300})this\.props\.privateChannelIds/, match: /(scrollToChannel\(\i\){.{1,300})(this\.props\.privateChannelIds)/,
replace: "[...$&,...$self.getAllUncollapsedChannels()]" replace: "$1[...$2,...$self.getAllUncollapsedChannels()]"
}, },
] ]

View file

@ -134,8 +134,8 @@ export default definePlugin({
{ {
find: '"MessageActionCreators"', find: '"MessageActionCreators"',
replacement: { replacement: {
match: /(?<=focusMessage\(\i\){.+?)(?=focus:{messageId:(\i)})/, match: /focusMessage\(\i\){.+?(?=focus:{messageId:(\i)})/,
replace: "after:$1," replace: "$&after:$1,"
} }
}, },
// Force Server Home instead of Server Guide // Force Server Home instead of Server Guide

View file

@ -89,8 +89,8 @@ export default definePlugin({
}, },
// Remove permission checking for getRenderLevel function // Remove permission checking for getRenderLevel function
{ {
match: /(?<=getRenderLevel\(\i\){.+?return)!\i\.\i\.can\(\i\.\i\.VIEW_CHANNEL,this\.record\)\|\|/, match: /(getRenderLevel\(\i\){.+?return)!\i\.\i\.can\(\i\.\i\.VIEW_CHANNEL,this\.record\)\|\|/,
replace: " " replace: (_, rest) => `${rest} `
} }
] ]
}, },
@ -159,8 +159,8 @@ export default definePlugin({
replacement: [ replacement: [
// Make the channel appear as muted if it's hidden // Make the channel appear as muted if it's hidden
{ {
match: /(?<={channel:(\i),name:\i,muted:(\i).+?;)/, match: /{channel:(\i),name:\i,muted:(\i).+?;/,
replace: (_, channel, muted) => `${muted}=$self.isHiddenChannel(${channel})?true:${muted};` replace: (m, channel, muted) => `${m}${muted}=$self.isHiddenChannel(${channel})?true:${muted};`
}, },
// Add the hidden eye icon if the channel is hidden // Add the hidden eye icon if the channel is hidden
{ {
@ -186,8 +186,8 @@ export default definePlugin({
{ {
// Hide unreads // Hide unreads
predicate: () => settings.store.hideUnreads === true, predicate: () => settings.store.hideUnreads === true,
match: /(?<={channel:(\i),name:\i,.+?unread:(\i).+?;)/, match: /{channel:(\i),name:\i,.+?unread:(\i).+?;/,
replace: (_, channel, unread) => `${unread}=$self.isHiddenChannel(${channel})?false:${unread};` replace: (m, channel, unread) => `${m}${unread}=$self.isHiddenChannel(${channel})?false:${unread};`
} }
] ]
}, },

View file

@ -60,8 +60,8 @@ export default definePlugin({
}, },
{ {
predicate: () => settings.store.keepSpotifyActivityOnIdle, predicate: () => settings.store.keepSpotifyActivityOnIdle,
match: /(?<=shouldShowActivity\(\){.{0,50})&&!\i\.\i\.isIdle\(\)/, match: /(shouldShowActivity\(\){.{0,50})&&!\i\.\i\.isIdle\(\)/,
replace: "" replace: "$1"
} }
] ]
} }

View file

@ -42,8 +42,8 @@ export default definePlugin({
{ {
find: ",BURST_REACTION_EFFECT_PLAY", find: ",BURST_REACTION_EFFECT_PLAY",
replacement: { replacement: {
match: /(?<=BURST_REACTION_EFFECT_PLAY:\i=>{.{50,100})(\i\(\i,\i\))>=\d+/, match: /(BURST_REACTION_EFFECT_PLAY:\i=>{.{50,100})(\i\(\i,\i\))>=\d+/,
replace: "!$self.shouldPlayBurstReaction($1)" replace: "$1!$self.shouldPlayBurstReaction($2)"
} }
}, },
{ {

View file

@ -206,8 +206,8 @@ export default definePlugin({
{ {
find: ".avatarPositionPanel", find: ".avatarPositionPanel",
replacement: { replacement: {
match: /(?<=avatarWrapperNonUserBot.{0,50})onClick:(\i\|\|\i)\?void 0(?<=,avatarSrc:(\i).+?)/, match: /(avatarWrapperNonUserBot.{0,50})onClick:(\i\|\|\i)\?void 0(?<=,avatarSrc:(\i).+?)/,
replace: "style:($1)?{cursor:\"pointer\"}:{},onClick:$1?()=>{$self.openImage($2)}" replace: "$1style:($2)?{cursor:\"pointer\"}:{},onClick:$2?()=>{$self.openImage($3)}"
} }
}, },
// Group DMs top small & large icon // Group DMs top small & large icon

View file

@ -99,6 +99,16 @@ Object.defineProperty(Function.prototype, "O", {
}; };
onChunksLoaded.toString = originalOnChunksLoaded.toString.bind(originalOnChunksLoaded); onChunksLoaded.toString = originalOnChunksLoaded.toString.bind(originalOnChunksLoaded);
// Returns whether a chunk has been loaded
Object.defineProperty(onChunksLoaded, "j", {
set(v) {
delete onChunksLoaded.j;
onChunksLoaded.j = v;
originalOnChunksLoaded.j = v;
},
configurable: true
});
} }
Object.defineProperty(this, "O", { Object.defineProperty(this, "O", {

View file

@ -402,7 +402,8 @@ export function findExportedComponentLazy<T extends object = any>(...props: stri
}); });
} }
const DefaultExtractAndLoadChunksRegex = /(?:Promise\.all\((\[\i\.\i\(".+?"\).+?\])\)|Promise\.resolve\(\)).then\(\i\.bind\(\i,"(.+?)"\)\)/; export const DefaultExtractAndLoadChunksRegex = /(?:Promise\.all\(\[(\i\.\i\("[^)]+?"\)[^\]]+?)\]\)|(\i\.\i\("[^)]+?"\))|Promise\.resolve\(\))\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/;
export const ChunkIdsRegex = /\("(.+?)"\)/g;
/** /**
* Extract and load chunks using their entry point * Extract and load chunks using their entry point
@ -431,7 +432,7 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def
return; return;
} }
const [, rawChunkIds, entryPointId] = match; const [, rawChunkIdsArray, rawChunkIdsSingle, entryPointId] = match;
if (Number.isNaN(Number(entryPointId))) { if (Number.isNaN(Number(entryPointId))) {
const err = new Error("extractAndLoadChunks: Matcher didn't return a capturing group with the chunk ids array, or the entry point id returned as the second group wasn't a number"); const err = new Error("extractAndLoadChunks: Matcher didn't return a capturing group with the chunk ids array, or the entry point id returned as the second group wasn't a number");
logger.warn(err, "Code:", code, "Matcher:", matcher); logger.warn(err, "Code:", code, "Matcher:", matcher);
@ -443,8 +444,9 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def
return; return;
} }
const rawChunkIds = rawChunkIdsArray ?? rawChunkIdsSingle;
if (rawChunkIds) { if (rawChunkIds) {
const chunkIds = Array.from(rawChunkIds.matchAll(/\("(.+?)"\)/g)).map((m: any) => m[1]); const chunkIds = Array.from(rawChunkIds.matchAll(ChunkIdsRegex)).map((m: any) => m[1]);
await Promise.all(chunkIds.map(id => wreq.e(id))); await Promise.all(chunkIds.map(id => wreq.e(id)));
} }