1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-10 09:56:24 +00:00

Merge branch 'newDevTools' of github.com:sadan4/vencord into newDevTools

This commit is contained in:
sadan 2024-11-15 09:16:59 -05:00
commit f7740da0e0
No known key found for this signature in database
10 changed files with 212 additions and 32 deletions

3
.gitignore vendored
View file

@ -22,3 +22,6 @@ src/userplugins
ExtensionCache/
settings/
# vencord companion module cache
.modules

View file

@ -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[];

View file

@ -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]>();

View file

@ -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");
@ -162,14 +165,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,
@ -212,7 +215,7 @@ export function initWs(isManual = false) {
}
case "search": {
let moduleId;
if (data.findType === FindType.STRING)
if (data.findType === "string")
moduleId = +findModuleId([idOrSearch.toString()]);
else
@ -287,9 +290,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
@ -326,7 +328,6 @@ export function initWs(isManual = false) {
return reply(`Replacement ${i} failed: ${err}`);
}
}
reply();
break;
}
@ -375,6 +376,138 @@ export function initWs(isManual = false) {
reply();
break;
}
case "allModules": {
const { promise, resolve, reject } = Promise.withResolvers<void>();
// 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(<AllModulesNoti done={promise} close={close} />, "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;
@ -382,3 +515,19 @@ export function initWs(isManual = false) {
});
}
interface AllModulesNotiProps {
done: Promise<unknown>;
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 });

View file

@ -0,0 +1,5 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

View file

@ -26,10 +26,6 @@ export interface RegexNode {
flags: string;
};
}
export enum FindType {
STRING,
REGEX
}
export interface FunctionNode {
type: "function";
value: string;

View file

@ -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(() => {

View file

@ -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<string, IShikiTheme>();

View file

@ -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")
},

View file

@ -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,
},