[Global] Preliminary debug ws implementation

This commit is contained in:
Beef 2022-10-19 23:11:44 +01:00
parent b4f5bdc996
commit daf0357d60
6 changed files with 117 additions and 6 deletions

View file

@ -3,12 +3,14 @@ import logger from "@lib/logger";
import * as metro from "@metro/filters";
import * as common from "@metro/common";
import initSettings from "./ui/settings";
import { patchLogHook } from "./lib/debug";
console.log("Hello from Vendetta!");
let erroredOnLoad = false;
try {
initSettings();
patchLogHook();
window.vendetta = {
patcher: patcher,

31
src/lib/debug.ts Normal file
View file

@ -0,0 +1,31 @@
import { after } from "spitroast";
import logger from "./logger";
export let socket: WebSocket;
let iLoveBundlers = eval;
export function connectToDebugWS(url: string) {
if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) {
socket.close();
}
socket = new WebSocket(`ws://${url}`);
socket.addEventListener("message", (message: any) => {
try {
console.log(iLoveBundlers(message.data));
} catch (e) {
console.error(e);
}
});
}
export function patchLogHook() {
after("nativeLoggingHook", globalThis, (args, ret) => {
if (socket?.readyState === WebSocket.OPEN) {
socket.send(JSON.stringify({ message: args[0], level: args[1] }));
}
logger.log(args[0]);
});
}

View file

@ -7,4 +7,7 @@ export const i18n = findByProps("Messages");
// React
export const React = findByProps("createElement") as typeof import("react");
export const ReactNative = findByProps("Text", "Image") as typeof import("react-native");
export const ReactNative = findByProps("Text", "Image") as typeof import("react-native");
// AsyncStorage
export const AsyncStorage = findByProps("setItem") as typeof import("@react-native-async-storage/async-storage").default;

View file

@ -1,12 +1,15 @@
import { React, ReactNative as RN } from "@metro/common";
import { connectToDebugWS } from "@/lib/debug";
import { AsyncStorage, React, ReactNative as RN } from "@metro/common";
import { Forms } from "@ui/components";
import Version from "./Version";
const { FormRow, FormSection } = Forms;
const { FormRow, FormSection, FormInput } = Forms;
const hermesProps = window.HermesInternal.getRuntimeProperties();
const rnVer = RN.Platform.constants.reactNativeVersion;
export default function Settings() {
const [debuggerUrl, setDebuggerUrl] = React.useState("");
const versions = [
{
label: "Discord",
@ -33,12 +36,24 @@ export default function Settings() {
return (
<>
{/* Why is there still a divider? */}
<FormSection title="Actions" android_noDivider>
<FormSection title="Debug" android_noDivider>
<FormInput
value={debuggerUrl}
onChange={(v: string) => setDebuggerUrl(v)}
title="DEBUGGER URL"
/>
</FormSection>
<FormSection title="Actions">
<FormRow
label="Reload Discord"
trailing={FormRow.Arrow}
onPress={() => RN.NativeModules.BundleUpdaterManager.reload()}
/>
<FormRow
label="Connect to debug websocket"
trailing={FormRow.Arrow}
onPress={() => connectToDebugWS(debuggerUrl)}
/>
</FormSection>
<FormSection title="Versions">
{versions.map((v) => <Version label={v.label} version={v.version} /> )}