update companion (#243)

This commit is contained in:
sadan4 2025-04-25 14:52:29 -04:00 committed by GitHub
parent a7f1d87f08
commit fe3777b1b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 36 additions and 8 deletions

View file

@ -61,9 +61,10 @@ 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 we're running the reporter, we need to initws in the reporter file to avoid a race condition
if (!IS_COMPANION_TEST) if (!IS_DEV) throw new Error("This plugin requires dev mode to run, please build with pnpm build --dev");
initWs(); initWs();
}, },
stop: stopWs, stop: stopWs,
}); });

View file

@ -6,6 +6,7 @@
import { popNotice, showNotice } from "@api/Notices"; import { popNotice, showNotice } from "@api/Notices";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { getIntlMessageFromHash } from "@utils/discord";
import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches"; 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";
@ -125,7 +126,7 @@ export function initWs(isManual = false) {
function reply(error?: string) { function reply(error?: string) {
const toSend = { nonce: d.nonce, ok: !error } as Record<string, unknown>; const toSend = { nonce: d.nonce, ok: !error } as Record<string, unknown>;
if (error) toSend.error = error; if (error) toSend.error = error;
logger.debug("Replying with:", toSend); logger.debug(`Replying with:`, toSend);
ws.send(JSON.stringify(toSend)); ws.send(JSON.stringify(toSend));
} }
function replyData(data: OutgoingMessage) { function replyData(data: OutgoingMessage) {
@ -437,8 +438,20 @@ export function initWs(isManual = false) {
}); });
break; break;
} }
case "i18n": {
const { hashedKey } = d.data;
replyData({
type: "i18n",
ok: true,
data: {
value: getIntlMessageFromHash(hashedKey)
}
});
break;
}
default: default:
reply("Unknown Type " + (d as any).type); // @ts-expect-error should be never
reply("Unknown Type " + d?.type);
break; break;
} }
}); });

View file

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

View file

@ -62,7 +62,7 @@ export type FindData = {
args: FindNode[]; args: FindNode[];
}; };
export type IncomingMessage = DisablePlugin | RawId | DiffPatch | Reload | ExtractModule | TestPatch | TestFind | AllModules; export type IncomingMessage = DisablePlugin | RawId | DiffPatch | Reload | ExtractModule | TestPatch | TestFind | AllModules | I18nLookup;
export type FullIncomingMessage = IncomingMessage & { nonce: number; }; export type FullIncomingMessage = IncomingMessage & { nonce: number; };
export type DisablePlugin = { export type DisablePlugin = {
@ -73,6 +73,13 @@ export type DisablePlugin = {
}; };
}; };
export type I18nLookup = {
type: "i18n";
data: {
hashedKey: string;
};
};
/** /**
* @deprecated use {@link ExtractModule} instead * @deprecated use {@link ExtractModule} instead
*/ */

View file

@ -8,7 +8,7 @@
import { ReporterData as IReporterData } from "debug/reporterData"; import { ReporterData as IReporterData } from "debug/reporterData";
export type ReporterData = IReporterData; export type ReporterData = IReporterData;
export type OutgoingMessage = (Report | DiffModule | ExtractModule | ModuleList | RawId) & Base; export type OutgoingMessage = (Report | DiffModule | ExtractModule | ModuleList | RawId | I18nValue) & Base;
export type FullOutgoingMessage = OutgoingMessage & Nonce; export type FullOutgoingMessage = OutgoingMessage & Nonce;
export type Base = { export type Base = {
@ -34,6 +34,13 @@ export type ModuleResult = {
}; };
// #region valid payloads // #region valid payloads
export type I18nValue = {
type: "i18n";
data: {
value: string;
};
};
export type Report = { export type Report = {
type: "report"; type: "report";
data: ReporterData; data: ReporterData;

View file

@ -9,11 +9,12 @@ import { Settings } from "@api/Settings";
import { canonicalizeMatch } from "@utils/patches"; import { canonicalizeMatch } from "@utils/patches";
import { CodeFilter, stringMatches, wreq } from "@webpack"; import { CodeFilter, stringMatches, wreq } from "@webpack";
import { Toasts } from "@webpack/common"; import { Toasts } from "@webpack/common";
import { WebpackPatcher } from "Vencord";
import { logger, settings as companionSettings } from "."; import { logger, settings as companionSettings } from ".";
import { FindNode } from "./types/recieve"; import { FindNode } from "./types/recieve";
const { WebpackPatcher: { getFactoryPatchedBy, getFactoryPatchedSource } } = require("Vencord") as typeof import("Vencord"); const { getFactoryPatchedBy, getFactoryPatchedSource } = WebpackPatcher;
/** /**
* 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