From c9b29127c90c11d9e51ea2c506ea17b7f7ca4cbb Mon Sep 17 00:00:00 2001 From: D3SOX Date: Sat, 1 Jun 2024 16:53:39 +0200 Subject: [PATCH 01/20] feat(audioPlaybackSpeed): add new plugin --- src/plugins/audioPlaybackSpeed/README.md | 5 + .../components/SpeedIcon.tsx | 21 +++++ src/plugins/audioPlaybackSpeed/index.tsx | 91 +++++++++++++++++++ src/plugins/audioPlaybackSpeed/styles.css | 5 + 4 files changed, 122 insertions(+) create mode 100644 src/plugins/audioPlaybackSpeed/README.md create mode 100644 src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx create mode 100644 src/plugins/audioPlaybackSpeed/index.tsx create mode 100644 src/plugins/audioPlaybackSpeed/styles.css diff --git a/src/plugins/audioPlaybackSpeed/README.md b/src/plugins/audioPlaybackSpeed/README.md new file mode 100644 index 000000000..f49f9cf53 --- /dev/null +++ b/src/plugins/audioPlaybackSpeed/README.md @@ -0,0 +1,5 @@ +# AudioPlaybackSpeed + +Adds an icon to change the playback speed of voice message and audio embeds + +![New icon with menu to change the playback speed](https://github.com/Vendicated/Vencord/assets/24937357/21792b09-8d6a-45be-a6e8-916cdd67a477) diff --git a/src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx b/src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx new file mode 100644 index 000000000..a59cbb094 --- /dev/null +++ b/src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx @@ -0,0 +1,21 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +function SpeedIcon() { + return ( + + + + ); +} + +export default SpeedIcon; diff --git a/src/plugins/audioPlaybackSpeed/index.tsx b/src/plugins/audioPlaybackSpeed/index.tsx new file mode 100644 index 000000000..03739f2dc --- /dev/null +++ b/src/plugins/audioPlaybackSpeed/index.tsx @@ -0,0 +1,91 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import "./styles.css"; + +import { classNameFactory } from "@api/Styles"; +import { makeRange } from "@components/PluginSettings/components"; +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { ContextMenuApi, FluxDispatcher, Menu, React } from "@webpack/common"; +import { RefObject } from "react"; + +import SpeedIcon from "./components/SpeedIcon"; + +const cl = classNameFactory("vc-audio-playback-speed-"); + +const speeds = makeRange(0.25, 3.5, 0.25); + +export default definePlugin({ + name: "AudioPlaybackSpeed", + description: "Adds an icon to change the playback speed of voice message and audio embeds", + authors: [Devs.D3SOX], + + playbackSpeedComponent(audioRef: RefObject) { + const changeSpeed = (speed: number) => { + const audio = audioRef.current; + if (audio) { + audio.playbackRate = speed; + } + }; + + return ( + + ); + }, + + patches: [ + // voice message embeds + { + find: "ComponentActions.VOICE_MESSAGE_PLAYBACK_STARTED", + replacement: { + match: /useCallback\(\(\)=>\{let \i=(\i).current;.{2300,2800}onVolumeShow:\i,onVolumeHide:\i\}\)/, + replace: "$&,$self.playbackSpeedComponent($1)" + } + }, + // audio embeds + { + // need to pass media ref via props to make it easily accessible from inside controls + find: "renderControls(){", + replacement: { + match: /onToggleMuted:this.toggleMuted,/, + replace: "$&mediaRef:this.mediaRef," + } + }, + { + find: "AUDIO:\"AUDIO\"", + replacement: { + match: /onVolumeHide:\i,iconClassName:\i.controlIcon,sliderWrapperClassName:\i.volumeSliderWrapper\}\)\}\),/, + replace: "$&$self.playbackSpeedComponent(this.props.mediaRef)," + } + } + ] +}); diff --git a/src/plugins/audioPlaybackSpeed/styles.css b/src/plugins/audioPlaybackSpeed/styles.css new file mode 100644 index 000000000..98fff293e --- /dev/null +++ b/src/plugins/audioPlaybackSpeed/styles.css @@ -0,0 +1,5 @@ +.vc-audio-playback-speed-icon { + background-color: transparent; + height: 100%; + z-index: 2; +} From 28767d97f47bb260019b7458a0a0f7e23ea28922 Mon Sep 17 00:00:00 2001 From: D3SOX Date: Sat, 1 Jun 2024 16:56:26 +0200 Subject: [PATCH 02/20] chore(audioPlaybackSpeed): remove obsolete style --- src/plugins/audioPlaybackSpeed/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/audioPlaybackSpeed/index.tsx b/src/plugins/audioPlaybackSpeed/index.tsx index 03739f2dc..c0f4e2956 100644 --- a/src/plugins/audioPlaybackSpeed/index.tsx +++ b/src/plugins/audioPlaybackSpeed/index.tsx @@ -39,7 +39,6 @@ export default definePlugin({ navId="playback-speed" onClose={() => FluxDispatcher.dispatch({ type: "CONTEXT_MENU_CLOSE" })} aria-label="Playback speed control" - style={{ zIndex: 2 }} > Date: Sat, 1 Jun 2024 17:14:38 +0200 Subject: [PATCH 03/20] fix(audioPlaybackSpeed): make compatible with VoiceDownload --- src/plugins/audioPlaybackSpeed/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/audioPlaybackSpeed/index.tsx b/src/plugins/audioPlaybackSpeed/index.tsx index c0f4e2956..bd6bd7cde 100644 --- a/src/plugins/audioPlaybackSpeed/index.tsx +++ b/src/plugins/audioPlaybackSpeed/index.tsx @@ -66,7 +66,7 @@ export default definePlugin({ { find: "ComponentActions.VOICE_MESSAGE_PLAYBACK_STARTED", replacement: { - match: /useCallback\(\(\)=>\{let \i=(\i).current;.{2300,2800}onVolumeShow:\i,onVolumeHide:\i\}\)/, + match: /useCallback\(\(\)=>\{let \i=(\i).current;.{2300,3000}onVolumeShow:\i,onVolumeHide:\i\}\)/, replace: "$&,$self.playbackSpeedComponent($1)" } }, From 8846d7024702e7715163ad0f10c3c8307fddf5e5 Mon Sep 17 00:00:00 2001 From: D3SOX Date: Sat, 1 Jun 2024 18:18:16 +0200 Subject: [PATCH 04/20] fix(audioPlaybackSpeed): copy hover color behavior --- src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx | 2 +- src/plugins/audioPlaybackSpeed/styles.css | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx b/src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx index a59cbb094..c6d4a907d 100644 --- a/src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx +++ b/src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx @@ -10,7 +10,7 @@ function SpeedIcon() { xmlns="http://www.w3.org/2000/svg" width="24" height="24" - fill="#e8eaed" + fill="currentColor" viewBox="0 -960 960 960" > diff --git a/src/plugins/audioPlaybackSpeed/styles.css b/src/plugins/audioPlaybackSpeed/styles.css index 98fff293e..8ad784aea 100644 --- a/src/plugins/audioPlaybackSpeed/styles.css +++ b/src/plugins/audioPlaybackSpeed/styles.css @@ -2,4 +2,9 @@ background-color: transparent; height: 100%; z-index: 2; + color: var(--interactive-normal); +} + +.vc-audio-playback-speed-icon:hover{ + color: var(--interactive-active); } From 64d519b54d735ee017469742f5234ebaeedcf5cc Mon Sep 17 00:00:00 2001 From: Nico Date: Sat, 1 Jun 2024 18:19:56 +0200 Subject: [PATCH 05/20] chore(audioPlaybackSpeed): fix formatting --- src/plugins/audioPlaybackSpeed/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/audioPlaybackSpeed/styles.css b/src/plugins/audioPlaybackSpeed/styles.css index 8ad784aea..3251010d2 100644 --- a/src/plugins/audioPlaybackSpeed/styles.css +++ b/src/plugins/audioPlaybackSpeed/styles.css @@ -5,6 +5,6 @@ color: var(--interactive-normal); } -.vc-audio-playback-speed-icon:hover{ +.vc-audio-playback-speed-icon:hover { color: var(--interactive-active); } From 78fd37a4c682ccc54085e5eb91f51b03a6b952ef Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 1 Jun 2024 19:13:27 +0200 Subject: [PATCH 06/20] fix(css): brand-experiment is now brand-500 --- src/api/Notifications/NotificationComponent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/Notifications/NotificationComponent.tsx b/src/api/Notifications/NotificationComponent.tsx index caa4b64ef..d07143c45 100644 --- a/src/api/Notifications/NotificationComponent.tsx +++ b/src/api/Notifications/NotificationComponent.tsx @@ -113,7 +113,7 @@ export default ErrorBoundary.wrap(function NotificationComponent({ {timeout !== 0 && !permanent && (
)} From d8524b087c850443cee954d8582f18de98a6806e Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:39:01 -0300 Subject: [PATCH 07/20] Add shortcut for lazy loading chunks --- scripts/generateReport.ts | 13 +- src/api/Settings.ts | 2 +- src/debug/loadLazyChunks.ts | 167 ++++++++++++++++++++++++++ src/debug/runReporter.ts | 163 ++----------------------- src/plugins/consoleShortcuts/index.ts | 2 + src/plugins/index.ts | 1 - src/plugins/partyMode/index.ts | 3 +- src/utils/Logger.ts | 2 +- 8 files changed, 191 insertions(+), 162 deletions(-) create mode 100644 src/debug/loadLazyChunks.ts diff --git a/scripts/generateReport.ts b/scripts/generateReport.ts index 0fde48637..cf4210779 100644 --- a/scripts/generateReport.ts +++ b/scripts/generateReport.ts @@ -241,17 +241,26 @@ page.on("console", async e => { error: await maybeGetError(e.args()[3]) ?? "Unknown error" }); + break; + case "LazyChunkLoader:": + console.error(await getText()); + + switch (message) { + case "A fatal error occurred:": + process.exit(1); + } + break; case "Reporter:": console.error(await getText()); switch (message) { + case "A fatal error occurred:": + process.exit(1); case "Webpack Find Fail:": process.exitCode = 1; report.badWebpackFinds.push(otherMessage); break; - case "A fatal error occurred:": - process.exit(1); case "Finished test": await browser.close(); await printReport(); diff --git a/src/api/Settings.ts b/src/api/Settings.ts index b94e6a3fd..70ba0bd4a 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -129,7 +129,7 @@ export const SettingsStore = new SettingsStoreClass(settings, { if (path === "plugins" && key in plugins) return target[key] = { - enabled: plugins[key].required ?? plugins[key].enabledByDefault ?? false + enabled: IS_REPORTER ?? plugins[key].required ?? plugins[key].enabledByDefault ?? false }; // Since the property is not set, check if this is a plugin's setting and if so, try to resolve diff --git a/src/debug/loadLazyChunks.ts b/src/debug/loadLazyChunks.ts new file mode 100644 index 000000000..d8f84335c --- /dev/null +++ b/src/debug/loadLazyChunks.ts @@ -0,0 +1,167 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Logger } from "@utils/Logger"; +import { canonicalizeMatch } from "@utils/patches"; +import * as Webpack from "@webpack"; +import { wreq } from "@webpack"; + +const LazyChunkLoaderLogger = new Logger("LazyChunkLoader"); + +export async function loadLazyChunks() { + try { + LazyChunkLoaderLogger.log("Loading all chunks..."); + + const validChunks = new Set(); + const invalidChunks = new Set(); + const deferredRequires = new Set(); + + let chunksSearchingResolve: (value: void | PromiseLike) => void; + const chunksSearchingDone = new Promise(r => chunksSearchingResolve = r); + + // True if resolved, false otherwise + const chunksSearchPromises = [] as Array<() => boolean>; + + const LazyChunkRegex = canonicalizeMatch(/(?:(?:Promise\.all\(\[)?(\i\.e\("[^)]+?"\)[^\]]*?)(?:\]\))?)\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/g); + + async function searchAndLoadLazyChunks(factoryCode: string) { + const lazyChunks = factoryCode.matchAll(LazyChunkRegex); + const validChunkGroups = new Set<[chunkIds: string[], entryPoint: string]>(); + + // Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before + // the chunk containing the component + const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT"); + + await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => { + const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Webpack.ChunkIdsRegex)).map(m => m[1]) : []; + + if (chunkIds.length === 0) { + return; + } + + let invalidChunkGroup = false; + + for (const id of chunkIds) { + if (wreq.u(id) == null || wreq.u(id) === "undefined.js") continue; + + const isWasm = await fetch(wreq.p + wreq.u(id)) + .then(r => r.text()) + .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); + + if (isWasm && IS_WEB) { + invalidChunks.add(id); + invalidChunkGroup = true; + continue; + } + + validChunks.add(id); + } + + if (!invalidChunkGroup) { + validChunkGroups.add([chunkIds, entryPoint]); + } + })); + + // Loads all found valid chunk groups + await Promise.all( + Array.from(validChunkGroups) + .map(([chunkIds]) => + Promise.all(chunkIds.map(id => wreq.e(id as any).catch(() => { }))) + ) + ); + + // Requires the entry points for all valid chunk groups + for (const [, entryPoint] of validChunkGroups) { + try { + if (shouldForceDefer) { + deferredRequires.add(entryPoint); + continue; + } + + if (wreq.m[entryPoint]) wreq(entryPoint as any); + } catch (err) { + console.error(err); + } + } + + // setImmediate to only check if all chunks were loaded after this function resolves + // We check if all chunks were loaded every time a factory is loaded + // If we are still looking for chunks in the other factories, the array will have that factory's chunk search promise not resolved + // But, if all chunk search promises are resolved, this means we found every lazy chunk loaded by Discord code and manually loaded them + setTimeout(() => { + let allResolved = true; + + for (let i = 0; i < chunksSearchPromises.length; i++) { + const isResolved = chunksSearchPromises[i](); + + if (isResolved) { + // Remove finished promises to avoid having to iterate through a huge array everytime + chunksSearchPromises.splice(i--, 1); + } else { + allResolved = false; + } + } + + if (allResolved) chunksSearchingResolve(); + }, 0); + } + + Webpack.factoryListeners.add(factory => { + let isResolved = false; + searchAndLoadLazyChunks(factory.toString()).then(() => isResolved = true); + + chunksSearchPromises.push(() => isResolved); + }); + + for (const factoryId in wreq.m) { + let isResolved = false; + searchAndLoadLazyChunks(wreq.m[factoryId].toString()).then(() => isResolved = true); + + chunksSearchPromises.push(() => isResolved); + } + + 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 + const allChunks = [] as string[]; + + // Matches "id" or id: + for (const currentMatch of wreq!.u.toString().matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) { + const id = currentMatch[1] ?? currentMatch[2]; + if (id == null) continue; + + allChunks.push(id); + } + + if (allChunks.length === 0) throw new Error("Failed to get all chunks"); + + // Chunks that are not loaded (not used) by Discord code anymore + const chunksLeft = allChunks.filter(id => { + return !(validChunks.has(id) || invalidChunks.has(id)); + }); + + await Promise.all(chunksLeft.map(async id => { + const isWasm = await fetch(wreq.p + wreq.u(id)) + .then(r => r.text()) + .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); + + // Loads and requires a chunk + if (!isWasm) { + await wreq.e(id as any); + if (wreq.m[id]) wreq(id as any); + } + })); + + LazyChunkLoaderLogger.log("Finished loading all chunks!"); + } catch (e) { + LazyChunkLoaderLogger.log("A fatal error occurred:", e); + } +} diff --git a/src/debug/runReporter.ts b/src/debug/runReporter.ts index 61c9f162b..6c7a2a03f 100644 --- a/src/debug/runReporter.ts +++ b/src/debug/runReporter.ts @@ -5,171 +5,22 @@ */ import { Logger } from "@utils/Logger"; -import { canonicalizeMatch } from "@utils/patches"; import * as Webpack from "@webpack"; -import { wreq } from "@webpack"; import { patches } from "plugins"; +import { loadLazyChunks } from "./loadLazyChunks"; + const ReporterLogger = new Logger("Reporter"); async function runReporter() { - ReporterLogger.log("Starting test..."); - try { - const validChunks = new Set(); - const invalidChunks = new Set(); - const deferredRequires = new Set(); + ReporterLogger.log("Starting test..."); - let chunksSearchingResolve: (value: void | PromiseLike) => void; - const chunksSearchingDone = new Promise(r => chunksSearchingResolve = r); + let loadLazyChunksResolve: (value: void | PromiseLike) => void; + const loadLazyChunksDone = new Promise(r => loadLazyChunksResolve = r); - // True if resolved, false otherwise - const chunksSearchPromises = [] as Array<() => boolean>; - - const LazyChunkRegex = canonicalizeMatch(/(?:(?:Promise\.all\(\[)?(\i\.e\("[^)]+?"\)[^\]]*?)(?:\]\))?)\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/g); - - async function searchAndLoadLazyChunks(factoryCode: string) { - const lazyChunks = factoryCode.matchAll(LazyChunkRegex); - const validChunkGroups = new Set<[chunkIds: string[], entryPoint: string]>(); - - // Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before - // the chunk containing the component - const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT"); - - await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => { - const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Webpack.ChunkIdsRegex)).map(m => m[1]) : []; - - if (chunkIds.length === 0) { - return; - } - - let invalidChunkGroup = false; - - for (const id of chunkIds) { - if (wreq.u(id) == null || wreq.u(id) === "undefined.js") continue; - - const isWasm = await fetch(wreq.p + wreq.u(id)) - .then(r => r.text()) - .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); - - if (isWasm && IS_WEB) { - invalidChunks.add(id); - invalidChunkGroup = true; - continue; - } - - validChunks.add(id); - } - - if (!invalidChunkGroup) { - validChunkGroups.add([chunkIds, entryPoint]); - } - })); - - // Loads all found valid chunk groups - await Promise.all( - Array.from(validChunkGroups) - .map(([chunkIds]) => - Promise.all(chunkIds.map(id => wreq.e(id as any).catch(() => { }))) - ) - ); - - // Requires the entry points for all valid chunk groups - for (const [, entryPoint] of validChunkGroups) { - try { - if (shouldForceDefer) { - deferredRequires.add(entryPoint); - continue; - } - - if (wreq.m[entryPoint]) wreq(entryPoint as any); - } catch (err) { - console.error(err); - } - } - - // setImmediate to only check if all chunks were loaded after this function resolves - // We check if all chunks were loaded every time a factory is loaded - // If we are still looking for chunks in the other factories, the array will have that factory's chunk search promise not resolved - // But, if all chunk search promises are resolved, this means we found every lazy chunk loaded by Discord code and manually loaded them - setTimeout(() => { - let allResolved = true; - - for (let i = 0; i < chunksSearchPromises.length; i++) { - const isResolved = chunksSearchPromises[i](); - - if (isResolved) { - // Remove finished promises to avoid having to iterate through a huge array everytime - chunksSearchPromises.splice(i--, 1); - } else { - allResolved = false; - } - } - - if (allResolved) chunksSearchingResolve(); - }, 0); - } - - Webpack.beforeInitListeners.add(async () => { - ReporterLogger.log("Loading all chunks..."); - - Webpack.factoryListeners.add(factory => { - let isResolved = false; - searchAndLoadLazyChunks(factory.toString()).then(() => isResolved = true); - - chunksSearchPromises.push(() => isResolved); - }); - - // setImmediate to only search the initial factories after Discord initialized the app - // our beforeInitListeners are called before Discord initializes the app - setTimeout(() => { - for (const factoryId in wreq.m) { - let isResolved = false; - searchAndLoadLazyChunks(wreq.m[factoryId].toString()).then(() => isResolved = true); - - chunksSearchPromises.push(() => isResolved); - } - }, 0); - }); - - 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 - const allChunks = [] as string[]; - - // Matches "id" or id: - for (const currentMatch of wreq!.u.toString().matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) { - const id = currentMatch[1] ?? currentMatch[2]; - if (id == null) continue; - - allChunks.push(id); - } - - if (allChunks.length === 0) throw new Error("Failed to get all chunks"); - - // Chunks that are not loaded (not used) by Discord code anymore - const chunksLeft = allChunks.filter(id => { - return !(validChunks.has(id) || invalidChunks.has(id)); - }); - - await Promise.all(chunksLeft.map(async id => { - const isWasm = await fetch(wreq.p + wreq.u(id)) - .then(r => r.text()) - .then(t => (IS_WEB && t.includes(".module.wasm")) || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push")); - - // Loads and requires a chunk - if (!isWasm) { - await wreq.e(id as any); - if (wreq.m[id]) wreq(id as any); - } - })); - - ReporterLogger.log("Finished loading all chunks!"); + Webpack.beforeInitListeners.add(() => loadLazyChunks().then((loadLazyChunksResolve))); + await loadLazyChunksDone; for (const patch of patches) { if (!patch.all) { diff --git a/src/plugins/consoleShortcuts/index.ts b/src/plugins/consoleShortcuts/index.ts index ee86b5fcf..0a1323e75 100644 --- a/src/plugins/consoleShortcuts/index.ts +++ b/src/plugins/consoleShortcuts/index.ts @@ -25,6 +25,7 @@ import definePlugin, { PluginNative, StartAt } from "@utils/types"; import * as Webpack from "@webpack"; import { extract, filters, findAll, findModuleId, search } from "@webpack"; import * as Common from "@webpack/common"; +import { loadLazyChunks } from "debug/loadLazyChunks"; import type { ComponentType } from "react"; const DESKTOP_ONLY = (f: string) => () => { @@ -82,6 +83,7 @@ function makeShortcuts() { wpsearch: search, wpex: extract, wpexs: (code: string) => extract(findModuleId(code)!), + loadLazyChunks: IS_DEV ? loadLazyChunks : () => { throw new Error("loadLazyChunks is dev only."); }, find, findAll: findAll, findByProps, diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 53ab7983a..32bfe7e97 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -44,7 +44,6 @@ const settings = Settings.plugins; export function isPluginEnabled(p: string) { return ( - IS_REPORTER || Plugins[p]?.required || Plugins[p]?.isDependency || settings[p]?.enabled diff --git a/src/plugins/partyMode/index.ts b/src/plugins/partyMode/index.ts index 56c19c02c..c40f2e3c7 100644 --- a/src/plugins/partyMode/index.ts +++ b/src/plugins/partyMode/index.ts @@ -18,7 +18,7 @@ import { definePluginSettings, migratePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; -import definePlugin, { OptionType } from "@utils/types"; +import definePlugin, { OptionType, ReporterTestable } from "@utils/types"; import { FluxDispatcher } from "@webpack/common"; const enum Intensity { @@ -46,6 +46,7 @@ export default definePlugin({ name: "PartyMode", description: "Allows you to use party mode cause the party never ends ✨", authors: [Devs.UwUDev], + reporterTestable: ReporterTestable.None, settings, start() { diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index 5296184d4..22a381360 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -32,7 +32,7 @@ export class Logger { constructor(public name: string, public color: string = "white") { } private _log(level: "log" | "error" | "warn" | "info" | "debug", levelColor: string, args: any[], customFmt = "") { - if (IS_REPORTER) { + if (IS_REPORTER && IS_WEB) { console[level]("[Vencord]", this.name + ":", ...args); return; } From 6e6ee4db689808c380662de17f5ae9ed0d28036e Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 1 Jun 2024 23:39:58 -0300 Subject: [PATCH 08/20] NoPendingCount: Fix for message requests --- src/plugins/noPendingCount/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugins/noPendingCount/index.ts b/src/plugins/noPendingCount/index.ts index 29458df9d..57a65f52c 100644 --- a/src/plugins/noPendingCount/index.ts +++ b/src/plugins/noPendingCount/index.ts @@ -62,6 +62,16 @@ export default definePlugin({ replace: "return 0;" } }, + // New message requests hook + { + find: "useNewMessageRequestsCount:", + predicate: () => settings.store.hideMessageRequestsCount, + replacement: { + match: /getNonChannelAckId\(\i\.\i\.MESSAGE_REQUESTS\).+?return /, + replace: "$&0;" + } + }, + // Old message requests hook { find: "getMessageRequestsCount(){", predicate: () => settings.store.hideMessageRequestsCount, From 19896ef59eb1d5c76c9eb48e99a7124d1e3620c6 Mon Sep 17 00:00:00 2001 From: D3SOX Date: Sun, 2 Jun 2024 14:42:43 +0200 Subject: [PATCH 09/20] refactor(audioPlaybackSpeed): rename to MediaPlaybackSpeed I was about to add support for videos but then I noticed it already works xD --- .../README.md | 4 ++-- .../components/SpeedIcon.tsx | 0 .../index.tsx | 16 ++++++++-------- .../styles.css | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) rename src/plugins/{audioPlaybackSpeed => mediaPlaybackSpeed}/README.md (59%) rename src/plugins/{audioPlaybackSpeed => mediaPlaybackSpeed}/components/SpeedIcon.tsx (100%) rename src/plugins/{audioPlaybackSpeed => mediaPlaybackSpeed}/index.tsx (87%) rename src/plugins/{audioPlaybackSpeed => mediaPlaybackSpeed}/styles.css (68%) diff --git a/src/plugins/audioPlaybackSpeed/README.md b/src/plugins/mediaPlaybackSpeed/README.md similarity index 59% rename from src/plugins/audioPlaybackSpeed/README.md rename to src/plugins/mediaPlaybackSpeed/README.md index f49f9cf53..066a24061 100644 --- a/src/plugins/audioPlaybackSpeed/README.md +++ b/src/plugins/mediaPlaybackSpeed/README.md @@ -1,5 +1,5 @@ -# AudioPlaybackSpeed +# MediaPlaybackSpeed -Adds an icon to change the playback speed of voice message and audio embeds +Adds an icon to change the playback speed of media embeds ![New icon with menu to change the playback speed](https://github.com/Vendicated/Vencord/assets/24937357/21792b09-8d6a-45be-a6e8-916cdd67a477) diff --git a/src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx b/src/plugins/mediaPlaybackSpeed/components/SpeedIcon.tsx similarity index 100% rename from src/plugins/audioPlaybackSpeed/components/SpeedIcon.tsx rename to src/plugins/mediaPlaybackSpeed/components/SpeedIcon.tsx diff --git a/src/plugins/audioPlaybackSpeed/index.tsx b/src/plugins/mediaPlaybackSpeed/index.tsx similarity index 87% rename from src/plugins/audioPlaybackSpeed/index.tsx rename to src/plugins/mediaPlaybackSpeed/index.tsx index bd6bd7cde..aff0dc8d5 100644 --- a/src/plugins/audioPlaybackSpeed/index.tsx +++ b/src/plugins/mediaPlaybackSpeed/index.tsx @@ -15,20 +15,20 @@ import { RefObject } from "react"; import SpeedIcon from "./components/SpeedIcon"; -const cl = classNameFactory("vc-audio-playback-speed-"); +const cl = classNameFactory("vc-media-playback-speed-"); const speeds = makeRange(0.25, 3.5, 0.25); export default definePlugin({ - name: "AudioPlaybackSpeed", - description: "Adds an icon to change the playback speed of voice message and audio embeds", + name: "MediaPlaybackSpeed", + description: "Adds an icon to change the playback speed of media embeds", authors: [Devs.D3SOX], - playbackSpeedComponent(audioRef: RefObject) { + playbackSpeedComponent(mediaRef: RefObject) { const changeSpeed = (speed: number) => { - const audio = audioRef.current; - if (audio) { - audio.playbackRate = speed; + const media = mediaRef.current; + if (media) { + media.playbackRate = speed; } }; @@ -70,7 +70,7 @@ export default definePlugin({ replace: "$&,$self.playbackSpeedComponent($1)" } }, - // audio embeds + // audio & video embeds { // need to pass media ref via props to make it easily accessible from inside controls find: "renderControls(){", diff --git a/src/plugins/audioPlaybackSpeed/styles.css b/src/plugins/mediaPlaybackSpeed/styles.css similarity index 68% rename from src/plugins/audioPlaybackSpeed/styles.css rename to src/plugins/mediaPlaybackSpeed/styles.css index 3251010d2..816190a48 100644 --- a/src/plugins/audioPlaybackSpeed/styles.css +++ b/src/plugins/mediaPlaybackSpeed/styles.css @@ -1,10 +1,10 @@ -.vc-audio-playback-speed-icon { +.vc-media-playback-speed-icon { background-color: transparent; height: 100%; z-index: 2; color: var(--interactive-normal); } -.vc-audio-playback-speed-icon:hover { +.vc-media-playback-speed-icon:hover { color: var(--interactive-active); } From b4e71fe4120969327913388fcb465551aa57a7c1 Mon Sep 17 00:00:00 2001 From: D3SOX Date: Mon, 3 Jun 2024 02:55:18 +0200 Subject: [PATCH 10/20] feat(mediaPlaybackSpeed): add tooltip --- src/plugins/mediaPlaybackSpeed/index.tsx | 59 +++++++++++++----------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/plugins/mediaPlaybackSpeed/index.tsx b/src/plugins/mediaPlaybackSpeed/index.tsx index aff0dc8d5..600983ff4 100644 --- a/src/plugins/mediaPlaybackSpeed/index.tsx +++ b/src/plugins/mediaPlaybackSpeed/index.tsx @@ -10,7 +10,7 @@ import { classNameFactory } from "@api/Styles"; import { makeRange } from "@components/PluginSettings/components"; import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; -import { ContextMenuApi, FluxDispatcher, Menu, React } from "@webpack/common"; +import { ContextMenuApi, FluxDispatcher, Menu, React, Tooltip } from "@webpack/common"; import { RefObject } from "react"; import SpeedIcon from "./components/SpeedIcon"; @@ -33,31 +33,38 @@ export default definePlugin({ }; return ( - + + {({ onMouseEnter, onMouseLeave }) => ( + + )} + ); }, From 065575718de8de68c813ca8e5d63a154617e1d48 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 6 Jun 2024 08:57:15 +0200 Subject: [PATCH 11/20] refactor(mediaPlaybackSpeed): prefix nav id with vc Co-authored-by: vee --- src/plugins/mediaPlaybackSpeed/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/mediaPlaybackSpeed/index.tsx b/src/plugins/mediaPlaybackSpeed/index.tsx index 600983ff4..6f683ae5c 100644 --- a/src/plugins/mediaPlaybackSpeed/index.tsx +++ b/src/plugins/mediaPlaybackSpeed/index.tsx @@ -42,7 +42,7 @@ export default definePlugin({ onClick={e => { ContextMenuApi.openContextMenu(e, () => FluxDispatcher.dispatch({ type: "CONTEXT_MENU_CLOSE" })} aria-label="Playback speed control" > From aec59be3f5a4689b32984ee2276c5077a062c5bd Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 6 Jun 2024 08:57:35 +0200 Subject: [PATCH 12/20] refactor(mediaPlaybackSpeed): spread all tooltip props Co-authored-by: vee --- src/plugins/mediaPlaybackSpeed/index.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/mediaPlaybackSpeed/index.tsx b/src/plugins/mediaPlaybackSpeed/index.tsx index 6f683ae5c..5b2328cf3 100644 --- a/src/plugins/mediaPlaybackSpeed/index.tsx +++ b/src/plugins/mediaPlaybackSpeed/index.tsx @@ -34,11 +34,10 @@ export default definePlugin({ return ( - {({ onMouseEnter, onMouseLeave }) => ( + {tooltipProps => ( + )} + + ); - }), + }, patches: [ // voice message embeds From bf71bbc979b7ec6a609c8e7e5e7f0bd20f9d990e Mon Sep 17 00:00:00 2001 From: Nico Date: Wed, 19 Jun 2024 07:09:54 +0200 Subject: [PATCH 17/20] fix(mediaPlaybackSpeed): update voice message patch --- src/plugins/mediaPlaybackSpeed/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/mediaPlaybackSpeed/index.tsx b/src/plugins/mediaPlaybackSpeed/index.tsx index aa9c48f54..209b518c5 100644 --- a/src/plugins/mediaPlaybackSpeed/index.tsx +++ b/src/plugins/mediaPlaybackSpeed/index.tsx @@ -73,7 +73,7 @@ export default definePlugin({ patches: [ // voice message embeds { - find: "ComponentActions.VOICE_MESSAGE_PLAYBACK_STARTED", + find: "--:--", replacement: { match: /onVolumeShow:\i,onVolumeHide:\i\}\)(?<=useCallback\(\(\)=>\{let \i=(\i).current;.+?)/, replace: "$&,$self.playbackSpeedComponent($1)" From 777b5dde69238b4341ab3b6b1f22670e7f90b1a5 Mon Sep 17 00:00:00 2001 From: Nico Date: Wed, 19 Jun 2024 19:39:42 +0200 Subject: [PATCH 18/20] refactor(mediaPlaybackSpeed): improve find --- src/plugins/mediaPlaybackSpeed/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/mediaPlaybackSpeed/index.tsx b/src/plugins/mediaPlaybackSpeed/index.tsx index 209b518c5..99b8a3fa0 100644 --- a/src/plugins/mediaPlaybackSpeed/index.tsx +++ b/src/plugins/mediaPlaybackSpeed/index.tsx @@ -73,7 +73,7 @@ export default definePlugin({ patches: [ // voice message embeds { - find: "--:--", + find: "\"--:--\"", replacement: { match: /onVolumeShow:\i,onVolumeHide:\i\}\)(?<=useCallback\(\(\)=>\{let \i=(\i).current;.+?)/, replace: "$&,$self.playbackSpeedComponent($1)" From 96df1bbe1ec7d320b138c46207715f9527ccc6f1 Mon Sep 17 00:00:00 2001 From: D3SOX Date: Mon, 1 Jul 2024 18:44:46 +0200 Subject: [PATCH 19/20] feat(mediaPlaybackSpeed): add settings to set default speeds --- src/plugins/mediaPlaybackSpeed/README.md | 2 +- src/plugins/mediaPlaybackSpeed/index.tsx | 130 ++++++++++++++++------- 2 files changed, 92 insertions(+), 40 deletions(-) diff --git a/src/plugins/mediaPlaybackSpeed/README.md b/src/plugins/mediaPlaybackSpeed/README.md index 066a24061..5e8387544 100644 --- a/src/plugins/mediaPlaybackSpeed/README.md +++ b/src/plugins/mediaPlaybackSpeed/README.md @@ -1,5 +1,5 @@ # MediaPlaybackSpeed -Adds an icon to change the playback speed of media embeds +Allows changing the (default) playback speed of media embeds ![New icon with menu to change the playback speed](https://github.com/Vendicated/Vencord/assets/24937357/21792b09-8d6a-45be-a6e8-916cdd67a477) diff --git a/src/plugins/mediaPlaybackSpeed/index.tsx b/src/plugins/mediaPlaybackSpeed/index.tsx index 99b8a3fa0..f1daf94da 100644 --- a/src/plugins/mediaPlaybackSpeed/index.tsx +++ b/src/plugins/mediaPlaybackSpeed/index.tsx @@ -6,26 +6,63 @@ import "./styles.css"; +import { definePluginSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; import ErrorBoundary from "@components/ErrorBoundary"; import { makeRange } from "@components/PluginSettings/components"; import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; -import { ContextMenuApi, FluxDispatcher, Menu, React, Tooltip } from "@webpack/common"; +import definePlugin, { OptionType } from "@utils/types"; +import { ContextMenuApi, FluxDispatcher, Heading, Menu, React, Tooltip, useEffect } from "@webpack/common"; import { RefObject } from "react"; import SpeedIcon from "./components/SpeedIcon"; const cl = classNameFactory("vc-media-playback-speed-"); -const speeds = makeRange(0.25, 3.5, 0.25); +const min = 0.25; +const max = 3.5; +const speeds = makeRange(min, max, 0.25); + +const settings = definePluginSettings({ + test: { + type: OptionType.COMPONENT, + description: "", + component() { + return + Default playback speeds + ; + } + }, + defaultVoiceMessageSpeed: { + type: OptionType.SLIDER, + default: 1, + description: "Voice messages", + markers: speeds, + }, + defaultVideoSpeed: { + type: OptionType.SLIDER, + default: 1, + description: "Videos", + markers: speeds, + }, + defaultAudioSpeed: { + type: OptionType.SLIDER, + default: 1, + description: "Audios", + markers: speeds, + }, +}); + +type MediaRef = RefObject | undefined; export default definePlugin({ name: "MediaPlaybackSpeed", - description: "Adds an icon to change the playback speed of media embeds", + description: "Allows changing the (default) playback speed of media embeds", authors: [Devs.D3SOX], - playbackSpeedComponent: (mediaRef: RefObject | undefined) => { + settings, + + PlaybackSpeedComponent({ mediaRef }: { mediaRef: MediaRef }) { const changeSpeed = (speed: number) => { const media = mediaRef?.current; if (media) { @@ -33,50 +70,65 @@ export default definePlugin({ } }; + useEffect(() => { + if (!mediaRef?.current) return; + const media = mediaRef.current; + if (media.tagName === "AUDIO") { + const isVoiceMessage = media.className.includes("audioElement_"); + changeSpeed(isVoiceMessage ? settings.store.defaultVoiceMessageSpeed : settings.store.defaultAudioSpeed); + } else if (media.tagName === "VIDEO") { + changeSpeed(settings.store.defaultVideoSpeed); + } + }, [mediaRef]); + return ( - - - {tooltipProps => ( - - )} - - + {speeds.map(speed => ( + changeSpeed(speed)} + /> + ))} + + + ); + }}> + + + )} + ); }, + renderComponent(mediaRef: MediaRef) { + return + + ; + }, + patches: [ // voice message embeds { find: "\"--:--\"", replacement: { match: /onVolumeShow:\i,onVolumeHide:\i\}\)(?<=useCallback\(\(\)=>\{let \i=(\i).current;.+?)/, - replace: "$&,$self.playbackSpeedComponent($1)" + replace: "$&,$self.renderComponent($1)" } }, // audio & video embeds @@ -92,7 +144,7 @@ export default definePlugin({ find: "AUDIO:\"AUDIO\"", replacement: { match: /onVolumeHide:\i,iconClassName:\i.controlIcon,sliderWrapperClassName:\i.volumeSliderWrapper\}\)\}\),/, - replace: "$&$self.playbackSpeedComponent(this.props.mediaRef)," + replace: "$&$self.renderComponent(this.props.mediaRef)," } } ] From a3db3faba6519004eaf9edfc4837fb3a190f0356 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 18 Jul 2024 09:11:01 +0200 Subject: [PATCH 20/20] fix(mediaPlaybackSpeed): update broken patch --- src/plugins/mediaPlaybackSpeed/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/mediaPlaybackSpeed/index.tsx b/src/plugins/mediaPlaybackSpeed/index.tsx index f1daf94da..e1776a933 100644 --- a/src/plugins/mediaPlaybackSpeed/index.tsx +++ b/src/plugins/mediaPlaybackSpeed/index.tsx @@ -143,7 +143,7 @@ export default definePlugin({ { find: "AUDIO:\"AUDIO\"", replacement: { - match: /onVolumeHide:\i,iconClassName:\i.controlIcon,sliderWrapperClassName:\i.volumeSliderWrapper\}\)\}\),/, + match: /onVolumeHide:\i,iconClassName:\i.controlIcon,iconColor:"currentColor",sliderWrapperClassName:\i.volumeSliderWrapper\}\)\}\),/, replace: "$&$self.renderComponent(this.props.mediaRef)," } }