Skip to content

Commit

Permalink
chore: refactor project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Jul 29, 2024
1 parent d637651 commit ccb49cb
Show file tree
Hide file tree
Showing 71 changed files with 248 additions and 437 deletions.
2 changes: 1 addition & 1 deletion shims/depsModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findByPropsLazy } from "@metro";
import { findByPropsLazy } from "@metro/wrappers";

module.exports = {
"react": findByPropsLazy("createElement"),
Expand Down
2 changes: 1 addition & 1 deletion shims/jsxRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getProxyFactory } from "@lib/utils/lazy";
import { findByPropsLazy } from "@metro/utils";
import { findByPropsLazy } from "@metro/wrappers";

const jsxRuntime = findByPropsLazy("jsx", "jsxs", "Fragment");

Expand Down
2 changes: 1 addition & 1 deletion src/core/commands/debug.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Strings } from "@core/i18n";
import { ApplicationCommand, ApplicationCommandOptionType } from "@lib/api/commands/types";
import { getDebugInfo } from "@lib/debug";
import { getDebugInfo } from "@lib/api/debug";
import { messageUtil } from "@metro/common";

export default () => <ApplicationCommand>{
Expand Down
4 changes: 2 additions & 2 deletions src/core/commands/eval.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Strings } from "@core/i18n";
import { ApplicationCommand, ApplicationCommandOptionType } from "@lib/api/commands/types";
import { settings } from "@lib/settings";
import { settings } from "@lib/api/settings";
import { messageUtil } from "@metro/common";
import { findByPropsLazy } from "@metro/utils";
import { findByPropsLazy } from "@metro/wrappers";

const util = findByPropsLazy("inspect");
const AsyncFunction = (async () => void 0).constructor;
Expand Down
2 changes: 1 addition & 1 deletion src/core/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FluxDispatcher } from "@metro/common";
import { findByNameLazy } from "@metro/utils";
import { findByNameLazy } from "@metro/wrappers";
import { PrimitiveType } from "intl-messageformat";

import langDefault from "./default.json";
Expand Down
24 changes: 17 additions & 7 deletions src/core/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { PluginInstanceInternal } from "@lib/plugins/types";

export function initCorePlugins() {
const unloads = [
require("./quickInstall")
].map(p => {
return p.default();
});
interface CorePlugin {
default: PluginInstanceInternal;
preenabled: boolean;
}

// Called from @lib/plugins
export const getCorePlugins = (): Record<string, CorePlugin> => ({
"vd-quick-install": require("./vd-quick-install")
});

return () => unloads.forEach(m => typeof m === "function" && m());
/**
* @internal
*/
export function defineCorePlugin(instance: PluginInstanceInternal): PluginInstanceInternal {
// @ts-expect-error
instance[Symbol.for("bunny.core.plugin")] = true;
return instance;
}
11 changes: 0 additions & 11 deletions src/core/plugins/quickInstall/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { findAssetId } from "@lib/api/assets";
import { isThemeSupported } from "@lib/api/native/loader";
import { after } from "@lib/api/patcher";
import { useProxy } from "@lib/api/storage";
import { installTheme, removeTheme, themes } from "@lib/managers/themes";
import { installTheme, removeTheme, themes } from "@lib/themes";
import { DISCORD_SERVER_ID, HTTP_REGEX_MULTI, PLUGINS_CHANNEL_ID, THEMES_CHANNEL_ID, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { Button } from "@metro/common/components";
import { findByProps, findByPropsLazy } from "@metro/utils";
import { findByProps, findByPropsLazy } from "@metro/wrappers";
import { ErrorBoundary } from "@ui/components";
import { showToast } from "@ui/toasts";

Expand Down
21 changes: 21 additions & 0 deletions src/core/plugins/vd-quick-install/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineCorePlugin } from "..";
import patchForumPost from "./forumPost";
import patchUrl from "./url";

let patches = [] as (() => unknown)[];

export default defineCorePlugin({
manifest: {
id: "bunny.quick.install",
name: "QuickInstall",
version: "1.0.0",
description: "Quickly install Vendetta plugins and themes",
authors: [{ name: "pylixonly" }]
},
start() {
patches = [patchForumPost(), patchUrl()];
},
stop() {
patches.forEach(p => p());
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { VdPluginManager } from "@core/vendetta/plugins";
import { findAssetId } from "@lib/api/assets";
import { isThemeSupported } from "@lib/api/native/loader";
import { after, instead } from "@lib/api/patcher";
import { installTheme } from "@lib/managers/themes";
import { installTheme } from "@lib/themes";
import { THEMES_CHANNEL_ID, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { channels, url } from "@metro/common";
import { byMutableProp } from "@metro/filters";
import { findExports } from "@metro/finders";
import { findByProps, findByPropsLazy } from "@metro/utils";
import { findByProps, findByPropsLazy } from "@metro/wrappers";
import { showConfirmationAlert } from "@ui/alerts";
import { showToast } from "@ui/toasts";

Expand Down
8 changes: 0 additions & 8 deletions src/core/polyfills/allSettled.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/core/polyfills/promise-all-settled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const allSettledFulfill = <T>(value: T) => ({ status: "fulfilled", value } as const);
const allSettledReject = <T>(reason: T) => ({ status: "rejected", reason } as const);
const mapAllSettled = <T>(item: T) => Promise.resolve(item).then(allSettledFulfill, allSettledReject);

Promise.allSettled ??= <T extends unknown[]>(iterator: T) => {
return Promise.all(Array.from(iterator).map(mapAllSettled));
};
2 changes: 1 addition & 1 deletion src/core/ui/components/AddonCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { findAssetId } from "@lib/api/assets";
import { lazyDestructure } from "@lib/utils/lazy";
import { Card, FormRadio, FormSwitch, IconButton, LegacyFormRow, Stack, Text } from "@metro/common/components";
import { findByProps } from "@metro/utils";
import { findByProps } from "@metro/wrappers";
import { semanticColors } from "@ui/color";
import { createStyles, TextStyleSheet } from "@ui/styles";
import { TouchableOpacity, View } from "react-native";
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/components/AddonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Strings } from "@core/i18n";
import { CardWrapper } from "@core/ui/components/AddonCard";
import { findAssetId } from "@lib/api/assets";
import { useProxy } from "@lib/api/storage";
import { settings } from "@lib/settings";
import { settings } from "@lib/api/settings";
import { HTTP_REGEX_MULTI } from "@lib/utils/constants";
import { findByProps } from "@metro";
import { clipboard } from "@metro/common";
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Strings } from "@core/i18n";
import { findAssetId } from "@lib/api/assets";
import { isFontSupported, isThemeSupported } from "@lib/api/native/loader";
import { useProxy } from "@lib/api/storage";
import { settings } from "@lib/settings";
import { settings } from "@lib/api/settings";
import { registerSection } from "@ui/settings";
import { version } from "bunny-build-info";

Expand Down
6 changes: 3 additions & 3 deletions src/core/ui/settings/pages/Developer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import AssetBrowser from "@core/ui/settings/pages/Developer/AssetBrowser";
import { findAssetId } from "@lib/api/assets";
import { getReactDevToolsProp, getReactDevToolsVersion, isLoaderConfigSupported, isReactDevToolsPreloaded, isVendettaLoader } from "@lib/api/native/loader";
import { useProxy } from "@lib/api/storage";
import { connectToDebugger } from "@lib/debug";
import { loaderConfig, settings } from "@lib/settings";
import { connectToDebugger } from "@lib/api/debug";
import { loaderConfig, settings } from "@lib/api/settings";
import { lazyDestructure } from "@lib/utils/lazy";
import { NavigationNative } from "@metro/common";
import { Button, LegacyFormText, Stack, TableRow, TableRowGroup, TableSwitchRow, TextInput } from "@metro/common/components";
import { findByProps } from "@metro/utils";
import { findByProps } from "@metro/wrappers";
import { semanticColors } from "@ui/color";
import { ErrorBoundary } from "@ui/components";
import { createStyles, TextStyleSheet } from "@ui/styles";
Expand Down
6 changes: 3 additions & 3 deletions src/core/ui/settings/pages/Fonts/FontCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { CardWrapper } from "@core/ui/components/AddonCard";
import { findAssetId } from "@lib/api/assets";
import { BundleUpdaterManager } from "@lib/api/native/modules";
import { useProxy } from "@lib/api/storage";
import { FontDefinition, fonts, selectFont } from "@lib/managers/fonts";
import { showConfirmationAlert } from "@lib/ui/alerts";
import { TextStyleSheet } from "@lib/ui/styles";
import { FontDefinition, fonts, selectFont } from "@lib/fonts";
import { showConfirmationAlert } from "@ui/alerts";
import { TextStyleSheet } from "@ui/styles";
import { lazyDestructure } from "@lib/utils/lazy";
import { ButtonColors } from "@lib/utils/types";
import { findByProps } from "@metro";
Expand Down
6 changes: 3 additions & 3 deletions src/core/ui/settings/pages/Fonts/FontEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { formatString, Strings } from "@core/i18n";
import { findAssetId } from "@lib/api/assets";
import { createProxy, useProxy } from "@lib/api/storage";
import { FontDefinition, fonts, removeFont, saveFont, validateFont } from "@lib/managers/fonts";
import { getCurrentTheme } from "@lib/managers/themes";
import { FontDefinition, fonts, removeFont, saveFont, validateFont } from "@lib/fonts";
import { getCurrentTheme } from "@lib/themes";
import { safeFetch } from "@lib/utils";
import { NavigationNative } from "@metro/common";
import { ActionSheet, BottomSheetTitleHeader, Button, IconButton, Stack, TableRow, TableRowGroup, Text, TextInput } from "@metro/common/components";
import { findByPropsLazy } from "@metro/utils";
import { findByPropsLazy } from "@metro/wrappers";
import { ErrorBoundary } from "@ui/components";
import { useMemo, useRef, useState } from "react";
import { ScrollView, View } from "react-native";
Expand Down
4 changes: 2 additions & 2 deletions src/core/ui/settings/pages/Fonts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Strings } from "@core/i18n";
import AddonPage from "@core/ui/components/AddonPage";
import FontEditor from "@core/ui/settings/pages/Fonts/FontEditor";
import { useProxy } from "@lib/api/storage";
import { FontDefinition, fonts, installFont } from "@lib/managers/fonts";
import { settings } from "@lib/settings";
import { FontDefinition, fonts, installFont } from "@lib/fonts";
import { settings } from "@lib/api/settings";
import { NavigationNative } from "@metro/common";

import FontCard from "./FontCard";
Expand Down
4 changes: 2 additions & 2 deletions src/core/ui/settings/pages/General/About.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Strings } from "@core/i18n";
import Version from "@core/ui/settings/pages/General/Version";
import { useProxy } from "@lib/api/storage";
import { getDebugInfo } from "@lib/debug";
import { settings } from "@lib/settings";
import { getDebugInfo } from "@lib/api/debug";
import { settings } from "@lib/api/settings";
import { Stack, TableRowGroup } from "@metro/common/components";
import { Platform, ScrollView } from "react-native";

Expand Down
4 changes: 2 additions & 2 deletions src/core/ui/settings/pages/General/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { PyoncordIcon } from "@core/ui/settings";
import About from "@core/ui/settings/pages/General/About";
import { findAssetId } from "@lib/api/assets";
import { useProxy } from "@lib/api/storage";
import { getDebugInfo, toggleSafeMode } from "@lib/debug";
import { settings } from "@lib/settings";
import { getDebugInfo, toggleSafeMode } from "@lib/api/debug";
import { settings } from "@lib/api/settings";
import { DISCORD_SERVER, GITHUB } from "@lib/utils/constants";
import { NavigationNative, url } from "@metro/common";
import { Stack, TableRow, TableRowGroup, TableSwitchRow } from "@metro/common/components";
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/pages/Plugins/PluginCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CardWrapper } from "@core/ui/components/AddonCard";
import { VdPluginManager, VendettaPlugin } from "@core/vendetta/plugins";
import { findAssetId } from "@lib/api/assets";
import { useProxy } from "@lib/api/storage";
import { showSheet } from "@lib/ui/sheets";
import { showSheet } from "@ui/sheets";
import { lazyDestructure } from "@lib/utils/lazy";
import { findByProps } from "@metro";
import { NavigationNative } from "@metro/common";
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/pages/Plugins/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AddonPage from "@core/ui/components/AddonPage";
import PluginCard from "@core/ui/settings/pages/Plugins/PluginCard";
import { VdPluginManager, VendettaPlugin } from "@core/vendetta/plugins";
import { useProxy } from "@lib/api/storage";
import { settings } from "@lib/settings";
import { settings } from "@lib/api/settings";
import { Author } from "@lib/utils/types";

export default function Plugins() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { formatString, Strings } from "@core/i18n";
import { VdPluginManager, VendettaPlugin } from "@core/vendetta/plugins";
import { findAssetId } from "@lib/api/assets";
import { purgeStorage, useProxy } from "@lib/api/storage";
import { showConfirmationAlert } from "@lib/ui/alerts";
import { hideSheet } from "@lib/ui/sheets";
import { showToast } from "@lib/ui/toasts";
import { showConfirmationAlert } from "@ui/alerts";
import { hideSheet } from "@ui/sheets";
import { showToast } from "@ui/toasts";
import { ButtonColors } from "@lib/utils/types";
import { clipboard } from "@metro/common";
import { ActionSheet, ActionSheetRow, Button, TableRow, Text } from "@metro/common/components";
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/pages/Plugins/usePluginCardStyles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createStyles } from "@lib/ui/styles";
import { createStyles } from "@ui/styles";
import { tokens } from "@metro/common";

export const usePluginCardStyles = createStyles({
Expand Down
7 changes: 3 additions & 4 deletions src/core/ui/settings/pages/Themes/ThemeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { formatString, Strings } from "@core/i18n";
import AddonCard, { CardWrapper } from "@core/ui/components/AddonCard";
import { findAssetId } from "@lib/api/assets";
import { useProxy } from "@lib/api/storage";
import { applyTheme, fetchTheme, removeTheme, selectTheme, Theme, themes } from "@lib/managers/themes";
import { settings } from "@lib/settings";
import { settings } from "@lib/api/settings";
import { applyTheme, fetchTheme, removeTheme, selectTheme, Theme, themes } from "@lib/themes";
import { ButtonColors } from "@lib/utils/types";
import { clipboard } from "@metro/common";
import { showConfirmationAlert } from "@ui/alerts";
Expand All @@ -18,7 +18,7 @@ function selectAndApply(value: boolean, theme: Theme) {
}
}

export default function ThemeCard({ item: theme, index }: CardWrapper<Theme>) {
export default function ThemeCard({ item: theme }: CardWrapper<Theme>) {
useProxy(theme);

const [removed, setRemoved] = React.useState(false);
Expand All @@ -30,7 +30,6 @@ export default function ThemeCard({ item: theme, index }: CardWrapper<Theme>) {

return (
<AddonCard
index={index}
headerLabel={theme.data.name}
headerSublabel={authors ? `by ${authors.map(i => i.name).join(", ")}` : ""}
descriptionLabel={theme.data.description ?? "No description."}
Expand Down
4 changes: 2 additions & 2 deletions src/core/ui/settings/pages/Themes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { formatString, Strings } from "@core/i18n";
import AddonPage from "@core/ui/components/AddonPage";
import ThemeCard from "@core/ui/settings/pages/Themes/ThemeCard";
import { useProxy } from "@lib/api/storage";
import { installTheme, Theme, themes } from "@lib/managers/themes";
import { settings } from "@lib/settings";
import { settings } from "@lib/api/settings";
import { installTheme, Theme, themes } from "@lib/themes";
import { Author } from "@lib/utils/types";
import { Button } from "@metro/common/components";

Expand Down
23 changes: 14 additions & 9 deletions src/core/vendetta/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { getVendettaLoaderIdentity, isPyonLoader } from "@lib/api/native/loader"
import patcher from "@lib/api/patcher";
import * as storage from "@lib/api/storage";
import { createStorage } from "@lib/api/storage";
import * as debug from "@lib/debug";
import * as themes from "@lib/managers/themes";
import { loaderConfig, settings } from "@lib/settings";
import * as debug from "@lib/api/debug";
import { loaderConfig, settings } from "@lib/api/settings";
import * as themes from "@lib/themes";
import * as utils from "@lib/utils";
import { cyrb64Hash } from "@lib/utils/cyrb64";
import { DiscordLogger } from "@lib/utils/logger";
Expand Down Expand Up @@ -39,6 +39,15 @@ export async function createVdPluginObject(plugin: VendettaPlugin) {
}

export const initVendettaObject = (): any => {
// pitfall: this assumes the returning module(s) are the same within the same location
// find(m => m.render?.name === "ActionSheet") - would work fine
// ["trackThis", "trackThat"].forEach(p => find(m => m[p])) - would not
const createStackBasedFilter = (fn: any) => {
return (filter: (m: any) => boolean) => {
return fn(metro.factories.createSimpleFilter(filter, cyrb64Hash(new Error().stack!)));
};
};

const api = window.vendetta = {
patcher: {
before: patcher.before,
Expand All @@ -47,12 +56,8 @@ export const initVendettaObject = (): any => {
},
metro: {
modules: window.modules,
find: (filter: (m: any) => boolean) => {
return metro.findExports(metro.createSimpleFilter(filter, cyrb64Hash(new Error().stack!)));
},
findAll: (filter: (m: any) => boolean) => {
return metro.findAllExports(metro.createSimpleFilter(filter, cyrb64Hash(new Error().stack!)));
},
find: createStackBasedFilter(metro.findExports),
findAll: createStackBasedFilter(metro.findAllExports),
findByProps: (...props: any[]) => {
// TODO: remove this hack to fix Decor
if (props.length === 1 && props[0] === "KeyboardAwareScrollView") {
Expand Down
5 changes: 2 additions & 3 deletions src/core/vendetta/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { allSettled } from "@core/polyfills/allSettled";
import { awaitStorage, createMMKVBackend, createStorage, purgeStorage, wrapSync } from "@lib/api/storage";
import { settings } from "@lib/settings";
import { settings } from "@lib/api/settings";
import { safeFetch } from "@lib/utils";
import { BUNNY_PROXY_PREFIX, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { DiscordLogger, logger } from "@lib/utils/logger";
Expand Down Expand Up @@ -168,7 +167,7 @@ export const VdPluginManager = {

if (!settings.safeMode?.enabled) {
// Loop over any plugin that is enabled, update it if allowed, then start it.
await allSettled(allIds.filter(pl => plugins[pl].enabled).map(async pl => (plugins[pl].update && await this.fetchPlugin(pl).catch((e: Error) => logger.error(e.message)), await this.startPlugin(pl))));
await Promise.allSettled(allIds.filter(pl => plugins[pl].enabled).map(async pl => (plugins[pl].update && await this.fetchPlugin(pl).catch((e: Error) => logger.error(e.message)), await this.startPlugin(pl))));
// Wait for the above to finish, then update all disabled plugins that are allowed to.
allIds.filter(pl => !plugins[pl].enabled && plugins[pl].update).forEach(pl => this.fetchPlugin(pl));
}
Expand Down
Loading

0 comments on commit ccb49cb

Please sign in to comment.