[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;
|
||||
}
|
||||
|
||||
declare enum ButtonColors {
|
||||
export enum ButtonColors {
|
||||
BRAND = "brand",
|
||||
RED = "red",
|
||||
GREEN = "green",
|
||||
|
@ -121,7 +121,7 @@ interface ApplicationCommand {
|
|||
type: ApplicationCommandType;
|
||||
}
|
||||
|
||||
declare enum ApplicationCommandInputType {
|
||||
export enum ApplicationCommandInputType {
|
||||
BUILT_IN,
|
||||
BUILT_IN_TEXT,
|
||||
BUILT_IN_INTEGRATION,
|
||||
|
@ -138,7 +138,7 @@ interface ApplicationCommandOption {
|
|||
displayDescription: string;
|
||||
}
|
||||
|
||||
declare enum ApplicationCommandOptionType {
|
||||
export enum ApplicationCommandOptionType {
|
||||
SUB_COMMAND = 1,
|
||||
SUB_COMMAND_GROUP,
|
||||
STRING,
|
||||
|
@ -152,7 +152,7 @@ declare enum ApplicationCommandOptionType {
|
|||
ATTACHMENT,
|
||||
}
|
||||
|
||||
declare enum ApplicationCommandType {
|
||||
export enum ApplicationCommandType {
|
||||
CHAT = 1,
|
||||
USER,
|
||||
MESSAGE,
|
||||
|
|
|
@ -7,11 +7,9 @@ import logger from "@lib/logger";
|
|||
export let socket: WebSocket;
|
||||
|
||||
export function connectToDebugger(url: string) {
|
||||
if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) {
|
||||
socket.close();
|
||||
}
|
||||
if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) socket.close();
|
||||
|
||||
if (url === "") {
|
||||
if (!url) {
|
||||
showToast("Invalid debugger URL!", getAssetIDByName("Small"));
|
||||
return;
|
||||
}
|
||||
|
@ -19,7 +17,6 @@ export function connectToDebugger(url: string) {
|
|||
socket = new WebSocket(`ws://${url}`);
|
||||
|
||||
socket.addEventListener("open", () => showToast("Connected to debugger.", getAssetIDByName("Check")));
|
||||
|
||||
socket.addEventListener("message", (message: any) => {
|
||||
try {
|
||||
(0, eval)(message.data);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Emitter, EmitterEvent, EmitterListener, EmitterListenerData, EmitterListeners } from "@types";
|
||||
|
||||
export const Events = Object.freeze({
|
||||
GET: "GET",
|
||||
SET: "SET",
|
||||
DEL: "DEL",
|
||||
});
|
||||
export enum Events {
|
||||
GET = "GET",
|
||||
SET = "SET",
|
||||
DEL = "DEL",
|
||||
};
|
||||
|
||||
export default function createEmitter(): Emitter {
|
||||
return {
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
const basicFind = (prop: string) => Object.values(window.modules).find(m => m?.publicModule.exports?.[prop])?.publicModule?.exports;
|
||||
|
||||
// Hoist React on window
|
||||
window.React = basicFind("createElement") as typeof import("react");;
|
||||
window.React = basicFind("createElement") as typeof import("react");
|
||||
|
||||
// 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 const constants = basicFind("AbortCodes");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
|
||||
import { LoaderConfig, Settings } from "@types";
|
||||
import { createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
|
||||
|
||||
export default wrapSync(createStorage<Settings>(createMMKVBackend("VENDETTA_SETTINGS")));
|
||||
export const loaderConfig = wrapSync(createStorage<LoaderConfig>(createFileBackend("vendetta_loader.json")));
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { clipboard } from "@metro/common";
|
||||
|
||||
// TODO: Remove/deprecate this, the clipboard module works the same way.
|
||||
|
||||
export default function copyText(content: string) {
|
||||
try {
|
||||
clipboard.setString(content);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// https://stackoverflow.com/a/68339174
|
||||
|
||||
export default function unfreeze(obj: object) {
|
||||
if (Object.isFrozen(obj)) {
|
||||
return Object.assign({}, obj);
|
||||
}
|
||||
if (Object.isFrozen(obj)) return Object.assign({}, obj);
|
||||
return obj;
|
||||
}
|
|
@ -4,7 +4,7 @@ import InputAlert from "@ui/components/InputAlert";
|
|||
|
||||
const Alerts = findByProps("openLazy", "close");
|
||||
|
||||
interface InternalConfirmationAlertOptions extends Omit<ConfirmationAlertOptions, 'content'> {
|
||||
interface InternalConfirmationAlertOptions extends Omit<ConfirmationAlertOptions, "content"> {
|
||||
content: string | JSX.Element | JSX.Element[] | undefined;
|
||||
body: string | undefined;
|
||||
children: JSX.Element | JSX.Element[];
|
||||
|
@ -20,18 +20,11 @@ export function showConfirmationAlert(options: ConfirmationAlertOptions) {
|
|||
};
|
||||
|
||||
delete internalOptions.content;
|
||||
|
||||
return Alerts.show(internalOptions);
|
||||
};
|
||||
|
||||
export function showCustomAlert(component: React.ComponentType, props: any) {
|
||||
Alerts.openLazy({
|
||||
importer: async function () {
|
||||
return () => React.createElement(component, props);
|
||||
}
|
||||
export const showCustomAlert = (component: React.ComponentType, props: any) => Alerts.openLazy({
|
||||
importer: async () => () => React.createElement(component, props),
|
||||
});
|
||||
};
|
||||
|
||||
export function showInputAlert(options: InputAlertProps) {
|
||||
showCustomAlert(InputAlert as React.ComponentType, options);
|
||||
};
|
||||
export const showInputAlert = (options: InputAlertProps) => showCustomAlert(InputAlert as React.ComponentType, options);
|
|
@ -1,6 +1,6 @@
|
|||
import { Asset, Indexable } from "@types";
|
||||
import { after } from "@lib/patcher";
|
||||
import { assets } from "@metro/common";
|
||||
import { after } from "@lib/patcher";
|
||||
|
||||
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 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.
|
||||
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?
|
||||
|
||||
//? 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
|
||||
//* 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";
|
||||
|
||||
const { FormInput } = Forms;
|
||||
|
||||
const Alerts = findByProps("openLazy", "close");
|
||||
|
||||
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
|
||||
// Literally could not figure this out, many thanks
|
||||
|
||||
import { findByProps, findByStoreName } from "@metro/filters";
|
||||
import { FluxDispatcher } from "@metro/common";
|
||||
import { findByProps, findByStoreName } from "@metro/filters";
|
||||
import logger from "@lib/logger";
|
||||
|
||||
// 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 { HTTP_REGEX } from "@lib/constants";
|
||||
import { installPlugin } from "@lib/plugins";
|
||||
import { showInputAlert } from "@ui/alerts";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
import { semanticColors } from "@ui/color";
|
||||
import { General } from "@ui/components";
|
||||
|
||||
const { TouchableOpacity, Image } = General;
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
import { ButtonColors, Plugin } from "@types";
|
||||
import { ReactNative as RN, stylesheet, NavigationNative } from "@metro/common";
|
||||
import { findByProps } from "@metro/filters";
|
||||
import { Forms, General } from "@ui/components";
|
||||
import { Plugin } from "@types";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
import { showToast } from "@ui/toasts";
|
||||
import { showConfirmationAlert } from "@ui/alerts";
|
||||
import { semanticColors } from "@ui/color";
|
||||
import { removePlugin, startPlugin, stopPlugin, getSettings } from "@lib/plugins";
|
||||
import copyText from "@utils/copyText";
|
||||
|
||||
// TODO: Replace with our eventual dialog API
|
||||
const Dialog = findByProps("show", "openLazy", "close");
|
||||
|
||||
const { FormRow, FormSwitch } = Forms;
|
||||
const { TouchableOpacity, Image } = General;
|
||||
|
||||
|
@ -79,12 +76,12 @@ export default function PluginCard({ plugin, index }: PluginCardProps) {
|
|||
trailing={
|
||||
<RN.View style={styles.actions}>
|
||||
<TouchableOpacity
|
||||
onPress={() => Dialog.show({
|
||||
onPress={() => showConfirmationAlert({
|
||||
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",
|
||||
cancelText: "Cancel",
|
||||
confirmColor: "red",
|
||||
confirmColor: ButtonColors.RED,
|
||||
onConfirm: () => {
|
||||
try {
|
||||
removePlugin(plugin.id);
|
||||
|
|
|
@ -4,11 +4,11 @@ import { after } from "@lib/patcher";
|
|||
import findInReactTree from "@utils/findInReactTree";
|
||||
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
||||
import SettingsSection from "@ui/settings/components/SettingsSection";
|
||||
import InstallPluginButton from "@ui/settings/components/InstallPluginButton";
|
||||
import General from "@ui/settings/pages/General";
|
||||
import Plugins from "@ui/settings/pages/Plugins";
|
||||
import Developer from "@ui/settings/pages/Developer";
|
||||
import AssetBrowser from "@ui/settings/pages/AssetBrowser";
|
||||
import InstallPluginButton from "@ui/settings/components/InstallPluginButton";
|
||||
|
||||
const screensModule = findByDisplayName("getScreens", false);
|
||||
const settingsModule = findByDisplayName("UserSettingsOverviewWrapper", false);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { ReactNative as RN, stylesheet } from "@metro/common";
|
||||
import { Forms, Search } from "@ui/components";
|
||||
import { all } from "@ui/assets";
|
||||
import { Forms, Search } from "@ui/components";
|
||||
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
||||
import AssetDisplay from "@ui/settings/components/AssetDisplay";
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { ReactNative as RN, NavigationNative } from "@metro/common";
|
||||
import { Forms } from "@ui/components";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
import { showToast } from "@ui/toasts";
|
||||
import { connectToDebugger } from "@lib/debug";
|
||||
import { useProxy } from "@lib/storage";
|
||||
import settings, { loaderConfig } from "@lib/settings";
|
||||
import logger from "@lib/logger";
|
||||
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
||||
|
||||
const { FormSection, FormRow, FormSwitchRow, FormInput, FormDivider } = Forms;
|
||||
|
@ -37,18 +35,10 @@ export default function Developer() {
|
|||
<FormRow
|
||||
label="Connect to React DevTools"
|
||||
leading={<FormRow.Icon source={getAssetIDByName("ic_badge_staff")} />}
|
||||
onPress={() => {
|
||||
try {
|
||||
window.__vendetta_rdc?.connectToDevTools({
|
||||
onPress={() => window.__vendetta_rdc?.connectToDevTools({
|
||||
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>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { ReactNative as RN, url, invites } from "@metro/common";
|
||||
import { DISCORD_SERVER, GITHUB } from "@lib/constants";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
import { Forms, Summary } from "@ui/components";
|
||||
import { DISCORD_SERVER, GITHUB } from "@lib/constants";
|
||||
import { getDebugInfo } from "@lib/debug";
|
||||
import { useProxy } from "@lib/storage";
|
||||
import settings from "@lib/settings";
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { toasts } from "@metro/common";
|
||||
|
||||
export function showToast(content: string, asset: number) {
|
||||
return toasts.open({
|
||||
export const showToast = (content: string, asset: number) => toasts.open({
|
||||
content: content,
|
||||
source: asset,
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue