diff --git a/src/lib/debug.ts b/src/lib/debug.ts index d0c853a..304df3b 100644 --- a/src/lib/debug.ts +++ b/src/lib/debug.ts @@ -1,4 +1,6 @@ import { after } from "@lib/patcher"; +import { getAssetIDByName } from "@ui/assets"; +import { showToast } from "@ui/toasts"; import logger from "@lib/logger"; export let socket: WebSocket; @@ -9,8 +11,15 @@ export function connectToDebugWS(url: string) { socket.close(); } + if (url === "") { + showToast("Invalid debugger URL!", getAssetIDByName("Small")); + return; + } + socket = new WebSocket(`ws://${url}`); + socket.addEventListener("open", () => showToast("Connected to debugger.", getAssetIDByName("Check"))); + socket.addEventListener("message", (message: any) => { try { iLoveBundlers(message.data); @@ -18,6 +27,11 @@ export function connectToDebugWS(url: string) { console.error(e); } }); + + socket.addEventListener("error", (err: any) => { + console.log(`Debugger error: ${err.message}`); + showToast("An error occurred with the debugger connection!", getAssetIDByName("Small")); + }); } export function patchLogHook() { diff --git a/src/lib/metro/common.ts b/src/lib/metro/common.ts index 2b9c3ec..7307e4d 100644 --- a/src/lib/metro/common.ts +++ b/src/lib/metro/common.ts @@ -1,9 +1,10 @@ -import { findByProps } from "@metro/filters"; +import { find, findByProps } from "@metro/filters"; // Discord export const constants = findByProps("API_HOST"); export const channels = findByProps("getVoiceChannelId"); export const i18n = findByProps("Messages"); +export const toasts = find(m => m.open && m.close && !m.startDrag && !m.init && !m.openReplay && !m.setAlwaysOnTop); // React export const React = findByProps("createElement") as typeof import("react"); diff --git a/src/ui/toasts.ts b/src/ui/toasts.ts new file mode 100644 index 0000000..597719d --- /dev/null +++ b/src/ui/toasts.ts @@ -0,0 +1,8 @@ +import { toasts } from "@metro/common"; + +export function showToast(content: string, asset: number) { + return toasts.open({ + content: content, + source: asset + }); +} \ No newline at end of file