dev companion updates
This commit is contained in:
parent
c66776a8e8
commit
77f1c71e8c
3 changed files with 23 additions and 5 deletions
|
|
@ -23,7 +23,7 @@ import definePlugin, { OptionType, ReporterTestable } from "@utils/types";
|
||||||
|
|
||||||
import { initWs, socket, stopWs } from "./initWs";
|
import { initWs, socket, stopWs } from "./initWs";
|
||||||
export const PORT = 8485;
|
export const PORT = 8485;
|
||||||
export const CLIENT_VERSION: readonly [major: number, minor: number, patch: number] = [0, 1, 2];
|
export const CLIENT_VERSION: readonly [major: number, minor: number, patch: number] = [0, 1, 3];
|
||||||
|
|
||||||
export const logger = new Logger("DevCompanion");
|
export const logger = new Logger("DevCompanion");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,12 +122,25 @@ export function initWs(isManual = false) {
|
||||||
/**
|
/**
|
||||||
* @param error the error to reply with. if there is no error, the reply is a sucess
|
* @param error the error to reply with. if there is no error, the reply is a sucess
|
||||||
*/
|
*/
|
||||||
function reply(error?: string) {
|
function replyError(error: string) {
|
||||||
const toSend = { nonce: d.nonce, ok: !error } as Record<string, unknown>;
|
const toSend = { nonce: d.nonce, ok: false, error } as Record<string, unknown>;
|
||||||
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 replyOk() {
|
||||||
|
const toSend = {
|
||||||
|
nonce: d.nonce,
|
||||||
|
ok: true,
|
||||||
|
type: "genericOk",
|
||||||
|
data: {},
|
||||||
|
} as Record<string, unknown>;
|
||||||
|
logger.debug("Replying with:", toSend);
|
||||||
|
ws.send(JSON.stringify(toSend));
|
||||||
|
}
|
||||||
|
function reply(error?: string) {
|
||||||
|
if (error) replyError(error);
|
||||||
|
else replyOk();
|
||||||
|
}
|
||||||
function replyData(data: OutgoingMessage) {
|
function replyData(data: OutgoingMessage) {
|
||||||
const toSend: FullOutgoingMessage = {
|
const toSend: FullOutgoingMessage = {
|
||||||
...data,
|
...data,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import { ReporterData } from "@debug/reporterData";
|
import { ReporterData } from "@debug/reporterData";
|
||||||
|
|
||||||
export type OutgoingMessage = Base<DiffModule | ExtractModule | ModuleList | RawId | I18nValue | VersionResponse>;
|
export type OutgoingMessage = Base<DiffModule | ExtractModule | ModuleList | RawId | I18nValue | VersionResponse | GenericOk>;
|
||||||
export type FullOutgoingMessage = OutgoingMessage & Nonce;
|
export type FullOutgoingMessage = OutgoingMessage & Nonce;
|
||||||
|
|
||||||
export type Base<T> = ({
|
export type Base<T> = ({
|
||||||
|
|
@ -32,6 +32,11 @@ export type ModuleResult = {
|
||||||
patchedBy: string[];
|
patchedBy: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type GenericOk = {
|
||||||
|
type: "genericOk";
|
||||||
|
data: {};
|
||||||
|
};
|
||||||
|
|
||||||
// #region valid payloads
|
// #region valid payloads
|
||||||
export type I18nValue = {
|
export type I18nValue = {
|
||||||
type: "i18n";
|
type: "i18n";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue