[Global] Code cleanup pass
This commit is contained in:
parent
69c2544b99
commit
7d36903b2c
19 changed files with 47 additions and 73 deletions
8
src/def.d.ts
vendored
8
src/def.d.ts
vendored
|
@ -46,7 +46,7 @@ interface Asset {
|
||||||
id: number;
|
id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare enum ButtonColors {
|
export enum ButtonColors {
|
||||||
BRAND = "brand",
|
BRAND = "brand",
|
||||||
RED = "red",
|
RED = "red",
|
||||||
GREEN = "green",
|
GREEN = "green",
|
||||||
|
@ -121,7 +121,7 @@ interface ApplicationCommand {
|
||||||
type: ApplicationCommandType;
|
type: ApplicationCommandType;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare enum ApplicationCommandInputType {
|
export enum ApplicationCommandInputType {
|
||||||
BUILT_IN,
|
BUILT_IN,
|
||||||
BUILT_IN_TEXT,
|
BUILT_IN_TEXT,
|
||||||
BUILT_IN_INTEGRATION,
|
BUILT_IN_INTEGRATION,
|
||||||
|
@ -138,7 +138,7 @@ interface ApplicationCommandOption {
|
||||||
displayDescription: string;
|
displayDescription: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare enum ApplicationCommandOptionType {
|
export enum ApplicationCommandOptionType {
|
||||||
SUB_COMMAND = 1,
|
SUB_COMMAND = 1,
|
||||||
SUB_COMMAND_GROUP,
|
SUB_COMMAND_GROUP,
|
||||||
STRING,
|
STRING,
|
||||||
|
@ -152,7 +152,7 @@ declare enum ApplicationCommandOptionType {
|
||||||
ATTACHMENT,
|
ATTACHMENT,
|
||||||
}
|
}
|
||||||
|
|
||||||
declare enum ApplicationCommandType {
|
export enum ApplicationCommandType {
|
||||||
CHAT = 1,
|
CHAT = 1,
|
||||||
USER,
|
USER,
|
||||||
MESSAGE,
|
MESSAGE,
|
||||||
|
|
|
@ -7,11 +7,9 @@ import logger from "@lib/logger";
|
||||||
export let socket: WebSocket;
|
export let socket: WebSocket;
|
||||||
|
|
||||||
export function connectToDebugger(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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url === "") {
|
if (!url) {
|
||||||
showToast("Invalid debugger URL!", getAssetIDByName("Small"));
|
showToast("Invalid debugger URL!", getAssetIDByName("Small"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +17,6 @@ export function connectToDebugger(url: string) {
|
||||||
socket = new WebSocket(`ws://${url}`);
|
socket = new WebSocket(`ws://${url}`);
|
||||||
|
|
||||||
socket.addEventListener("open", () => showToast("Connected to debugger.", getAssetIDByName("Check")));
|
socket.addEventListener("open", () => showToast("Connected to debugger.", getAssetIDByName("Check")));
|
||||||
|
|
||||||
socket.addEventListener("message", (message: any) => {
|
socket.addEventListener("message", (message: any) => {
|
||||||
try {
|
try {
|
||||||
(0, eval)(message.data);
|
(0, eval)(message.data);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { Emitter, EmitterEvent, EmitterListener, EmitterListenerData, EmitterListeners } from "@types";
|
import { Emitter, EmitterEvent, EmitterListener, EmitterListenerData, EmitterListeners } from "@types";
|
||||||
|
|
||||||
export const Events = Object.freeze({
|
export enum Events {
|
||||||
GET: "GET",
|
GET = "GET",
|
||||||
SET: "SET",
|
SET = "SET",
|
||||||
DEL: "DEL",
|
DEL = "DEL",
|
||||||
});
|
};
|
||||||
|
|
||||||
export default function createEmitter(): Emitter {
|
export default function createEmitter(): Emitter {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
const basicFind = (prop: string) => Object.values(window.modules).find(m => m?.publicModule.exports?.[prop])?.publicModule?.exports;
|
const basicFind = (prop: string) => Object.values(window.modules).find(m => m?.publicModule.exports?.[prop])?.publicModule?.exports;
|
||||||
|
|
||||||
// Hoist React on window
|
// Hoist React on window
|
||||||
window.React = basicFind("createElement") as typeof import("react");;
|
window.React = basicFind("createElement") as typeof import("react");
|
||||||
|
|
||||||
// Export ReactNative
|
// Export ReactNative
|
||||||
export const ReactNative = basicFind("Text") as typeof import("react-native");
|
export const ReactNative = basicFind("AppRegistry") as typeof import("react-native");
|
||||||
|
|
||||||
// Export Discord's constants
|
// Export Discord's constants
|
||||||
export const constants = basicFind("AbortCodes");
|
export const constants = basicFind("AbortCodes");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
|
|
||||||
import { LoaderConfig, Settings } from "@types";
|
import { LoaderConfig, Settings } from "@types";
|
||||||
|
import { createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
|
||||||
|
|
||||||
export default wrapSync(createStorage<Settings>(createMMKVBackend("VENDETTA_SETTINGS")));
|
export default wrapSync(createStorage<Settings>(createMMKVBackend("VENDETTA_SETTINGS")));
|
||||||
export const loaderConfig = wrapSync(createStorage<LoaderConfig>(createFileBackend("vendetta_loader.json")));
|
export const loaderConfig = wrapSync(createStorage<LoaderConfig>(createFileBackend("vendetta_loader.json")));
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { clipboard } from "@metro/common";
|
import { clipboard } from "@metro/common";
|
||||||
|
|
||||||
|
// TODO: Remove/deprecate this, the clipboard module works the same way.
|
||||||
|
|
||||||
export default function copyText(content: string) {
|
export default function copyText(content: string) {
|
||||||
try {
|
try {
|
||||||
clipboard.setString(content);
|
clipboard.setString(content);
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
// https://stackoverflow.com/a/68339174
|
// https://stackoverflow.com/a/68339174
|
||||||
|
|
||||||
export default function unfreeze(obj: object) {
|
export default function unfreeze(obj: object) {
|
||||||
if (Object.isFrozen(obj)) {
|
if (Object.isFrozen(obj)) return Object.assign({}, obj);
|
||||||
return Object.assign({}, obj);
|
|
||||||
}
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@ import InputAlert from "@ui/components/InputAlert";
|
||||||
|
|
||||||
const Alerts = findByProps("openLazy", "close");
|
const Alerts = findByProps("openLazy", "close");
|
||||||
|
|
||||||
interface InternalConfirmationAlertOptions extends Omit<ConfirmationAlertOptions, 'content'> {
|
interface InternalConfirmationAlertOptions extends Omit<ConfirmationAlertOptions, "content"> {
|
||||||
content: string | JSX.Element | JSX.Element[] | undefined;
|
content: string | JSX.Element | JSX.Element[] | undefined;
|
||||||
body: string | undefined;
|
body: string | undefined;
|
||||||
children: JSX.Element | JSX.Element[];
|
children: JSX.Element | JSX.Element[];
|
||||||
|
@ -20,18 +20,11 @@ export function showConfirmationAlert(options: ConfirmationAlertOptions) {
|
||||||
};
|
};
|
||||||
|
|
||||||
delete internalOptions.content;
|
delete internalOptions.content;
|
||||||
|
|
||||||
return Alerts.show(internalOptions);
|
return Alerts.show(internalOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function showCustomAlert(component: React.ComponentType, props: any) {
|
export const showCustomAlert = (component: React.ComponentType, props: any) => Alerts.openLazy({
|
||||||
Alerts.openLazy({
|
importer: async () => () => React.createElement(component, props),
|
||||||
importer: async function () {
|
});
|
||||||
return () => React.createElement(component, props);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export function showInputAlert(options: InputAlertProps) {
|
export const showInputAlert = (options: InputAlertProps) => showCustomAlert(InputAlert as React.ComponentType, options);
|
||||||
showCustomAlert(InputAlert as React.ComponentType, options);
|
|
||||||
};
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Asset, Indexable } from "@types";
|
import { Asset, Indexable } from "@types";
|
||||||
import { after } from "@lib/patcher";
|
|
||||||
import { assets } from "@metro/common";
|
import { assets } from "@metro/common";
|
||||||
|
import { after } from "@lib/patcher";
|
||||||
|
|
||||||
export const all: Indexable<Asset> = {};
|
export const all: Indexable<Asset> = {};
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,13 @@ import { constants } from "@metro/hoist";
|
||||||
//* In 167.1, most if not all traces of the old color modules were removed.
|
//* In 167.1, most if not all traces of the old color modules were removed.
|
||||||
//* In 168.6, Discord restructured EVERYTHING again. SemanticColor on this module no longer works when passed to a stylesheet. We must now use what you see below.
|
//* In 168.6, Discord restructured EVERYTHING again. SemanticColor on this module no longer works when passed to a stylesheet. We must now use what you see below.
|
||||||
//? However, this is not all bad. The changes made in 168.6 do allow for better native-less theming.
|
//? However, this is not all bad. The changes made in 168.6 do allow for better native-less theming.
|
||||||
const colorModule = findByProps("SemanticColor");
|
const colorModule = findByProps("colors", "meta");
|
||||||
|
|
||||||
//* For both below, SemanticColor and RawColor are seemingly not used. Once again, what are Discord doing?
|
//* For both below, SemanticColor and RawColor are seemingly not used. Once again, what are Discord doing?
|
||||||
|
|
||||||
//? SemanticColor and default.colors are effectively ThemeColorMap
|
//? SemanticColor and default.colors are effectively ThemeColorMap
|
||||||
export const semanticColors = (constants.ThemeColorMap ?? colorModule?.default?.colors ?? colorModule?.SemanticColor);
|
export const semanticColors = (constants.ThemeColorMap ?? colorModule?.colors);
|
||||||
|
|
||||||
//? RawColor and default.unsafe_rawColors are effectively Colors
|
//? RawColor and default.unsafe_rawColors are effectively Colors
|
||||||
//* Note that constants.Colors does still appear to exist on newer versions despite Discord not internally using it - what the fuck?
|
//* Note that constants.Colors does still appear to exist on newer versions despite Discord not internally using it - what the fuck?
|
||||||
export const rawColors = (constants.Colors ?? colorModule?.default?.unsafe_rawColors ?? colorModule?.RawColor);
|
export const rawColors = (constants.Colors ?? colorModule?.unsafe_rawColors);
|
|
@ -3,7 +3,6 @@ import { Forms, Alert } from "@ui/components";
|
||||||
import { InputAlertProps } from "@types";
|
import { InputAlertProps } from "@types";
|
||||||
|
|
||||||
const { FormInput } = Forms;
|
const { FormInput } = Forms;
|
||||||
|
|
||||||
const Alerts = findByProps("openLazy", "close");
|
const Alerts = findByProps("openLazy", "close");
|
||||||
|
|
||||||
export default function InputAlert({ title, confirmText, confirmColor, onConfirm, cancelText, placeholder, initialValue = "" }: InputAlertProps) {
|
export default function InputAlert({ title, confirmText, confirmColor, onConfirm, cancelText, placeholder, initialValue = "" }: InputAlertProps) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Based on https://github.com/Aliucord/AliucordRN/blob/main/src/ui/patchTheme.ts
|
// Based on https://github.com/Aliucord/AliucordRN/blob/main/src/ui/patchTheme.ts
|
||||||
// Literally could not figure this out, many thanks
|
// Literally could not figure this out, many thanks
|
||||||
|
|
||||||
import { findByProps, findByStoreName } from "@metro/filters";
|
|
||||||
import { FluxDispatcher } from "@metro/common";
|
import { FluxDispatcher } from "@metro/common";
|
||||||
|
import { findByProps, findByStoreName } from "@metro/filters";
|
||||||
import logger from "@lib/logger";
|
import logger from "@lib/logger";
|
||||||
|
|
||||||
// TODO: Move these to common modules?
|
// TODO: Move these to common modules?
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { HTTP_REGEX } from "@/lib/constants";
|
|
||||||
import { semanticColors } from "@ui/color";
|
|
||||||
import { installPlugin } from "@lib/plugins";
|
|
||||||
import { clipboard, stylesheet } from "@metro/common";
|
import { clipboard, stylesheet } from "@metro/common";
|
||||||
|
import { HTTP_REGEX } from "@lib/constants";
|
||||||
|
import { installPlugin } from "@lib/plugins";
|
||||||
import { showInputAlert } from "@ui/alerts";
|
import { showInputAlert } from "@ui/alerts";
|
||||||
import { getAssetIDByName } from "@ui/assets";
|
import { getAssetIDByName } from "@ui/assets";
|
||||||
|
import { semanticColors } from "@ui/color";
|
||||||
import { General } from "@ui/components";
|
import { General } from "@ui/components";
|
||||||
|
|
||||||
const { TouchableOpacity, Image } = General;
|
const { TouchableOpacity, Image } = General;
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
|
import { ButtonColors, Plugin } from "@types";
|
||||||
import { ReactNative as RN, stylesheet, NavigationNative } from "@metro/common";
|
import { ReactNative as RN, stylesheet, NavigationNative } from "@metro/common";
|
||||||
import { findByProps } from "@metro/filters";
|
|
||||||
import { Forms, General } from "@ui/components";
|
import { Forms, General } from "@ui/components";
|
||||||
import { Plugin } from "@types";
|
|
||||||
import { getAssetIDByName } from "@ui/assets";
|
import { getAssetIDByName } from "@ui/assets";
|
||||||
import { showToast } from "@ui/toasts";
|
import { showToast } from "@ui/toasts";
|
||||||
|
import { showConfirmationAlert } from "@ui/alerts";
|
||||||
import { semanticColors } from "@ui/color";
|
import { semanticColors } from "@ui/color";
|
||||||
import { removePlugin, startPlugin, stopPlugin, getSettings } from "@lib/plugins";
|
import { removePlugin, startPlugin, stopPlugin, getSettings } from "@lib/plugins";
|
||||||
import copyText from "@utils/copyText";
|
import copyText from "@utils/copyText";
|
||||||
|
|
||||||
// TODO: Replace with our eventual dialog API
|
|
||||||
const Dialog = findByProps("show", "openLazy", "close");
|
|
||||||
|
|
||||||
const { FormRow, FormSwitch } = Forms;
|
const { FormRow, FormSwitch } = Forms;
|
||||||
const { TouchableOpacity, Image } = General;
|
const { TouchableOpacity, Image } = General;
|
||||||
|
|
||||||
|
@ -79,12 +76,12 @@ export default function PluginCard({ plugin, index }: PluginCardProps) {
|
||||||
trailing={
|
trailing={
|
||||||
<RN.View style={styles.actions}>
|
<RN.View style={styles.actions}>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => Dialog.show({
|
onPress={() => showConfirmationAlert({
|
||||||
title: "Wait!",
|
title: "Wait!",
|
||||||
body: `Are you sure you wish to delete ${plugin.manifest.name}?`,
|
content: `Are you sure you wish to delete ${plugin.manifest.name}?`,
|
||||||
confirmText: "Delete",
|
confirmText: "Delete",
|
||||||
cancelText: "Cancel",
|
cancelText: "Cancel",
|
||||||
confirmColor: "red",
|
confirmColor: ButtonColors.RED,
|
||||||
onConfirm: () => {
|
onConfirm: () => {
|
||||||
try {
|
try {
|
||||||
removePlugin(plugin.id);
|
removePlugin(plugin.id);
|
||||||
|
|
|
@ -4,11 +4,11 @@ import { after } from "@lib/patcher";
|
||||||
import findInReactTree from "@utils/findInReactTree";
|
import findInReactTree from "@utils/findInReactTree";
|
||||||
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
||||||
import SettingsSection from "@ui/settings/components/SettingsSection";
|
import SettingsSection from "@ui/settings/components/SettingsSection";
|
||||||
|
import InstallPluginButton from "@ui/settings/components/InstallPluginButton";
|
||||||
import General from "@ui/settings/pages/General";
|
import General from "@ui/settings/pages/General";
|
||||||
import Plugins from "@ui/settings/pages/Plugins";
|
import Plugins from "@ui/settings/pages/Plugins";
|
||||||
import Developer from "@ui/settings/pages/Developer";
|
import Developer from "@ui/settings/pages/Developer";
|
||||||
import AssetBrowser from "@ui/settings/pages/AssetBrowser";
|
import AssetBrowser from "@ui/settings/pages/AssetBrowser";
|
||||||
import InstallPluginButton from "@ui/settings/components/InstallPluginButton";
|
|
||||||
|
|
||||||
const screensModule = findByDisplayName("getScreens", false);
|
const screensModule = findByDisplayName("getScreens", false);
|
||||||
const settingsModule = findByDisplayName("UserSettingsOverviewWrapper", false);
|
const settingsModule = findByDisplayName("UserSettingsOverviewWrapper", false);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { ReactNative as RN, stylesheet } from "@metro/common";
|
import { ReactNative as RN, stylesheet } from "@metro/common";
|
||||||
import { Forms, Search } from "@ui/components";
|
|
||||||
import { all } from "@ui/assets";
|
import { all } from "@ui/assets";
|
||||||
|
import { Forms, Search } from "@ui/components";
|
||||||
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
||||||
import AssetDisplay from "@ui/settings/components/AssetDisplay";
|
import AssetDisplay from "@ui/settings/components/AssetDisplay";
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import { ReactNative as RN, NavigationNative } from "@metro/common";
|
import { ReactNative as RN, NavigationNative } from "@metro/common";
|
||||||
import { Forms } from "@ui/components";
|
import { Forms } from "@ui/components";
|
||||||
import { getAssetIDByName } from "@ui/assets";
|
import { getAssetIDByName } from "@ui/assets";
|
||||||
import { showToast } from "@ui/toasts";
|
|
||||||
import { connectToDebugger } from "@lib/debug";
|
import { connectToDebugger } from "@lib/debug";
|
||||||
import { useProxy } from "@lib/storage";
|
import { useProxy } from "@lib/storage";
|
||||||
import settings, { loaderConfig } from "@lib/settings";
|
import settings, { loaderConfig } from "@lib/settings";
|
||||||
import logger from "@lib/logger";
|
|
||||||
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
||||||
|
|
||||||
const { FormSection, FormRow, FormSwitchRow, FormInput, FormDivider } = Forms;
|
const { FormSection, FormRow, FormSwitchRow, FormInput, FormDivider } = Forms;
|
||||||
|
@ -37,18 +35,10 @@ export default function Developer() {
|
||||||
<FormRow
|
<FormRow
|
||||||
label="Connect to React DevTools"
|
label="Connect to React DevTools"
|
||||||
leading={<FormRow.Icon source={getAssetIDByName("ic_badge_staff")} />}
|
leading={<FormRow.Icon source={getAssetIDByName("ic_badge_staff")} />}
|
||||||
onPress={() => {
|
onPress={() => window.__vendetta_rdc?.connectToDevTools({
|
||||||
try {
|
host: settings.debuggerUrl.split(":")?.[0],
|
||||||
window.__vendetta_rdc?.connectToDevTools({
|
resolveRNStyle: RN.StyleSheet.flatten,
|
||||||
host: settings.debuggerUrl.split(":")?.[0],
|
})}
|
||||||
resolveRNStyle: RN.StyleSheet.flatten,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
// TODO: Check if this ever actually catches anything
|
|
||||||
logger.error("Failed to connect to React DevTools!", e);
|
|
||||||
showToast("Failed to connect to React DevTools!", getAssetIDByName("Small"));
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</>}
|
</>}
|
||||||
</FormSection>
|
</FormSection>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { ReactNative as RN, url, invites } from "@metro/common";
|
import { ReactNative as RN, url, invites } from "@metro/common";
|
||||||
import { DISCORD_SERVER, GITHUB } from "@lib/constants";
|
|
||||||
import { getAssetIDByName } from "@ui/assets";
|
import { getAssetIDByName } from "@ui/assets";
|
||||||
import { Forms, Summary } from "@ui/components";
|
import { Forms, Summary } from "@ui/components";
|
||||||
|
import { DISCORD_SERVER, GITHUB } from "@lib/constants";
|
||||||
import { getDebugInfo } from "@lib/debug";
|
import { getDebugInfo } from "@lib/debug";
|
||||||
import { useProxy } from "@lib/storage";
|
import { useProxy } from "@lib/storage";
|
||||||
import settings from "@lib/settings";
|
import settings from "@lib/settings";
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { toasts } from "@metro/common";
|
import { toasts } from "@metro/common";
|
||||||
|
|
||||||
export function showToast(content: string, asset: number) {
|
export const showToast = (content: string, asset: number) => toasts.open({
|
||||||
return toasts.open({
|
content: content,
|
||||||
content: content,
|
source: asset,
|
||||||
source: asset,
|
});
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in a new issue