diff --git a/.gitignore b/.gitignore index 1055b510..ed2eca9c 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ ExtensionCache/ settings/ src/equicordplugins/usrpe + +# vencord companion module cache +.modules diff --git a/.vscode/settings.json b/.vscode/settings.json index 076215ed..df9c501a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,5 +18,6 @@ "domain": "codeberg.org", "type": "Gitea" } - ] -} + ], + "equicord-companion.showSidebar": true, +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7706f6e5..d32d009d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -31,6 +31,25 @@ "command": "pnpm build --dev", "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", "type": "shell", @@ -41,4 +60,4 @@ } } ] -} +} \ No newline at end of file diff --git a/src/api/Notices.ts b/src/api/Notices.ts index cd5d5876..72054aa0 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/debug/reporterData.ts b/src/debug/reporterData.ts index 1ed7a9cb..1bce68f6 100644 --- a/src/debug/reporterData.ts +++ b/src/debug/reporterData.ts @@ -17,7 +17,7 @@ interface ErroredPatch extends EvaledPatch { oldModule: string, newModule: string; } -interface ReporterData { +export interface ReporterData { failedPatches: { foundNoModule: Patch[]; hadNoEffect: EvaledPatch[]; diff --git a/src/plugins/devCompanion/index.tsx b/src/plugins/devCompanion/index.tsx index a72c519e..e7bb86b2 100644 --- a/src/plugins/devCompanion/index.tsx +++ b/src/plugins/devCompanion/index.tsx @@ -22,7 +22,9 @@ import { Logger } from "@utils/Logger"; import definePlugin, { OptionType, ReporterTestable } from "@utils/types"; import { initWs, socket, stopWs } from "./initWs"; +console.log("imported"); export const PORT = 8485; +const NAV_ID = "dev-companion-reconnect"; export const logger = new Logger("DevCompanion"); @@ -59,7 +61,9 @@ export default definePlugin({ }, start() { - initWs(); + // if we're running the reporter, we need to initws in the reporter file to avoid a race condition + if (!IS_COMPANION_TEST) + initWs(); }, stop: stopWs, diff --git a/src/plugins/devCompanion/initWs.tsx b/src/plugins/devCompanion/initWs.tsx index 702b706c..941e84bb 100644 --- a/src/plugins/devCompanion/initWs.tsx +++ b/src/plugins/devCompanion/initWs.tsx @@ -10,11 +10,11 @@ import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches"; import { filters, findAll, search, wreq } from "@webpack"; 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 { Recieve } from "./types"; -import { FullOutgoingMessage, OutgoingMessage } from "./types/send"; +import { Recieve, Send } from "./types"; import { extractModule, extractOrThrow, findModuleId, mkRegexFind, parseNode, toggleEnabled, } from "./util"; export function stopWs() { @@ -29,7 +29,7 @@ export function initWs(isManual = false) { let hasErrored = false; const ws = socket = new WebSocket(`ws://localhost:${PORT}`); - function replyData(data: OutgoingMessage) { + function replyData(data: Send.OutgoingMessage) { ws.send(JSON.stringify(data)); } @@ -47,6 +47,21 @@ export function initWs(isManual = false) { 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 { if (settings.store.notifyOnAutoConnect || isManual) { Toasts.show({ @@ -112,8 +127,8 @@ export function initWs(isManual = false) { ws.send(JSON.stringify(data)); } - function replyData(data: OutgoingMessage) { - const toSend: FullOutgoingMessage = { + function replyData(data: Send.OutgoingMessage) { + const toSend: Send.FullOutgoingMessage = { ...data, nonce: d.nonce }; @@ -290,7 +305,6 @@ export function initWs(isManual = false) { case "testPatch": { const m = d.data; let candidates; - console.log(m.find.toString()); if (d.data.findType === "string") candidates = search(m.find.toString()); diff --git a/src/plugins/devCompanion/types/index.ts b/src/plugins/devCompanion/types/index.ts index 18bc6854..532843e1 100644 --- a/src/plugins/devCompanion/types/index.ts +++ b/src/plugins/devCompanion/types/index.ts @@ -5,3 +5,4 @@ */ export * as Recieve from "./recieve"; +export * as Send from "./send"; diff --git a/src/plugins/devCompanion/types/send.ts b/src/plugins/devCompanion/types/send.ts index 5865d681..870189b1 100644 --- a/src/plugins/devCompanion/types/send.ts +++ b/src/plugins/devCompanion/types/send.ts @@ -5,8 +5,8 @@ */ // should be the same types as src/server/types/recieve.ts in the companion -import { reporterData } from "debug/reporterData"; -export type ReporterData = typeof reporterData; +import { ReporterData as IReporterData } from "debug/reporterData"; +export type ReporterData = IReporterData; export type OutgoingMessage = (Report | DiffModule | ExtractModule | ModuleList | RawId) & Base; export type FullOutgoingMessage = OutgoingMessage & Nonce; diff --git a/src/plugins/devCompanion/util.tsx b/src/plugins/devCompanion/util.tsx index 8e172976..95d6c403 100644 --- a/src/plugins/devCompanion/util.tsx +++ b/src/plugins/devCompanion/util.tsx @@ -11,7 +11,7 @@ import { CodeFilter, stringMatches, wreq } from "@webpack"; import { Toasts } from "@webpack/common"; 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 @@ -37,7 +37,7 @@ export function extractModule(id: number, patched = companionSettings.store.useP throw new Error("No module found for module id:" + id); 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) { case "string": return node.value;