[Cleanup] Lots of tidying, fill out API object
This commit is contained in:
parent
c98b2c7e25
commit
7610a97b78
11 changed files with 52 additions and 48 deletions
28
src/def.d.ts
vendored
28
src/def.d.ts
vendored
|
@ -50,22 +50,42 @@ interface VendettaObject {
|
||||||
findByDisplayName: (name: string, defaultExp: boolean) => any;
|
findByDisplayName: (name: string, defaultExp: boolean) => any;
|
||||||
findByDisplayNameAll: (name: string, defaultExp: boolean) => any[];
|
findByDisplayNameAll: (name: string, defaultExp: boolean) => any[];
|
||||||
common: {
|
common: {
|
||||||
constants: Object;
|
constants: PropIntellisense<"API_HOST">;
|
||||||
channels: Object;
|
channels: PropIntellisense<"getVoiceChannelId">;
|
||||||
i18n: Object;
|
i18n: PropIntellisense<"Messages">;
|
||||||
|
url: PropIntellisense<"openURL">;
|
||||||
|
toasts: PropIntellisense<"open" | "close">;
|
||||||
React: typeof _React;
|
React: typeof _React;
|
||||||
ReactNative: typeof _RN;
|
ReactNative: typeof _RN;
|
||||||
AsyncStorage: typeof _AsyncStorage;
|
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: {
|
ui: {
|
||||||
|
components: {
|
||||||
|
Forms: PropIntellisense<"FormSection">;
|
||||||
|
}
|
||||||
|
toasts: {
|
||||||
|
showToast: (content: string, asset: number) => void;
|
||||||
|
};
|
||||||
assets: {
|
assets: {
|
||||||
all: Assets;
|
all: Assets;
|
||||||
find: (filter: (a: any) => void) => Asset | null | undefined;
|
find: (filter: (a: any) => void) => Asset | null | undefined;
|
||||||
getAssetByName: (name: string) => Asset;
|
getAssetByName: (name: string) => Asset;
|
||||||
getAssetByID: (id: number) => Asset;
|
getAssetByID: (id: number) => Asset;
|
||||||
getAssetIDByName: (name: string) => number;
|
getAssetIDByName: (name: string) => number;
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
}
|
}
|
||||||
|
|
23
src/index.ts
23
src/index.ts
|
@ -1,11 +1,17 @@
|
||||||
import patcher from "@lib/patcher";
|
import patcher from "@lib/patcher";
|
||||||
import logger from "@lib/logger";
|
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 metro from "@metro/filters";
|
||||||
import * as common from "@metro/common";
|
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 { all, find, getAssetByID, getAssetByName, getAssetIDByName } from "@ui/assets";
|
||||||
import patchAssets from "@ui/assets";
|
import patchAssets from "@ui/assets";
|
||||||
import initSettings from "@ui/settings";
|
import initSettings from "@ui/settings";
|
||||||
import { patchLogHook } from "@lib/debug";
|
import { connectToDebugger, patchLogHook } from "@lib/debug";
|
||||||
|
|
||||||
console.log("Hello from Vendetta!");
|
console.log("Hello from Vendetta!");
|
||||||
|
|
||||||
|
@ -19,9 +25,19 @@ async function init() {
|
||||||
|
|
||||||
window.vendetta = {
|
window.vendetta = {
|
||||||
patcher: patcher,
|
patcher: patcher,
|
||||||
metro: { ...metro, common: common },
|
metro: { ...metro, common: { ...common } },
|
||||||
logger: logger,
|
constants: { ...constants },
|
||||||
|
utils: {
|
||||||
|
copyText: copyText,
|
||||||
|
findInReactTree: findInReactTree,
|
||||||
|
findInTree: findInTree,
|
||||||
|
},
|
||||||
|
debug: {
|
||||||
|
connectToDebugger: connectToDebugger,
|
||||||
|
},
|
||||||
ui: {
|
ui: {
|
||||||
|
components: { ...components },
|
||||||
|
toasts: { ...toasts },
|
||||||
assets: {
|
assets: {
|
||||||
all: all,
|
all: all,
|
||||||
find: find,
|
find: find,
|
||||||
|
@ -30,6 +46,7 @@ async function init() {
|
||||||
getAssetIDByName: getAssetIDByName,
|
getAssetIDByName: getAssetIDByName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
logger: logger,
|
||||||
};
|
};
|
||||||
} catch (e: Error | any) {
|
} catch (e: Error | any) {
|
||||||
erroredOnLoad = true;
|
erroredOnLoad = true;
|
||||||
|
|
|
@ -6,7 +6,7 @@ export let socket: WebSocket;
|
||||||
|
|
||||||
let iLoveBundlers = eval;
|
let iLoveBundlers = eval;
|
||||||
|
|
||||||
export function connectToDebugWS(url: string) {
|
export function connectToDebugger(url: string) {
|
||||||
if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) {
|
if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) {
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,6 @@ export default function copyText(content: string) {
|
||||||
try {
|
try {
|
||||||
clipboard.setString(content);
|
clipboard.setString(content);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error("Failed to set clipboard content.")
|
throw new Error("Failed to set clipboard content.");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@ export default function patchAssets() {
|
||||||
const asset = assetsModule.getAssetByID(id);
|
const asset = assetsModule.getAssetByID(id);
|
||||||
if (!asset) break;
|
if (!asset) break;
|
||||||
if (all[asset.name]) continue;
|
if (all[asset.name]) continue;
|
||||||
all[asset.name] = { ...asset, id: id }
|
all[asset.name] = { ...asset, id: id };
|
||||||
};
|
};
|
||||||
} catch {};
|
} catch {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { findByProps } from "@metro/filters";
|
import { findByProps } from "@metro/filters";
|
||||||
|
|
||||||
// TODO: Type individual props
|
|
||||||
export const Forms = findByProps("FormSection");
|
export const Forms = findByProps("FormSection");
|
|
@ -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"))
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -25,7 +25,7 @@ export default function AssetDisplay({ asset }: AssetDisplayProps) {
|
||||||
trailing={() => <RN.Image source={asset.id} style={styles.asset} />}
|
trailing={() => <RN.Image source={asset.id} style={styles.asset} />}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
copyText(asset.name);
|
copyText(asset.name);
|
||||||
showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link"))
|
showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link"));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default function Version({ label, version, icon }: VersionProps) {
|
||||||
trailing={() => <FormText>{version}</FormText>}
|
trailing={() => <FormText>{version}</FormText>}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
copyText(`${label} - ${version}`);
|
copyText(`${label} - ${version}`);
|
||||||
showToast("Copied version to clipboard.", getAssetIDByName("toast_copy_link"))
|
showToast("Copied version to clipboard.", getAssetIDByName("toast_copy_link"));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { React, ReactNative as RN, url } from "@metro/common";
|
import { React, ReactNative as RN, url } from "@metro/common";
|
||||||
import { DISCORD_SERVER, GITHUB } from "@lib/constants";
|
import { DISCORD_SERVER, GITHUB } from "@lib/constants";
|
||||||
import { connectToDebugWS } from "@lib/debug";
|
import { connectToDebugger } from "@lib/debug";
|
||||||
import { getAssetIDByName } from "@ui/assets";
|
import { getAssetIDByName } from "@ui/assets";
|
||||||
import { Forms } from "@ui/components";
|
import { Forms } from "@ui/components";
|
||||||
import Version from "@ui/settings/components/Version";
|
import Version from "@ui/settings/components/Version";
|
||||||
|
@ -62,7 +62,7 @@ export default function General() {
|
||||||
label="Connect to debug websocket"
|
label="Connect to debug websocket"
|
||||||
leading={() => <FormRow.Icon source={getAssetIDByName("copy")} />}
|
leading={() => <FormRow.Icon source={getAssetIDByName("copy")} />}
|
||||||
trailing={FormRow.Arrow}
|
trailing={FormRow.Arrow}
|
||||||
onPress={() => connectToDebugWS(debuggerUrl)}
|
onPress={() => connectToDebugger(debuggerUrl)}
|
||||||
/>
|
/>
|
||||||
<FormRow
|
<FormRow
|
||||||
label="Reload Discord"
|
label="Reload Discord"
|
||||||
|
|
|
@ -3,6 +3,6 @@ import { toasts } from "@metro/common";
|
||||||
export function showToast(content: string, asset: number) {
|
export function showToast(content: string, asset: number) {
|
||||||
return toasts.open({
|
return toasts.open({
|
||||||
content: content,
|
content: content,
|
||||||
source: asset
|
source: asset,
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in a new issue