[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

@ -14,6 +14,7 @@
"author": "Beef",
"license": "BSD-3-Clause",
"devDependencies": {
"@react-native-async-storage/async-storage": "^1.17.10",
"@types/react": "^18.0.21",
"@types/react-native": "^0.70.5",
"esbuild": "^0.15.11",
@ -23,7 +24,8 @@
"zustand": "^4.1.2"
},
"dependencies": {
"spitroast": "^1.4.2"
"spitroast": "^1.4.2",
"valtio": "^1.7.4"
},
"pnpm": {
"peerDependencyRules": {

View file

@ -1,6 +1,7 @@
lockfileVersion: 5.4
specifiers:
'@react-native-async-storage/async-storage': ^1.17.10
'@types/react': ^18.0.21
'@types/react-native': ^0.70.5
esbuild: ^0.15.11
@ -8,12 +9,15 @@ specifiers:
redux: ^4.2.0
spitroast: ^1.4.2
typescript: ^4.8.4
valtio: ^1.7.4
zustand: ^4.1.2
dependencies:
spitroast: 1.4.2
valtio: 1.7.4
devDependencies:
'@react-native-async-storage/async-storage': 1.17.10
'@types/react': 18.0.21
'@types/react-native': 0.70.5
esbuild: 0.15.11
@ -49,6 +53,17 @@ packages:
dev: true
optional: true
/@react-native-async-storage/async-storage/1.17.10:
resolution: {integrity: sha512-KrR021BmBLsA0TT1AAsfH16bHYy0MSbhdAeBAqpriak3GS1T2alFcdTUvn13p0ZW6FKRD6Bd3ryU2zhU/IYYJQ==}
peerDependencies:
react-native: ^0.0.0-0 || 0.60 - 0.70 || 1000.0.0
peerDependenciesMeta:
react-native:
optional: true
dependencies:
merge-options: 3.0.4
dev: true
/@types/prop-types/15.7.5:
resolution: {integrity: sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==}
dev: true
@ -289,6 +304,22 @@ packages:
esbuild-windows-arm64: 0.15.11
dev: true
/is-plain-obj/2.1.0:
resolution: {integrity: sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==}
engines: {node: '>=8'}
dev: true
/merge-options/3.0.4:
resolution: {integrity: sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==}
engines: {node: '>=10'}
dependencies:
is-plain-obj: 2.1.0
dev: true
/proxy-compare/2.3.0:
resolution: {integrity: sha512-c3L2CcAi7f7pvlD0D7xsF+2CQIW8C3HaYx2Pfgq8eA4HAl3GAH6/dVYsyBbYF/0XJs2ziGLrzmz5fmzPm6A0pQ==}
dev: false
/redux/4.2.0:
resolution: {integrity: sha512-oSBmcKKIuIR4ME29/AeNUnl5L+hvBq7OaJWzaptTQJAntaPvxIJqfnjbaEiCzzaIz+XmVILfqAM3Ob0aXLPfjA==}
dependencies:
@ -316,7 +347,34 @@ packages:
peerDependenciesMeta:
react:
optional: true
dev: true
/valtio/1.7.4:
resolution: {integrity: sha512-x8N7I7hfIlRHQyRe8cx3QJsEYdzMHb12HYUGIDjPruEwLrMpegvS8iZDk4PZ/i8HgeiOPF7Qr78Ke3HA1CGu9A==}
engines: {node: '>=12.7.0'}
peerDependencies:
'@babel/helper-module-imports': '>=7.12'
'@babel/types': '>=7.13'
aslemammad-vite-plugin-macro: '>=1.0.0-alpha.1'
babel-plugin-macros: '>=3.0'
react: '>=16.8'
vite: '>=2.8.6'
peerDependenciesMeta:
'@babel/helper-module-imports':
optional: true
'@babel/types':
optional: true
aslemammad-vite-plugin-macro:
optional: true
babel-plugin-macros:
optional: true
react:
optional: true
vite:
optional: true
dependencies:
proxy-compare: 2.3.0
use-sync-external-store: 1.2.0
dev: false
/zustand/4.1.2:
resolution: {integrity: sha512-gcRaKchcxFPbImrBb/BKgujOhHhik9YhVpIeP87ETT7uokEe2Szu7KkuZ9ghjtD+/KKkcrRNktR2AiLXPIbKIQ==}

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

@ -8,3 +8,6 @@ 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");
// 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} /> )}