diff --git a/src/def.d.ts b/src/def.d.ts index bdf9be6..a3b489f 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -50,22 +50,42 @@ interface VendettaObject { findByDisplayName: (name: string, defaultExp: boolean) => any; findByDisplayNameAll: (name: string, defaultExp: boolean) => any[]; common: { - constants: Object; - channels: Object; - i18n: Object; + constants: PropIntellisense<"API_HOST">; + channels: PropIntellisense<"getVoiceChannelId">; + i18n: PropIntellisense<"Messages">; + url: PropIntellisense<"openURL">; + toasts: PropIntellisense<"open" | "close">; React: typeof _React; ReactNative: typeof _RN; AsyncStorage: typeof _AsyncStorage; }; }; + constants: { + DISCORD_SERVER: string; + GITHUB: string; + }; + utils: { + copyText: (content: string) => void; + findInReactTree: (tree: { [key: string]: any }, filter: SearchFilter) => void; + findInTree: (tree: { [key: string]: any }, filter: SearchFilter, options: FindInTreeOptions) => any; + }; + debug: { + connectToDebugger: (url: string) => void; + } ui: { + components: { + Forms: PropIntellisense<"FormSection">; + } + toasts: { + showToast: (content: string, asset: number) => void; + }; assets: { all: Assets; find: (filter: (a: any) => void) => Asset | null | undefined; getAssetByName: (name: string) => Asset; getAssetByID: (id: number) => Asset; getAssetIDByName: (name: string) => number; - } + }; }; logger: Logger; } diff --git a/src/index.ts b/src/index.ts index d84b1a4..d8c4a1c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,17 @@ import patcher from "@lib/patcher"; import logger from "@lib/logger"; +import copyText from "@utils/copyText"; +import findInReactTree from "@utils/findInReactTree"; +import findInTree from "@utils/findInTree"; +import * as constants from "@lib/constants"; import * as metro from "@metro/filters"; import * as common from "@metro/common"; +import * as components from "@ui/components"; +import * as toasts from "@ui/toasts"; import { all, find, getAssetByID, getAssetByName, getAssetIDByName } from "@ui/assets"; import patchAssets from "@ui/assets"; import initSettings from "@ui/settings"; -import { patchLogHook } from "@lib/debug"; +import { connectToDebugger, patchLogHook } from "@lib/debug"; console.log("Hello from Vendetta!"); @@ -19,9 +25,19 @@ async function init() { window.vendetta = { patcher: patcher, - metro: { ...metro, common: common }, - logger: logger, + metro: { ...metro, common: { ...common } }, + constants: { ...constants }, + utils: { + copyText: copyText, + findInReactTree: findInReactTree, + findInTree: findInTree, + }, + debug: { + connectToDebugger: connectToDebugger, + }, ui: { + components: { ...components }, + toasts: { ...toasts }, assets: { all: all, find: find, @@ -30,6 +46,7 @@ async function init() { getAssetIDByName: getAssetIDByName, }, }, + logger: logger, }; } catch (e: Error | any) { erroredOnLoad = true; diff --git a/src/lib/debug.ts b/src/lib/debug.ts index 304df3b..a8cfa72 100644 --- a/src/lib/debug.ts +++ b/src/lib/debug.ts @@ -6,7 +6,7 @@ export let socket: WebSocket; let iLoveBundlers = eval; -export function connectToDebugWS(url: string) { +export function connectToDebugger(url: string) { if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) { socket.close(); } diff --git a/src/lib/utils/copyText.ts b/src/lib/utils/copyText.ts index e13354c..1dc3d79 100644 --- a/src/lib/utils/copyText.ts +++ b/src/lib/utils/copyText.ts @@ -6,6 +6,6 @@ export default function copyText(content: string) { try { clipboard.setString(content); } catch (e) { - throw new Error("Failed to set clipboard content.") + throw new Error("Failed to set clipboard content."); } } \ No newline at end of file diff --git a/src/ui/assets.ts b/src/ui/assets.ts index db3b092..908e93c 100644 --- a/src/ui/assets.ts +++ b/src/ui/assets.ts @@ -17,7 +17,7 @@ export default function patchAssets() { const asset = assetsModule.getAssetByID(id); if (!asset) break; if (all[asset.name]) continue; - all[asset.name] = { ...asset, id: id } + all[asset.name] = { ...asset, id: id }; }; } catch {}; } diff --git a/src/ui/components.ts b/src/ui/components.ts index eb64fbb..0acad0a 100644 --- a/src/ui/components.ts +++ b/src/ui/components.ts @@ -1,4 +1,3 @@ import { findByProps } from "@metro/filters"; -// TODO: Type individual props export const Forms = findByProps("FormSection"); \ No newline at end of file diff --git a/src/ui/settings/AssetDisplay.tsx b/src/ui/settings/AssetDisplay.tsx deleted file mode 100644 index 51b9ad1..0000000 --- a/src/ui/settings/AssetDisplay.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { Asset } from "@types"; -import { React, ReactNative as RN } from "@metro/common"; -import { showToast } from "@ui/toasts"; -import { getAssetIDByName } from "@ui/assets"; -import { Forms } from "@ui/components"; -import copyText from "@lib/utils/copyText"; - -interface AssetDisplayProps { - asset: Asset; -} - -const { FormRow } = Forms; - -const styles = RN.StyleSheet.create({ - asset: { - width: 32, - height: 32, - } -}); - -export default function AssetDisplay({ asset }: AssetDisplayProps) { - return ( - } - onPress={() => { - copyText(asset.name); - showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link")) - }} - /> - ) -} \ No newline at end of file diff --git a/src/ui/settings/components/AssetDisplay.tsx b/src/ui/settings/components/AssetDisplay.tsx index 51b9ad1..c1f25b9 100644 --- a/src/ui/settings/components/AssetDisplay.tsx +++ b/src/ui/settings/components/AssetDisplay.tsx @@ -25,7 +25,7 @@ export default function AssetDisplay({ asset }: AssetDisplayProps) { trailing={() => } onPress={() => { copyText(asset.name); - showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link")) + showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link")); }} /> ) diff --git a/src/ui/settings/components/Version.tsx b/src/ui/settings/components/Version.tsx index 3c537e0..cd57b94 100644 --- a/src/ui/settings/components/Version.tsx +++ b/src/ui/settings/components/Version.tsx @@ -20,7 +20,7 @@ export default function Version({ label, version, icon }: VersionProps) { trailing={() => {version}} onPress={() => { copyText(`${label} - ${version}`); - showToast("Copied version to clipboard.", getAssetIDByName("toast_copy_link")) + showToast("Copied version to clipboard.", getAssetIDByName("toast_copy_link")); }} /> ) diff --git a/src/ui/settings/pages/General.tsx b/src/ui/settings/pages/General.tsx index 9fa3b25..2668e4a 100644 --- a/src/ui/settings/pages/General.tsx +++ b/src/ui/settings/pages/General.tsx @@ -1,6 +1,6 @@ import { React, ReactNative as RN, url } from "@metro/common"; import { DISCORD_SERVER, GITHUB } from "@lib/constants"; -import { connectToDebugWS } from "@lib/debug"; +import { connectToDebugger } from "@lib/debug"; import { getAssetIDByName } from "@ui/assets"; import { Forms } from "@ui/components"; import Version from "@ui/settings/components/Version"; @@ -62,7 +62,7 @@ export default function General() { label="Connect to debug websocket" leading={() => } trailing={FormRow.Arrow} - onPress={() => connectToDebugWS(debuggerUrl)} + onPress={() => connectToDebugger(debuggerUrl)} />