[Cleanup] Lots of tidying, fill out API object

This commit is contained in:
Beef 2022-10-28 18:50:40 +01:00
parent c98b2c7e25
commit 7610a97b78
11 changed files with 52 additions and 48 deletions

28
src/def.d.ts vendored
View file

@ -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;
}

View file

@ -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;

View file

@ -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();
}

View file

@ -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.");
}
}

View file

@ -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 {};
}

View file

@ -1,4 +1,3 @@
import { findByProps } from "@metro/filters";
// TODO: Type individual props
export const Forms = findByProps("FormSection");

View file

@ -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 (
<FormRow
label={`${asset.name} - ${asset.id}`}
trailing={() => <RN.Image source={asset.id} style={styles.asset} />}
onPress={() => {
copyText(asset.name);
showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link"))
}}
/>
)
}

View file

@ -25,7 +25,7 @@ export default function AssetDisplay({ asset }: AssetDisplayProps) {
trailing={() => <RN.Image source={asset.id} style={styles.asset} />}
onPress={() => {
copyText(asset.name);
showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link"))
showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link"));
}}
/>
)

View file

@ -20,7 +20,7 @@ export default function Version({ label, version, icon }: VersionProps) {
trailing={() => <FormText>{version}</FormText>}
onPress={() => {
copyText(`${label} - ${version}`);
showToast("Copied version to clipboard.", getAssetIDByName("toast_copy_link"))
showToast("Copied version to clipboard.", getAssetIDByName("toast_copy_link"));
}}
/>
)

View file

@ -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={() => <FormRow.Icon source={getAssetIDByName("copy")} />}
trailing={FormRow.Arrow}
onPress={() => connectToDebugWS(debuggerUrl)}
onPress={() => connectToDebugger(debuggerUrl)}
/>
<FormRow
label="Reload Discord"

View file

@ -3,6 +3,6 @@ import { toasts } from "@metro/common";
export function showToast(content: string, asset: number) {
return toasts.open({
content: content,
source: asset
source: asset,
});
}