[Global] Code cleanup pass

This commit is contained in:
Beef 2023-04-15 19:54:23 +01:00
parent ffbb507125
commit 85d0bd263b
30 changed files with 65 additions and 80 deletions

View file

@ -15,18 +15,18 @@
"license": "BSD-3-Clause",
"devDependencies": {
"@react-native-clipboard/clipboard": "1.10.0",
"@swc/core": "^1.3.35",
"@swc/core": "^1.3.50",
"@types/chroma-js": "^2.4.0",
"@types/lodash": "^4.14.191",
"@types/react": "18.0.27",
"@types/lodash": "^4.14.194",
"@types/react": "18.0.35",
"@types/react-native": "0.70.6",
"esbuild": "^0.17.11",
"esbuild": "^0.17.16",
"esbuild-plugin-alias": "^0.2.1",
"moment": "2.22.2",
"typescript": "^4.9.5"
"typescript": "^5.0.4"
},
"dependencies": {
"@swc/helpers": "^0.4.14",
"@swc/helpers": "^0.5.0",
"spitroast": "^1.4.2"
},
"pnpm": {

2
src/def.d.ts vendored
View file

@ -436,7 +436,7 @@ interface VendettaObject {
Search: _React.ComponentType<SearchProps>;
}
toasts: {
showToast: (content: string, asset: number) => void;
showToast: (content: string, asset?: number) => void;
};
alerts: {
showConfirmationAlert: (options: ConfirmationAlertOptions) => void;

View file

@ -1,8 +1,8 @@
import { patchLogHook } from "@lib/debug";
import { patchCommands } from "@lib/commands";
import { initPlugins } from "@lib/plugins";
import { patchAssets } from "@ui/assets";
import { patchChatBackground } from "@lib/themes";
import { patchAssets } from "@ui/assets";
import initQuickInstall from "@ui/quickInstall";
import initSafeMode from "@ui/safeMode";
import initSettings from "@ui/settings";

View file

@ -5,7 +5,7 @@ import { after } from "@lib/patcher";
let commands: ApplicationCommand[] = [];
export function patchCommands() {
const unpatch = after("getBuiltInCommands", commandsModule, (args, res) => res.concat(commands));
const unpatch = after("getBuiltInCommands", commandsModule, (_, res) => res.concat(commands));
return () => {
commands = [];
unpatch();

View file

@ -1,8 +1,8 @@
import { RNConstants } from "@types";
import { ReactNative as RN } from "@metro/common";
import { after } from "@lib/patcher";
import { ClientInfoManager, DeviceManager, BundleUpdaterManager } from "@lib/native";
import { getCurrentTheme, selectTheme } from "@lib/themes";
import { ClientInfoManager, DeviceManager, BundleUpdaterManager } from "@lib/native";
import { getAssetIDByName } from "@ui/assets";
import { showToast } from "@ui/toasts";
import settings from "@lib/settings";

View file

@ -11,8 +11,7 @@ function onDispatch({ locale }: { locale: string }) {
// Theming
// Based on https://github.com/Aliucord/AliucordRN/blob/main/src/ui/patchTheme.ts
try {
const theme = ThemeStore.theme || "dark";
ThemeManager.overrideTheme(theme);
ThemeManager.overrideTheme(ThemeStore?.theme ?? "dark");
if (AMOLEDThemeManager && UnsyncedUserSettingsStore.useAMOLEDTheme === 2) AMOLEDThemeManager.setAMOLEDThemeEnabled(true);
} catch(e) {
logger.error("Failed to fix theme...", e);

View file

@ -4,14 +4,12 @@ import { MetroModules, PropsFinder, PropsFinderAll } from "@types";
declare const __r: (moduleId: number) => any;
// Function to blacklist a module, preventing it from being searched again
function blacklist(id: number) {
Object.defineProperty(window.modules, id, {
value: window.modules[id],
enumerable: false,
configurable: true,
writable: true
})
}
const blacklist = (id: number) => Object.defineProperty(window.modules, id, {
value: window.modules[id],
enumerable: false,
configurable: true,
writable: true
});
// Blacklist any "bad-actor" modules, e.g. the dreaded null proxy, the window itself, or undefined modules
for (const key in window.modules) {
@ -34,25 +32,21 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
if (!modules[id].isInitialized) try {
__r(id);
} catch {};
} catch {}
if (!module) {
blacklist(id);
continue;
};
}
try {
if (module.default && module.__esModule && filter(module.default)) {
if (single) return module.default;
found.push(module.default);
}
if (module.default && module.__esModule && filter(module.default)) {
if (single) return module.default;
found.push(module.default);
}
if (filter(module)) {
if (single) return module;
else found.push(module);
}
} catch (e: Error | any) {
console.error(`Failed to filter modules... ${e.stack || e.toString()}`);
if (filter(module)) {
if (single) return module;
else found.push(module);
}
}

View file

@ -1,9 +1,9 @@
import { PluginManifest, Plugin } from "@types";
import { safeFetch } from "@lib/utils";
import { awaitSyncWrapper, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
import { MMKVManager } from "@lib/native";
import settings from "@lib/settings";
import logger, { logModule } from "@lib/logger";
import safeFetch from "@utils/safeFetch";
import settings from "@lib/settings";
type EvaledPlugin = {
onLoad?(): void;

View file

@ -1,8 +1,8 @@
import { initThemes } from "@lib/themes";
// Hoist required modules
// This used to be in filters.ts, but things became convoluted
import { initThemes } from "@lib/themes";
// Early find logic
const basicFind = (prop: string) => Object.values(window.modules).find(m => m?.publicModule.exports?.[prop])?.publicModule?.exports;

View file

@ -1,5 +1,5 @@
import { Emitter, StorageBackend } from "@types";
import createEmitter from "../emitter";
import createEmitter from "@lib/emitter";
const emitterSymbol = Symbol("emitter accessor");
const syncAwaitSymbol = Symbol("wrapSync promise accessor");

View file

@ -3,7 +3,7 @@ import { ReactNative as RN, chroma } from "@metro/common";
import { findByName, findByProps } from "@metro/filters";
import { instead, after } from "@lib/patcher";
import { createFileBackend, createMMKVBackend, createStorage, wrapSync, awaitSyncWrapper } from "@lib/storage";
import { safeFetch } from "@utils";
import { safeFetch } from "@lib/utils";
//! As of 173.10, early-finding this does not work.
// Somehow, this is late enough, though?

View file

@ -1,5 +1,5 @@
import { SearchFilter } from "@types";
import findInTree from "@utils/findInTree";
import { findInTree } from "@lib/utils";
export default (tree: { [key: string]: any }, filter: SearchFilter): any => findInTree(tree, filter, {
walkable: ["props", "children", "child", "sibling"],

View file

@ -1,6 +1,7 @@
// Makes mass-importing utils cleaner, chosen over moving utils to one file
export { default as findInReactTree } from "@utils/findInReactTree";
export { default as findInTree } from "@utils/findInTree";
export { default as safeFetch } from "@utils/safeFetch";
export { default as unfreeze } from "@utils/unfreeze";
export { default as without } from "@utils/without";
export { default as findInReactTree } from "@lib/utils/findInReactTree";
export { default as findInTree } from "@lib/utils/findInTree";
export { default as safeFetch } from "@lib/utils/safeFetch";
export { default as unfreeze } from "@lib/utils/unfreeze";
export { default as without } from "@lib/utils/without";

View file

@ -15,7 +15,7 @@ import * as toasts from "@ui/toasts";
import * as alerts from "@ui/alerts";
import * as assets from "@ui/assets";
import * as color from "@ui/color";
import * as utils from "@utils";
import * as utils from "@lib/utils";
export default async (unloads: any[]): Promise<VendettaObject> => ({
patcher: utils.without(patcher, "unpatchAll"),

View file

@ -1,7 +1,6 @@
import { ErrorBoundaryProps } from "@types";
import { React, ReactNative as RN, stylesheet, constants } from "@metro/common";
import { React, ReactNative as RN, stylesheet } from "@metro/common";
import { Forms, Button, Codeblock } from "@ui/components";
import { semanticColors } from "@ui/color";
interface ErrorBoundaryState {
hasErr: boolean;

View file

@ -1,6 +1,6 @@
import { InputAlertProps } from "@types";
import { findByProps } from "@metro/filters";
import { Forms, Alert } from "@ui/components";
import { InputAlertProps } from "@types";
const { FormInput } = Forms;
const Alerts = findByProps("openLazy", "close");

View file

@ -1,26 +1,25 @@
import { SummaryProps } from "@types";
import { Forms } from "@ui/components";
import { getAssetIDByName } from "@ui/assets";
import { ReactNative as RN } from "@metro/common";
// TODO: Destructuring Forms doesn't work here. Why?
import { getAssetIDByName } from "@ui/assets";
import { Forms } from "@ui/components";
export default function Summary({ label, icon, noPadding = false, noAnimation = false, children }: SummaryProps) {
const { FormRow, FormDivider } = Forms;
const [hidden, setHidden] = React.useState(true);
return (
<>
<Forms.FormRow
<FormRow
label={label}
leading={icon && <Forms.FormRow.Icon source={getAssetIDByName(icon)} />}
trailing={<Forms.FormRow.Arrow style={{ transform: [{ rotate: `${hidden ? 180 : 90}deg` }] }} />}
leading={icon && <FormRow.Icon source={getAssetIDByName(icon)} />}
trailing={<FormRow.Arrow style={{ transform: [{ rotate: `${hidden ? 180 : 90}deg` }] }} />}
onPress={() => {
setHidden(!hidden);
if (!noAnimation) RN.LayoutAnimation.configureNext(RN.LayoutAnimation.Presets.easeInEaseOut);
}}
/>
{!hidden && <>
<Forms.FormDivider />
<FormDivider />
<RN.View style={!noPadding && { paddingHorizontal: 15 }}>{children}</RN.View>
</>}
</>

View file

@ -5,8 +5,8 @@ import { installPlugin } from "@lib/plugins";
import { installTheme } from "@lib/themes";
import { findInReactTree } from "@lib/utils";
import { getAssetIDByName } from "@ui/assets";
import { Forms } from "@ui/components";
import { showToast } from "@ui/toasts";
import { Forms } from "@ui/components";
const ForumPostLongPressActionSheet = findByName("ForumPostLongPressActionSheet", false);
const { FormRow } = Forms;

View file

@ -2,8 +2,8 @@ import { ButtonColors } from "@types";
import { ReactNative as RN, stylesheet } from "@metro/common";
import { findByName, findByProps, findByStoreName } from "@metro/filters";
import { after } from "@lib/patcher";
import { DeviceManager } from "@lib/native";
import { toggleSafeMode } from "@lib/debug";
import { DeviceManager } from "@lib/native";
import { semanticColors } from "@ui/color";
import { Button, Codeblock, ErrorBoundary as _ErrorBoundary, SafeAreaView } from "@ui/components";
import settings from "@lib/settings";

View file

@ -4,9 +4,7 @@ import { showToast } from "@ui/toasts";
import { getAssetIDByName } from "@ui/assets";
import { Forms } from "@ui/components";
interface AssetDisplayProps {
asset: Asset;
}
interface AssetDisplayProps { asset: Asset }
const { FormRow } = Forms;

View file

@ -1,8 +1,8 @@
import { ReactNative as RN, stylesheet } from "@metro/common";
import { findByProps } from "@metro/filters";
import { Forms } from "@ui/components";
import { getAssetIDByName } from "@ui/assets";
import { semanticColors } from "@ui/color";
import { Forms } from "@ui/components";
const { FormRow, FormSwitch, FormRadio } = Forms;
const { hideActionSheet } = findByProps("openLazy", "hideActionSheet");

View file

@ -1,10 +1,10 @@
import { ButtonColors, Plugin } from "@types";
import { NavigationNative, clipboard } from "@metro/common";
import { removePlugin, startPlugin, stopPlugin, getSettings, fetchPlugin } from "@lib/plugins";
import { MMKVManager } from "@lib/native";
import { getAssetIDByName } from "@ui/assets";
import { showToast } from "@ui/toasts";
import { showConfirmationAlert } from "@ui/alerts";
import { removePlugin, startPlugin, stopPlugin, getSettings, fetchPlugin } from "@lib/plugins";
import Card, { CardWrapper } from "@ui/settings/components/Card";
async function stopThenStart(plugin: Plugin, callback: Function) {

View file

@ -1,7 +1,7 @@
import { NavigationNative } from "@metro/common";
import { ErrorBoundary, Forms } from "@ui/components";
import { getAssetIDByName } from "@ui/assets";
import { useProxy } from "@lib/storage";
import { getAssetIDByName } from "@ui/assets";
import { ErrorBoundary, Forms } from "@ui/components";
import settings from "@lib/settings";
const { FormRow, FormSection, FormDivider } = Forms;

View file

@ -1,8 +1,8 @@
import { ButtonColors, Theme } from "@types";
import { clipboard } from "@metro/common";
import { fetchTheme, removeTheme, selectTheme } from "@lib/themes";
import { BundleUpdaterManager } from "@lib/native";
import { useProxy } from "@lib/storage";
import { BundleUpdaterManager } from "@lib/native";
import { getAssetIDByName } from "@ui/assets";
import { showConfirmationAlert } from "@ui/alerts";
import { showToast } from "@ui/toasts";

View file

@ -4,8 +4,8 @@ import { after } from "@lib/patcher";
import { installPlugin } from "@lib/plugins";
import { installTheme } from "@lib/themes";
import { Forms } from "@ui/components";
import findInReactTree from "@utils/findInReactTree";
import without from "@utils/without";
import findInReactTree from "@lib/utils/findInReactTree";
import without from "@lib/utils/without";
import ErrorBoundary from "@ui/components/ErrorBoundary";
import SettingsSection from "@ui/settings/components/SettingsSection";
import InstallButton from "@ui/settings/components/InstallButton";

View file

@ -1,7 +1,6 @@
import { ReactNative as RN } from "@metro/common";
import { all } from "@ui/assets";
import { Forms, Search } from "@ui/components";
import ErrorBoundary from "@ui/components/ErrorBoundary";
import { Forms, Search, ErrorBoundary } from "@ui/components";
import AssetDisplay from "@ui/settings/components/AssetDisplay";
const { FormDivider } = Forms;

View file

@ -1,11 +1,10 @@
import { ReactNative as RN, NavigationNative } from "@metro/common";
import { findByProps } from "@metro/filters";
import { Forms } from "@ui/components";
import { getAssetIDByName } from "@ui/assets";
import { connectToDebugger } from "@lib/debug";
import { useProxy } from "@lib/storage";
import { getAssetIDByName } from "@ui/assets";
import { Forms, ErrorBoundary } from "@ui/components";
import settings, { loaderConfig } from "@lib/settings";
import ErrorBoundary from "@ui/components/ErrorBoundary";
const { FormSection, FormRow, FormSwitchRow, FormInput, FormDivider } = Forms;
const { hideActionSheet } = findByProps("openLazy", "hideActionSheet");

View file

@ -1,13 +1,12 @@
import { ReactNative as RN, url } from "@metro/common";
import { getAssetIDByName } from "@ui/assets";
import { Forms, Summary } from "@ui/components";
import { DISCORD_SERVER, GITHUB } from "@lib/constants";
import { getDebugInfo, toggleSafeMode } from "@lib/debug";
import { useProxy } from "@lib/storage";
import { BundleUpdaterManager } from "@lib/native";
import { getAssetIDByName } from "@ui/assets";
import { Forms, Summary, ErrorBoundary } from "@ui/components";
import settings from "@lib/settings";
import Version from "@ui/settings/components/Version";
import ErrorBoundary from "@ui/components/ErrorBoundary";
const { FormRow, FormSwitchRow, FormSection, FormDivider } = Forms;
const debugInfo = getDebugInfo();

View file

@ -1,6 +1,6 @@
import { toasts } from "@metro/common";
export const showToast = (content: string, asset: number) => toasts.open({
export const showToast = (content: string, asset?: number) => toasts.open({
content: content,
source: asset,
});

View file

@ -16,8 +16,6 @@
"@/*": ["src/*"],
"@types": ["src/def.d.ts"],
"@lib/*": ["src/lib/*"],
"@utils": ["src/lib/utils/index.ts"],
"@utils/*": ["src/lib/utils/*"],
"@metro/*": ["src/lib/metro/*"],
"@ui/*": ["src/ui/*"]
}