From 0250243db744a57ca2681db2548f416941ce6712 Mon Sep 17 00:00:00 2001 From: sadan <117494111+sadan4@users.noreply.github.com> Date: Fri, 15 Nov 2024 02:23:56 -0500 Subject: [PATCH 1/5] more horror code --- .gitignore | 3 + src/api/Notices.ts | 2 +- src/plugins/devCompanion.dev/initWs.tsx | 165 +++++++++++++++++++- src/plugins/devCompanion.dev/types/index.ts | 5 + src/plugins/devCompanion.dev/util.tsx | 4 - 5 files changed, 166 insertions(+), 13 deletions(-) create mode 100644 src/plugins/devCompanion.dev/types/index.ts diff --git a/.gitignore b/.gitignore index 135673a6d..d01825b1b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ src/userplugins ExtensionCache/ settings/ + +# vencord companion module cache +.modules diff --git a/src/api/Notices.ts b/src/api/Notices.ts index 6d20087a7..5bd2f9b20 100644 --- a/src/api/Notices.ts +++ b/src/api/Notices.ts @@ -18,7 +18,7 @@ import { waitFor } from "@webpack"; -let NoticesModule: any; +export let NoticesModule: any; waitFor(m => m.show && m.dismiss && !m.suppressAll, m => NoticesModule = m); export const noticesQueue = [] as any[]; diff --git a/src/plugins/devCompanion.dev/initWs.tsx b/src/plugins/devCompanion.dev/initWs.tsx index 1cb67fa75..d846e9c5d 100644 --- a/src/plugins/devCompanion.dev/initWs.tsx +++ b/src/plugins/devCompanion.dev/initWs.tsx @@ -4,14 +4,17 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ +import { popNotice, showNotice } from "@api/Notices"; +import ErrorBoundary from "@components/ErrorBoundary"; import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches"; import { filters, findAll, search, wreq } from "@webpack"; -import { Toasts } from "@webpack/common"; +import { React, Toasts, useState } from "@webpack/common"; +import { loadLazyChunks } from "debug/loadLazyChunks"; import { reporterData } from "debug/reporterData"; import { Settings } from "Vencord"; import { logger, PORT, settings } from "."; -import { extractModule, extractOrThrow, FindData, findModuleId, FindType, mkRegexFind, parseNode, PatchData, SendData, toggleEnabled, } from "./util"; +import { extractModule, extractOrThrow, FindData, findModuleId, mkRegexFind, parseNode, PatchData, SendData, toggleEnabled, } from "./util"; export function stopWs() { socket?.close(1000, "Plugin Stopped"); @@ -155,14 +158,14 @@ export function initWs(isManual = false) { } case "search": { let moduleId; - if (data.findType === FindType.STRING) + if (data.findType === "string") moduleId = +findModuleId([idOrSearch.toString()]); else moduleId = +findModuleId(mkRegexFind(idOrSearch)); const p = extractOrThrow(moduleId); const p2 = extractModule(moduleId, false); - console.log(p, p2, "done"); + replyData({ type: "diff", ok: true, @@ -205,7 +208,7 @@ export function initWs(isManual = false) { } case "search": { let moduleId; - if (data.findType === FindType.STRING) + if (data.findType === "string") moduleId = +findModuleId([idOrSearch.toString()]); else @@ -280,9 +283,8 @@ export function initWs(isManual = false) { } case "testPatch": { const { find, replacement } = data as PatchData; - let candidates; - if (data.findType === FindType.STRING) + if (data.findType === "string") candidates = search(find.toString()); else @@ -319,7 +321,6 @@ export function initWs(isManual = false) { return reply(`Replacement ${i} failed: ${err}`); } } - reply(); break; } @@ -368,6 +369,138 @@ export function initWs(isManual = false) { reply(); break; } + case "allModules": { + const { promise, resolve, reject } = Promise.withResolvers(); + // wrap in try/catch to prevent crashing if notice api is not loaded + try { + let closed = false; + const close = () => { + if (closed) return; + closed = true; + popNotice(); + }; + // @ts-expect-error it accepts react components + showNotice(, "OK", () => { + closed = true; + popNotice(); + }); + } catch (e) { + console.error(e); + } + loadLazyChunks() + .then(() => { + resolve(); + replyData({ + type: "allModules", + data: Object.keys(wreq.m), + ok: true + }); + }) + .catch(e => { + console.error(e); + replyData({ + type: "allModules", + ok: false, + data: e.toString() + }); + reject(e); + }); + break; + } + // FIXME: this is just extract but with a different name + case "rawContent": { + try { + const { extractType, idOrSearch } = data; + switch (extractType) { + case "id": { + if (typeof idOrSearch !== "number") + throw new Error("Id is not a number, got :" + typeof idOrSearch); + + else + replyData({ + type: "rawContent", + ok: true, + data: extractModule(idOrSearch), + moduleNumber: idOrSearch + }); + + break; + } + case "search": { + let moduleId; + if (data.findType === "string") + moduleId = +findModuleId([idOrSearch.toString()]); + + else + moduleId = +findModuleId(mkRegexFind(idOrSearch)); + replyData({ + type: "rawContent", + ok: true, + data: extractModule(moduleId), + moduleNumber: moduleId + }); + break; + } + case "find": { + const { findType, findArgs } = data; + try { + var parsedArgs = findArgs.map(parseNode); + } catch (err) { + return reply("Failed to parse args: " + err); + } + + try { + let results: any[]; + switch (findType.replace("find", "").replace("Lazy", "")) { + case "": + case "Component": + results = findAll(parsedArgs[0]); + break; + case "ByProps": + results = findAll(filters.byProps(...parsedArgs)); + break; + case "Store": + results = findAll(filters.byStoreName(parsedArgs[0])); + break; + case "ByCode": + results = findAll(filters.byCode(...parsedArgs)); + break; + case "ModuleId": + results = Object.keys(search(parsedArgs[0])); + break; + case "ComponentByCode": + results = findAll(filters.componentByCode(...parsedArgs)); + break; + default: + return reply("Unknown Find Type " + findType); + } + + const uniqueResultsCount = new Set(results).size; + if (uniqueResultsCount === 0) throw "No results"; + if (uniqueResultsCount > 1) throw "Found more than one result! Make this filter more specific"; + // best name ever + const foundFind: string = [...results][0].toString(); + replyData({ + type: "rawContent", + ok: true, + find: true, + data: foundFind, + moduleNumber: +findModuleId([foundFind]) + }); + } catch (err) { + return reply("Failed to find: " + err); + } + break; + } + default: + reply(`Unknown Extract type. Got: ${extractType}`); + break; + } + } catch (error) { + reply(String(error)); + } + break; + } default: reply("Unknown Type " + type); break; @@ -375,3 +508,19 @@ export function initWs(isManual = false) { }); } +interface AllModulesNotiProps { + done: Promise; + close: () => void; +} + +const AllModulesNoti = ErrorBoundary.wrap(function ({ done, close }: AllModulesNotiProps) { + const [state, setState] = useState<0 | 1 | -1>(0); + done.then(setState.bind(null, 1)).catch(setState.bind(null, -1)); + console.log("test"); + if (state === 1) setTimeout(close, 5000); + return (<> + {state === 0 && "Loading lazy modules, restarting could lead to errors"} + {state === 1 && "Loaded all lazy modules"} + {state === -1 && "Failed to load lazy modules, check console for errors"} + ); +}, { noop: true }); diff --git a/src/plugins/devCompanion.dev/types/index.ts b/src/plugins/devCompanion.dev/types/index.ts new file mode 100644 index 000000000..3beb3e42c --- /dev/null +++ b/src/plugins/devCompanion.dev/types/index.ts @@ -0,0 +1,5 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ diff --git a/src/plugins/devCompanion.dev/util.tsx b/src/plugins/devCompanion.dev/util.tsx index f18496aba..9765ae908 100644 --- a/src/plugins/devCompanion.dev/util.tsx +++ b/src/plugins/devCompanion.dev/util.tsx @@ -26,10 +26,6 @@ export interface RegexNode { flags: string; }; } -export enum FindType { - STRING, - REGEX -} export interface FunctionNode { type: "function"; value: string; From a203477c1886ff3799411fb1231aa5cc901d797e Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:51:58 -0300 Subject: [PATCH 2/5] Actually stop searching for CSS debugging chunk --- src/debug/loadLazyChunks.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/debug/loadLazyChunks.ts b/src/debug/loadLazyChunks.ts index 6923d3a23..c7f8047db 100644 --- a/src/debug/loadLazyChunks.ts +++ b/src/debug/loadLazyChunks.ts @@ -27,11 +27,11 @@ export async function loadLazyChunks() { const LazyChunkRegex = canonicalizeMatch(/(?:(?:Promise\.all\(\[)?(\i\.e\("?[^)]+?"?\)[^\]]*?)(?:\]\))?)\.then\(\i\.bind\(\i,"?([^)]+?)"?\)\)/g); - const foundCssDebuggingLoad = false; + let foundCssDebuggingLoad = false; async function searchAndLoadLazyChunks(factoryCode: string) { // Workaround to avoid loading the CSS debugging chunk which turns the app pink - const hasCssDebuggingLoad = foundCssDebuggingLoad ? false : factoryCode.includes(".cssDebuggingEnabled&&"); + const hasCssDebuggingLoad = foundCssDebuggingLoad ? false : (foundCssDebuggingLoad = factoryCode.includes(".cssDebuggingEnabled&&")); const lazyChunks = factoryCode.matchAll(LazyChunkRegex); const validChunkGroups = new Set<[chunkIds: number[], entryPoint: number]>(); From eeeb4d46b66e468ec577327c91004673eab9c415 Mon Sep 17 00:00:00 2001 From: Frocat <65976911+ItsFrocat@users.noreply.github.com> Date: Thu, 14 Nov 2024 23:54:01 +0100 Subject: [PATCH 3/5] ShikiCodeblocks: Updated codeblocks themes (#3013) --- .../shikiCodeblocks.desktop/api/themes.ts | 46 +++++++++++++++---- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/plugins/shikiCodeblocks.desktop/api/themes.ts b/src/plugins/shikiCodeblocks.desktop/api/themes.ts index f31ce60b3..bc1dd184d 100644 --- a/src/plugins/shikiCodeblocks.desktop/api/themes.ts +++ b/src/plugins/shikiCodeblocks.desktop/api/themes.ts @@ -1,6 +1,6 @@ /* * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors + * Copyright (c) 2024 Vendicated and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,9 +18,9 @@ import { IShikiTheme } from "@vap/shiki"; -export const SHIKI_REPO = "shikijs/shiki"; -export const SHIKI_REPO_COMMIT = "0b28ad8ccfbf2615f2d9d38ea8255416b8ac3043"; -export const shikiRepoTheme = (name: string) => `https://raw.githubusercontent.com/${SHIKI_REPO}/${SHIKI_REPO_COMMIT}/packages/shiki/themes/${name}.json`; +export const SHIKI_REPO = "shikijs/textmate-grammars-themes"; +export const SHIKI_REPO_COMMIT = "2d87559c7601a928b9f7e0f0dda243d2fb6d4499"; +export const shikiRepoTheme = (name: string) => `https://raw.githubusercontent.com/${SHIKI_REPO}/${SHIKI_REPO_COMMIT}/packages/tm-themes/themes/${name}.json`; export const themes = { // Default @@ -30,33 +30,59 @@ export const themes = { MaterialCandy: "https://raw.githubusercontent.com/millsp/material-candy/master/material-candy.json", // More from Shiki repo + Andromeeda: shikiRepoTheme("andromeeda"), + AuroraX: shikiRepoTheme("aurora-x"), + AyuDark: shikiRepoTheme("ayu-dark"), + CatppuccinLatte: shikiRepoTheme("catppuccin-latte"), + CatppuccinFrappe: shikiRepoTheme("catppuccin-frappe"), + CatppuccinMacchiato: shikiRepoTheme("catppuccin-macchiato"), + CatppuccinMocha: shikiRepoTheme("catppuccin-mocha"), DraculaSoft: shikiRepoTheme("dracula-soft"), Dracula: shikiRepoTheme("dracula"), + EverforestDark: shikiRepoTheme("everforest-dark"), + EverforestLight: shikiRepoTheme("everforest-light"), + GithubDarkDefault: shikiRepoTheme("github-dark-default"), GithubDarkDimmed: shikiRepoTheme("github-dark-dimmed"), + GithubDarkHighContrast: shikiRepoTheme("github-dark-high-contrast"), GithubDark: shikiRepoTheme("github-dark"), + GithubLightDefault: shikiRepoTheme("github-light-default"), + GithubLightHighContrast: shikiRepoTheme("github-light-high-contrast"), GithubLight: shikiRepoTheme("github-light"), + Houston: shikiRepoTheme("houston"), + KanagawaDragon: shikiRepoTheme("kanagawa-dragon"), + KanagawaLotus: shikiRepoTheme("kanagawa-lotus"), + KanagawaWave: shikiRepoTheme("kanagawa-wave"), + LaserWave: shikiRepoTheme("laserwave"), LightPlus: shikiRepoTheme("light-plus"), - MaterialDarker: shikiRepoTheme("material-darker"), - MaterialDefault: shikiRepoTheme("material-default"), - MaterialLighter: shikiRepoTheme("material-lighter"), - MaterialOcean: shikiRepoTheme("material-ocean"), - MaterialPalenight: shikiRepoTheme("material-palenight"), + MaterialDarker: shikiRepoTheme("material-theme-darker"), + MaterialDefault: shikiRepoTheme("material-theme"), + MaterialLighter: shikiRepoTheme("material-theme-lighter"), + MaterialOcean: shikiRepoTheme("material-theme-ocean"), + MaterialPalenight: shikiRepoTheme("material-theme-palenight"), MinDark: shikiRepoTheme("min-dark"), MinLight: shikiRepoTheme("min-light"), Monokai: shikiRepoTheme("monokai"), + NightOwl: shikiRepoTheme("night-owl"), Nord: shikiRepoTheme("nord"), OneDarkPro: shikiRepoTheme("one-dark-pro"), + OneLight: shikiRepoTheme("one-light"), + Plastic: shikiRepoTheme("plastic"), Poimandres: shikiRepoTheme("poimandres"), + Red: shikiRepoTheme("red"), RosePineDawn: shikiRepoTheme("rose-pine-dawn"), RosePineMoon: shikiRepoTheme("rose-pine-moon"), RosePine: shikiRepoTheme("rose-pine"), SlackDark: shikiRepoTheme("slack-dark"), SlackOchin: shikiRepoTheme("slack-ochin"), + SnazzyLight: shikiRepoTheme("snazzy-light"), SolarizedDark: shikiRepoTheme("solarized-dark"), SolarizedLight: shikiRepoTheme("solarized-light"), + Synthwave84: shikiRepoTheme("synthwave-84"), + TokyoNight: shikiRepoTheme("tokyo-night"), + Vesper: shikiRepoTheme("vesper"), + VitesseBlack: shikiRepoTheme("vitesse-black"), VitesseDark: shikiRepoTheme("vitesse-dark"), VitesseLight: shikiRepoTheme("vitesse-light"), - CssVariables: shikiRepoTheme("css-variables"), }; export const themeCache = new Map(); From 62c59c0456fee18fdc835e9a7280a3462b1e62f3 Mon Sep 17 00:00:00 2001 From: Lumap Date: Thu, 14 Nov 2024 23:57:16 +0100 Subject: [PATCH 4/5] PictureInPicture: Fix button not showing up (#3014) --- src/plugins/pictureInPicture/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/pictureInPicture/index.tsx b/src/plugins/pictureInPicture/index.tsx index 20cedf45b..ef3d35ff1 100644 --- a/src/plugins/pictureInPicture/index.tsx +++ b/src/plugins/pictureInPicture/index.tsx @@ -30,10 +30,10 @@ export default definePlugin({ { find: ".removeMosaicItemHoverButton),", replacement: { - match: /\.nonMediaMosaicItem\]:!(\i).{0,50}?children:\[\S,(\S)/, - replace: "$&,$1&&$2&&$self.renderPiPButton()," - }, - }, + match: /\.nonMediaMosaicItem\]:.{0,40}children:\[(?<=showDownload:(\i).+?isVisualMediaType:(\i).+?)/, + replace: "$&$1&&$2&&$self.renderPiPButton()," + } + } ], renderPiPButton: ErrorBoundary.wrap(() => { From 4c37b87f95f546fd0c25b547a47eff526dd96c96 Mon Sep 17 00:00:00 2001 From: nyx <60797172+verticalsync@users.noreply.github.com> Date: Fri, 15 Nov 2024 01:00:11 +0200 Subject: [PATCH 5/5] ViewRaw: Add support for Group DMs (#3010) --- src/plugins/viewRaw/index.tsx | 1 + src/utils/constants.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/viewRaw/index.tsx b/src/plugins/viewRaw/index.tsx index 0134ea3e3..8ee1ca8d7 100644 --- a/src/plugins/viewRaw/index.tsx +++ b/src/plugins/viewRaw/index.tsx @@ -155,6 +155,7 @@ export default definePlugin({ "guild-context": MakeContextCallback("Guild"), "channel-context": MakeContextCallback("Channel"), "thread-context": MakeContextCallback("Channel"), + "gdm-context": MakeContextCallback("Channel"), "user-context": MakeContextCallback("User") }, diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 70eca56fd..11ce47388 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -520,8 +520,8 @@ export const Devs = /* #__PURE__*/ Object.freeze({ id: 721717126523781240n, }, nyx: { - name: "verticalsync", - id: 328165170536775680n + name: "verticalsync.", + id: 1207087393929171095n }, nekohaxx: { name: "nekohaxx", @@ -575,7 +575,7 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "RamziAH", id: 1279957227612147747n, }, - SomeAspy: { + SomeAspy: { name: "SomeAspy", id: 516750892372852754n, },