Update DevComp to PR

This commit is contained in:
thororen1234 2025-01-09 10:37:02 -05:00
parent 218dadbe04
commit 93ec8dbe7a
10 changed files with 58 additions and 16 deletions

3
.gitignore vendored
View file

@ -26,3 +26,6 @@ ExtensionCache/
settings/ settings/
src/equicordplugins/usrpe src/equicordplugins/usrpe
# vencord companion module cache
.modules

View file

@ -18,5 +18,6 @@
"domain": "codeberg.org", "domain": "codeberg.org",
"type": "Gitea" "type": "Gitea"
} }
] ],
"equicord-companion.showSidebar": true,
} }

19
.vscode/tasks.json vendored
View file

@ -31,6 +31,25 @@
"command": "pnpm build --dev", "command": "pnpm build --dev",
"group": "build" "group": "build"
}, },
{
// for use with the vencord companion extension
"label": "Build Companion Reporter",
"type": "shell",
"command": "pnpm build --dev --reporter --companion-test",
"presentation": {
"echo": true,
"reveal": "silent",
"panel": "shared",
"showReuseMessage": true,
"clear": true
}
},
{
"label": "Build Dev",
"type": "shell",
"command": "pnpm build --dev",
"group": "build"
},
{ {
"label": "Watch", "label": "Watch",
"type": "shell", "type": "shell",

View file

@ -18,7 +18,7 @@
import { waitFor } from "@webpack"; import { waitFor } from "@webpack";
let NoticesModule: any; export let NoticesModule: any;
waitFor(m => m.show && m.dismiss && !m.suppressAll, m => NoticesModule = m); waitFor(m => m.show && m.dismiss && !m.suppressAll, m => NoticesModule = m);
export const noticesQueue = [] as any[]; export const noticesQueue = [] as any[];

View file

@ -17,7 +17,7 @@ interface ErroredPatch extends EvaledPatch {
oldModule: string, oldModule: string,
newModule: string; newModule: string;
} }
interface ReporterData { export interface ReporterData {
failedPatches: { failedPatches: {
foundNoModule: Patch[]; foundNoModule: Patch[];
hadNoEffect: EvaledPatch[]; hadNoEffect: EvaledPatch[];

View file

@ -22,7 +22,9 @@ import { Logger } from "@utils/Logger";
import definePlugin, { OptionType, ReporterTestable } from "@utils/types"; import definePlugin, { OptionType, ReporterTestable } from "@utils/types";
import { initWs, socket, stopWs } from "./initWs"; import { initWs, socket, stopWs } from "./initWs";
console.log("imported");
export const PORT = 8485; export const PORT = 8485;
const NAV_ID = "dev-companion-reconnect";
export const logger = new Logger("DevCompanion"); export const logger = new Logger("DevCompanion");
@ -59,6 +61,8 @@ export default definePlugin({
}, },
start() { start() {
// if we're running the reporter, we need to initws in the reporter file to avoid a race condition
if (!IS_COMPANION_TEST)
initWs(); initWs();
}, },

View file

@ -10,11 +10,11 @@ import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches";
import { filters, findAll, search, wreq } from "@webpack"; import { filters, findAll, search, wreq } from "@webpack";
import { React, Toasts, useState } from "@webpack/common"; import { React, Toasts, useState } from "@webpack/common";
import { loadLazyChunks } from "debug/loadLazyChunks"; import { loadLazyChunks } from "debug/loadLazyChunks";
import { reporterData } from "debug/reporterData";
import { Settings } from "Vencord"; import { Settings } from "Vencord";
import { logger, PORT, settings } from "."; import { logger, PORT, settings } from ".";
import { Recieve } from "./types"; import { Recieve, Send } from "./types";
import { FullOutgoingMessage, OutgoingMessage } from "./types/send";
import { extractModule, extractOrThrow, findModuleId, mkRegexFind, parseNode, toggleEnabled, } from "./util"; import { extractModule, extractOrThrow, findModuleId, mkRegexFind, parseNode, toggleEnabled, } from "./util";
export function stopWs() { export function stopWs() {
@ -29,7 +29,7 @@ export function initWs(isManual = false) {
let hasErrored = false; let hasErrored = false;
const ws = socket = new WebSocket(`ws://localhost:${PORT}`); const ws = socket = new WebSocket(`ws://localhost:${PORT}`);
function replyData(data: OutgoingMessage) { function replyData(data: Send.OutgoingMessage) {
ws.send(JSON.stringify(data)); ws.send(JSON.stringify(data));
} }
@ -47,6 +47,21 @@ export function initWs(isManual = false) {
ok: true ok: true
}); });
if (IS_COMPANION_TEST) {
const toSend = JSON.stringify(reporterData, (_k, v) => {
if (v instanceof RegExp)
return String(v);
return v;
});
socket?.send(JSON.stringify({
type: "report",
data: JSON.parse(toSend),
ok: true
}));
}
try { try {
if (settings.store.notifyOnAutoConnect || isManual) { if (settings.store.notifyOnAutoConnect || isManual) {
Toasts.show({ Toasts.show({
@ -112,8 +127,8 @@ export function initWs(isManual = false) {
ws.send(JSON.stringify(data)); ws.send(JSON.stringify(data));
} }
function replyData(data: OutgoingMessage) { function replyData(data: Send.OutgoingMessage) {
const toSend: FullOutgoingMessage = { const toSend: Send.FullOutgoingMessage = {
...data, ...data,
nonce: d.nonce nonce: d.nonce
}; };
@ -290,7 +305,6 @@ export function initWs(isManual = false) {
case "testPatch": { case "testPatch": {
const m = d.data; const m = d.data;
let candidates; let candidates;
console.log(m.find.toString());
if (d.data.findType === "string") if (d.data.findType === "string")
candidates = search(m.find.toString()); candidates = search(m.find.toString());

View file

@ -5,3 +5,4 @@
*/ */
export * as Recieve from "./recieve"; export * as Recieve from "./recieve";
export * as Send from "./send";

View file

@ -5,8 +5,8 @@
*/ */
// should be the same types as src/server/types/recieve.ts in the companion // should be the same types as src/server/types/recieve.ts in the companion
import { reporterData } from "debug/reporterData"; import { ReporterData as IReporterData } from "debug/reporterData";
export type ReporterData = typeof reporterData; export type ReporterData = IReporterData;
export type OutgoingMessage = (Report | DiffModule | ExtractModule | ModuleList | RawId) & Base; export type OutgoingMessage = (Report | DiffModule | ExtractModule | ModuleList | RawId) & Base;
export type FullOutgoingMessage = OutgoingMessage & Nonce; export type FullOutgoingMessage = OutgoingMessage & Nonce;

View file

@ -11,7 +11,7 @@ import { CodeFilter, stringMatches, wreq } from "@webpack";
import { Toasts } from "@webpack/common"; import { Toasts } from "@webpack/common";
import { settings as companionSettings } from "."; import { settings as companionSettings } from ".";
import { FindNode } from "./types/recieve"; import { Recieve } from "./types";
/** /**
* extracts the patched module, if there is no patched module, throws an error * extracts the patched module, if there is no patched module, throws an error
@ -37,7 +37,7 @@ export function extractModule(id: number, patched = companionSettings.store.useP
throw new Error("No module found for module id:" + id); throw new Error("No module found for module id:" + id);
return patched ? module.$$vencordPatchedSource ?? module.original.toString() : module.original.toString(); return patched ? module.$$vencordPatchedSource ?? module.original.toString() : module.original.toString();
} }
export function parseNode(node: FindNode): any { export function parseNode(node: Recieve.FindNode): any {
switch (node.type) { switch (node.type) {
case "string": case "string":
return node.value; return node.value;