Skip to content

Commit ea592e1

Browse files
authored
Merge pull request #7 from Vendicated/main
1.8.6
2 parents da826d0 + 1866e4d commit ea592e1

File tree

17 files changed

+289
-56
lines changed

17 files changed

+289
-56
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vencord",
33
"private": "true",
4-
"version": "1.8.5",
4+
"version": "1.8.6",
55
"description": "The cutest Discord client mod",
66
"homepage": "https://github.com/Vendicated/Vencord#readme",
77
"bugs": {

scripts/generateReport.ts

+44-18
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,27 @@ page.on("console", async e => {
243243
}
244244
}
245245

246-
if (isDebug) {
247-
console.error(e.text());
248-
} else if (level === "error") {
249-
const text = await Promise.all(
250-
e.args().map(async a => {
251-
try {
246+
async function getText() {
247+
try {
248+
return await Promise.all(
249+
e.args().map(async a => {
252250
return await maybeGetError(a) || await a.jsonValue();
253-
} catch (e) {
254-
return a.toString();
255-
}
256-
})
257-
).then(a => a.join(" ").trim());
251+
})
252+
).then(a => a.join(" ").trim());
253+
} catch {
254+
return e.text();
255+
}
256+
}
257+
258+
if (isDebug) {
259+
const text = await getText();
258260

261+
console.error(text);
262+
if (text.includes("A fatal error occurred:")) {
263+
process.exit(1);
264+
}
265+
} else if (level === "error") {
266+
const text = await getText();
259267

260268
if (text.length && !text.startsWith("Failed to load resource: the server responded with a status of") && !text.includes("Webpack")) {
261269
console.error("[Unexpected Error]", text);
@@ -322,22 +330,31 @@ async function runtime(token: string) {
322330

323331
const validChunks = new Set<string>();
324332
const invalidChunks = new Set<string>();
333+
const deferredRequires = new Set<string>();
325334

326335
let chunksSearchingResolve: (value: void | PromiseLike<void>) => void;
327336
const chunksSearchingDone = new Promise<void>(r => chunksSearchingResolve = r);
328337

329338
// True if resolved, false otherwise
330339
const chunksSearchPromises = [] as Array<() => boolean>;
331-
const lazyChunkRegex = canonicalizeMatch(/Promise\.all\((\[\i\.\i\(".+?"\).+?\])\).then\(\i\.bind\(\i,"(.+?)"\)\)/g);
332-
const chunkIdsRegex = canonicalizeMatch(/\("(.+?)"\)/g);
340+
341+
const LazyChunkRegex = canonicalizeMatch(/(?:Promise\.all\(\[(\i\.\i\("[^)]+?"\)[^\]]+?)\]\)|(\i\.\i\("[^)]+?"\)))\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/g);
333342

334343
async function searchAndLoadLazyChunks(factoryCode: string) {
335-
const lazyChunks = factoryCode.matchAll(lazyChunkRegex);
344+
const lazyChunks = factoryCode.matchAll(LazyChunkRegex);
336345
const validChunkGroups = new Set<[chunkIds: string[], entryPoint: string]>();
337346

338-
await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => {
339-
const chunkIds = Array.from(rawChunkIds.matchAll(chunkIdsRegex)).map(m => m[1]);
340-
if (chunkIds.length === 0) return;
347+
// Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before
348+
// the chunk containing the component
349+
const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT");
350+
351+
await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIdsArray, rawChunkIdsSingle, entryPoint]) => {
352+
const rawChunkIds = rawChunkIdsArray ?? rawChunkIdsSingle;
353+
const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Vencord.Webpack.ChunkIdsRegex)).map(m => m[1]) : [];
354+
355+
if (chunkIds.length === 0) {
356+
return;
357+
}
341358

342359
let invalidChunkGroup = false;
343360

@@ -373,6 +390,11 @@ async function runtime(token: string) {
373390
// Requires the entry points for all valid chunk groups
374391
for (const [, entryPoint] of validChunkGroups) {
375392
try {
393+
if (shouldForceDefer) {
394+
deferredRequires.add(entryPoint);
395+
continue;
396+
}
397+
376398
if (wreq.m[entryPoint]) wreq(entryPoint as any);
377399
} catch (err) {
378400
console.error(err);
@@ -435,6 +457,11 @@ async function runtime(token: string) {
435457

436458
await chunksSearchingDone;
437459

460+
// Require deferred entry points
461+
for (const deferredRequire of deferredRequires) {
462+
wreq!(deferredRequire as any);
463+
}
464+
438465
// All chunks Discord has mapped to asset files, even if they are not used anymore
439466
const allChunks = [] as string[];
440467

@@ -514,7 +541,6 @@ async function runtime(token: string) {
514541
setTimeout(() => console.log("[PUPPETEER_TEST_DONE_SIGNAL]"), 1000);
515542
} catch (e) {
516543
console.log("[PUP_DEBUG]", "A fatal error occurred:", e);
517-
process.exit(1);
518544
}
519545
}
520546

src/main/patcher.ts

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ if (!IS_VANILLA) {
7373
const original = options.webPreferences.preload;
7474
options.webPreferences.preload = join(__dirname, IS_DISCORD_DESKTOP ? "preload.js" : "vencordDesktopPreload.js");
7575
options.webPreferences.sandbox = false;
76+
// work around discord unloading when in background
77+
options.webPreferences.backgroundThrottling = false;
78+
7679
if (settings.frameless) {
7780
options.frame = false;
7881
} else if (process.platform === "win32" && settings.winNativeTitleBar) {
@@ -136,6 +139,9 @@ if (!IS_VANILLA) {
136139
}
137140
return originalAppend.apply(this, args);
138141
};
142+
143+
// Work around discord unloading when in background
144+
app.commandLine.appendSwitch("disable-renderer-backgrounding");
139145
} else {
140146
console.log("[Vencord] Running in vanilla mode. Not loading Vencord");
141147
}

src/plugins/_core/settings.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ export default definePlugin({
5656
}
5757
]
5858
},
59+
// Discord Stable
60+
// FIXME: remove once change merged to stable
61+
{
62+
find: "Messages.ACTIVITY_SETTINGS",
63+
replacement: {
64+
get match() {
65+
switch (Settings.plugins.Settings.settingsLocation) {
66+
case "top": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.USER_SETTINGS/;
67+
case "aboveNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.BILLING_SETTINGS/;
68+
case "belowNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.APP_SETTINGS/;
69+
case "belowActivity": return /(?<=\{section:(\i\.\i)\.DIVIDER},)\{section:"changelog"/;
70+
case "bottom": return /\{section:(\i\.\i)\.CUSTOM,\s*element:.+?}/;
71+
case "aboveActivity":
72+
default:
73+
return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.ACTIVITY_SETTINGS/;
74+
}
75+
},
76+
replace: "...$self.makeSettingsCategories($1),$&"
77+
}
78+
},
5979
{
6080
find: "Messages.ACTIVITY_SETTINGS",
6181
replacement: {

src/plugins/anonymiseFileNames/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ export default definePlugin({
7373
{
7474
find: "instantBatchUpload:function",
7575
replacement: {
76-
match: /uploadFiles:(.{1,2}),/,
76+
match: /uploadFiles:(\i),/,
7777
replace:
7878
"uploadFiles:(...args)=>(args[0].uploads.forEach(f=>f.filename=$self.anonymise(f)),$1(...args)),",
7979
},
8080
},
8181
{
82-
find: "message.attachments",
82+
find: 'addFilesTo:"message.attachments"',
8383
replacement: {
8484
match: /(\i.uploadFiles\((\i),)/,
8585
replace: "$2.forEach(f=>f.filename=$self.anonymise(f)),$1"
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BetterRoleContext
22

3-
Adds options to copy role color and edit role when right clicking roles in the user profile
3+
Adds options to copy role color, edit role and view role icon when right clicking roles in the user profile
44

5-
![](https://github.com/Vendicated/Vencord/assets/45497981/d1765e9e-7db2-4a3c-b110-139c59235326)
5+
![](https://github.com/Vendicated/Vencord/assets/45497981/354220a4-09f3-4c5f-a28e-4b19ca775190)
66

src/plugins/betterRoleContext/index.tsx

+44-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
* SPDX-License-Identifier: GPL-3.0-or-later
55
*/
66

7+
import { definePluginSettings } from "@api/Settings";
8+
import { ImageIcon } from "@components/Icons";
79
import { Devs } from "@utils/constants";
8-
import { getCurrentGuild } from "@utils/discord";
9-
import definePlugin from "@utils/types";
10+
import { getCurrentGuild, openImageModal } from "@utils/discord";
11+
import definePlugin, { OptionType } from "@utils/types";
1012
import { findByPropsLazy } from "@webpack";
1113
import { Clipboard, GuildStore, Menu, PermissionStore, TextAndImagesSettingsStores } from "@webpack/common";
1214

@@ -34,10 +36,34 @@ function AppearanceIcon() {
3436
);
3537
}
3638

39+
const settings = definePluginSettings({
40+
roleIconFileFormat: {
41+
type: OptionType.SELECT,
42+
description: "File format to use when viewing role icons",
43+
options: [
44+
{
45+
label: "png",
46+
value: "png",
47+
default: true
48+
},
49+
{
50+
label: "webp",
51+
value: "webp",
52+
},
53+
{
54+
label: "jpg",
55+
value: "jpg"
56+
}
57+
]
58+
}
59+
});
60+
3761
export default definePlugin({
3862
name: "BetterRoleContext",
39-
description: "Adds options to copy role color / edit role when right clicking roles in the user profile",
40-
authors: [Devs.Ven],
63+
description: "Adds options to copy role color / edit role / view role icon when right clicking roles in the user profile",
64+
authors: [Devs.Ven, Devs.goodbee],
65+
66+
settings,
4167

4268
start() {
4369
// DeveloperMode needs to be enabled for the context menu to be shown
@@ -63,6 +89,20 @@ export default definePlugin({
6389
);
6490
}
6591

92+
if (role.icon) {
93+
children.push(
94+
<Menu.MenuItem
95+
id="vc-view-role-icon"
96+
label="View Role Icon"
97+
action={() => {
98+
openImageModal(`${location.protocol}//${window.GLOBAL_ENV.CDN_HOST}/role-icons/${role.id}/${role.icon}.${settings.store.roleIconFileFormat}`);
99+
}}
100+
icon={ImageIcon}
101+
/>
102+
103+
);
104+
}
105+
66106
if (PermissionStore.getGuildPermissionProps(guild).canManageRoles) {
67107
children.push(
68108
<Menu.MenuItem
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vc-fpt-preview * {
2+
pointer-events: none;
3+
}

0 commit comments

Comments
 (0)