Skip to content

Commit

Permalink
refactor: expose more stuff and move some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Oct 12, 2024
1 parent fe937a4 commit f2f1f6a
Show file tree
Hide file tree
Showing 53 changed files with 248 additions and 407 deletions.
2 changes: 1 addition & 1 deletion src/core/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PluginInstanceInternal } from "@lib/plugins/types";
import { PluginInstanceInternal } from "@lib/addons/plugins/types";

interface CorePlugin {
default: PluginInstanceInternal;
Expand Down
10 changes: 5 additions & 5 deletions src/core/plugins/quickinstall/forumPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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/themes";
import { DISCORD_SERVER_ID, HTTP_REGEX_MULTI, PLUGINS_CHANNEL_ID, THEMES_CHANNEL_ID, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { installTheme, removeTheme, themes } from "@lib/addons/themes";
import { VD_DISCORD_SERVER_ID, HTTP_REGEX_MULTI, VD_PLUGINS_CHANNEL_ID, VD_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/wrappers";
Expand Down Expand Up @@ -39,13 +39,13 @@ const postMap = {
};

function useExtractThreadContent(thread: any, _firstMessage = null, actionSheet = false): ([PostType, string]) | void {
if (thread.guild_id !== DISCORD_SERVER_ID) return;
if (thread.guild_id !== VD_DISCORD_SERVER_ID) return;

// Determine what type of addon this is.
let postType: PostType;
if (thread.parent_id === PLUGINS_CHANNEL_ID) {
if (thread.parent_id === VD_PLUGINS_CHANNEL_ID) {
postType = "Plugin";
} else if (thread.parent_id === THEMES_CHANNEL_ID && isThemeSupported()) {
} else if (thread.parent_id === VD_THEMES_CHANNEL_ID && isThemeSupported()) {
postType = "Theme";
} else return;

Expand Down
8 changes: 4 additions & 4 deletions src/core/plugins/quickinstall/url.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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/themes";
import { THEMES_CHANNEL_ID, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { installTheme } from "@lib/addons/themes";
import { VD_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/wrappers";
import { showConfirmationAlert } from "@ui/alerts";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { showToast } from "@ui/toasts";

const showSimpleActionSheet = findExports(byMutableProp("showSimpleActionSheet"));
Expand Down Expand Up @@ -66,7 +66,7 @@ export default () => {
if (!urlType) return orig.apply(this, args);

// Make clicking on theme links only work in #themes, should there be a theme proxy in the future, this can be removed.
if (urlType === "theme" && getChannel(getChannelId())?.parent_id !== THEMES_CHANNEL_ID) return orig.apply(this, args);
if (urlType === "theme" && getChannel(getChannelId())?.parent_id !== VD_THEMES_CHANNEL_ID) return orig.apply(this, args);

showConfirmationAlert({
title: Strings.HOLD_UP,
Expand Down
4 changes: 1 addition & 3 deletions src/core/ui/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export default function initSettings() {
title: () => Strings.BUNNY,
icon: { uri: PyoncordIcon },
render: () => import("@core/ui/settings/pages/General"),
rawTabsConfig: {
useTrailing: () => `(${version})`
}
useTrailing: () => `(${version})`
},
{
key: "BUNNY_PLUGINS",
Expand Down
7 changes: 3 additions & 4 deletions src/core/ui/settings/pages/Fonts/FontCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ 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/fonts";
import { FontDefinition, fonts, selectFont } from "@lib/addons/fonts";
import { lazyDestructure } from "@lib/utils/lazy";
import { ButtonColors } from "@lib/utils/types";
import { findByProps } from "@metro";
import { NavigationNative, tokens } from "@metro/common";
import { Button, Card, IconButton, Stack, Text } from "@metro/common/components";
import * as Skia from "@shopify/react-native-skia";
import { showConfirmationAlert } from "@ui/alerts";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { TextStyleSheet } from "@ui/styles";
import { useMemo } from "react";
import { View } from "react-native";
Expand Down Expand Up @@ -104,7 +103,7 @@ export default function FontCard({ item: font }: CardWrapper<FontDefinition>) {
content: "Reload Discord to apply changes?",
confirmText: Strings.RELOAD,
cancelText: Strings.CANCEL,
confirmColor: ButtonColors.RED,
confirmColor: "red",
onConfirm: BundleUpdaterManager.reload
});
}}
Expand Down
4 changes: 2 additions & 2 deletions src/core/ui/settings/pages/Fonts/FontEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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/fonts";
import { getCurrentTheme } from "@lib/themes";
import { FontDefinition, fonts, removeFont, saveFont, validateFont } from "@lib/addons/fonts";
import { getCurrentTheme } from "@lib/addons/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";
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/pages/Fonts/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 FontEditor from "@core/ui/settings/pages/Fonts/FontEditor";
import { settings } from "@lib/api/settings";
import { useProxy } from "@lib/api/storage";
import { FontDefinition, fonts } from "@lib/fonts";
import { FontDefinition, fonts } from "@lib/addons/fonts";
import { NavigationNative } from "@metro/common";

import FontCard from "./FontCard";
Expand Down
10 changes: 5 additions & 5 deletions src/core/ui/settings/pages/PluginBrowser/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { findAssetId } from "@lib/api/assets";
import { installPlugin, isPluginInstalled, uninstallPlugin } from "@lib/plugins";
import { BunnyPluginManifest } from "@lib/plugins/types";
import { installPlugin, isPluginInstalled, uninstallPlugin } from "@lib/addons/plugins";
import { BunnyPluginManifest } from "@lib/addons/plugins/types";
import { showToast } from "@lib/ui/toasts";
import { safeFetch } from "@lib/utils";
import { OFFICIAL_PLUGINS_REPO_URL } from "@lib/utils/constants";
Expand Down Expand Up @@ -41,7 +41,7 @@ async function* getManifests(repoUrl: string) {

function InstallButton(props: { id: string; }) {
const [installed, setInstalled] = useState(isPluginInstalled(props.id));
const installationState = useMutation<void, Error, { install: boolean }>({
const installationState = useMutation<void, Error, { install: boolean; }>({
mutationFn: async ({ install }) => {
await (install ? installPlugin : uninstallPlugin)(props.id, true);
},
Expand All @@ -63,11 +63,11 @@ function InstallButton(props: { id: string; }) {
/>;
}

function TrailingButtons(props: { id: string }) {
function TrailingButtons(props: { id: string; }) {
return <Stack spacing={8} direction="horizontal">
<IconButton
size="sm"
onPress={() => {}}
onPress={() => { }}
variant="secondary"
icon={findAssetId("CircleInformationIcon")}
/>
Expand Down
6 changes: 3 additions & 3 deletions src/core/ui/settings/pages/Plugins/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { useProxy as useNewProxy } from "@lib/api/storage/new";
import { showToast } from "@lib/ui/toasts";
import { BUNNY_PROXY_PREFIX, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { Author } from "@lib/utils/types";
import { findByProps } from "@metro";
import { NavigationNative, tokens } from "@metro/common";
import { Card, FlashList, IconButton, PressableScale, Stack, Text } from "@metro/common/components";
import { ComponentProps } from "react";
import { Image, View } from "react-native";

import unifyVdPlugin from "./models/vendetta";
import { isCorePlugin, isPluginInstalled, pluginSettings, registeredPlugins } from "@lib/plugins";
import { isCorePlugin, isPluginInstalled, pluginSettings, registeredPlugins } from "@lib/addons/plugins";
import unifyBunnyPlugin from "./models/bunny";
import { createStyles } from "@lib/ui/styles";
import { Author } from "@lib/addons/types";

const useStyles = createStyles({
xButton: {
Expand All @@ -33,7 +33,7 @@ export interface UnifiedPluginModel {
id: string;
name: string;
description?: string;
authors?: Array<Author | string>;
authors?: Author;
icon?: string;

isEnabled(): boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/core/ui/settings/pages/Plugins/models/bunny.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useProxy } from "@lib/api/storage/new";
import { disablePlugin, enablePlugin, getId, getPluginSettingsComponent, isPluginEnabled, pluginSettings } from "@lib/plugins";
import { BunnyPluginManifest } from "@lib/plugins/types";
import { disablePlugin, enablePlugin, getId, getPluginSettingsComponent, isPluginEnabled, pluginSettings } from "@lib/addons/plugins";
import { BunnyPluginManifest } from "@lib/addons/plugins/types";

import { UnifiedPluginModel } from "..";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { formatString, Strings } from "@core/i18n";
import { VdPluginManager } from "@core/vendetta/plugins";
import { findAssetId } from "@lib/api/assets";
import { purgeStorage } from "@lib/api/storage";
import { ButtonColors } from "@lib/utils/types";
import { clipboard } from "@metro/common";
import { ActionSheet, ActionSheetRow, Button, TableRow, Text } from "@metro/common/components";
import { showConfirmationAlert } from "@ui/alerts";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { hideSheet } from "@ui/sheets";
import { showToast } from "@ui/toasts";
import { ScrollView, View } from "react-native";
Expand Down Expand Up @@ -85,7 +84,7 @@ export default function PluginInfoActionSheet({ plugin, navigation }: PluginInfo
content: formatString("ARE_YOU_SURE_TO_CLEAR_DATA", { name: plugin.name }),
confirmText: Strings.CLEAR,
cancelText: Strings.CANCEL,
confirmColor: ButtonColors.RED,
confirmColor: "red",
onConfirm: async () => {
if (vdPlugin.enabled) VdPluginManager.stopPlugin(plugin.id, false);

Expand Down Expand Up @@ -122,7 +121,7 @@ export default function PluginInfoActionSheet({ plugin, navigation }: PluginInfo
content: formatString("ARE_YOU_SURE_TO_DELETE_PLUGIN", { name: plugin.name }),
confirmText: Strings.DELETE,
cancelText: Strings.CANCEL,
confirmColor: ButtonColors.RED,
confirmColor: "red",
onConfirm: () => {
try {
VdPluginManager.removePlugin(plugin.id);
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 @@ -3,10 +3,9 @@ import AddonCard, { CardWrapper } from "@core/ui/components/AddonCard";
import { findAssetId } from "@lib/api/assets";
import { settings } from "@lib/api/settings";
import { useProxy } from "@lib/api/storage";
import { applyTheme, fetchTheme, removeTheme, selectTheme, Theme, themes } from "@lib/themes";
import { ButtonColors } from "@lib/utils/types";
import { applyTheme, fetchTheme, removeTheme, selectTheme, Theme, themes } from "@lib/addons/themes";
import { clipboard } from "@metro/common";
import { showConfirmationAlert } from "@ui/alerts";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { showToast } from "@ui/toasts";

function selectAndApply(value: boolean, theme: Theme) {
Expand Down Expand Up @@ -68,7 +67,7 @@ export default function ThemeCard({ item: theme }: CardWrapper<Theme>) {
content: formatString("ARE_YOU_SURE_TO_DELETE_THEME", { name: theme.data.name }),
confirmText: Strings.DELETE,
cancelText: Strings.CANCEL,
confirmColor: ButtonColors.RED,
confirmColor: "red",
onConfirm: () => {
removeTheme(theme.id).then(wasSelected => {
setRemoved(true);
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 @@ -3,9 +3,9 @@ import AddonPage from "@core/ui/components/AddonPage";
import ThemeCard from "@core/ui/settings/pages/Themes/ThemeCard";
import { settings } from "@lib/api/settings";
import { useProxy } from "@lib/api/storage";
import { installTheme, Theme, themes } from "@lib/themes";
import { Author } from "@lib/utils/types";
import { installTheme, Theme, themes } from "@lib/addons/themes";
import { Button } from "@metro/common/components";
import { Author } from "@lib/addons/types";

export default function Themes() {
useProxy(settings);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/ui/alerts.ts → src/core/vendetta/alerts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ButtonColors } from "@lib/utils/types";
import { findByPropsLazy } from "@metro/wrappers";
import InputAlert, { InputAlertProps } from "@ui/components/InputAlert";

Expand All @@ -13,7 +12,7 @@ export interface ConfirmationAlertOptions {
title?: string;
content: string | JSX.Element | (string | JSX.Element)[];
confirmText?: string;
confirmColor?: ButtonColors;
confirmColor?: string;
onConfirm: () => void;
secondaryConfirmText?: string;
onConfirmSecondary?: () => void;
Expand Down
8 changes: 4 additions & 4 deletions src/core/vendetta/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import patcher from "@lib/api/patcher";
import { loaderConfig, settings } from "@lib/api/settings";
import * as storage from "@lib/api/storage";
import { createStorage } from "@lib/api/storage";
import * as themes from "@lib/themes";
import * as themes from "@lib/addons/themes";
import * as utils from "@lib/utils";
import { cyrb64Hash } from "@lib/utils/cyrb64";
import { DiscordLogger } from "@lib/utils/logger";
import { LoggerClass } from "@lib/utils/logger";
import * as metro from "@metro";
import * as common from "@metro/common";
import { Forms } from "@metro/common/components";
import * as commonComponents from "@metro/common/components";
import * as alerts from "@ui/alerts";
import * as alerts from "@core/vendetta/alerts";
import * as color from "@ui/color";
import * as components from "@ui/components";
import { createThemedStyleSheet } from "@ui/styles";
Expand All @@ -34,7 +34,7 @@ export async function createVdPluginObject(plugin: VendettaPlugin) {
// Wrapping this with wrapSync is NOT an option.
storage: await createStorage<Record<string, any>>(storage.createMMKVBackend(plugin.id)),
},
logger: new DiscordLogger(`Bunny » ${plugin.manifest.name}`),
logger: new LoggerClass(`Bunny » ${plugin.manifest.name}`),
};
}

Expand Down
14 changes: 8 additions & 6 deletions src/core/vendetta/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Author } from "@lib/addons/types";
import { settings } from "@lib/api/settings";
import { awaitStorage, createMMKVBackend, createStorage, purgeStorage, wrapSync } from "@lib/api/storage";
import { safeFetch } from "@lib/utils";
import { BUNNY_PROXY_PREFIX, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { DiscordLogger, logger } from "@lib/utils/logger";
import { Author } from "@lib/utils/types";
import { LoggerClass, logger } from "@lib/utils/logger";

type EvaledPlugin = {
onLoad?(): void;
Expand Down Expand Up @@ -39,7 +39,9 @@ export const VdPluginManager = {
plugins,
async pluginFetch(url: string) {
if (url.startsWith(VD_PROXY_PREFIX)) {
url = url.replace(VD_PROXY_PREFIX, BUNNY_PROXY_PREFIX);
url = url
.replace("https://bunny-mod.github.io/plugins-proxy", BUNNY_PROXY_PREFIX)
.replace(VD_PROXY_PREFIX, BUNNY_PROXY_PREFIX);
}

return await safeFetch(url, { cache: "no-store" });
Expand All @@ -61,7 +63,7 @@ export const VdPluginManager = {

if (existingPlugin?.manifest.hash !== pluginManifest.hash) {
try {
// by polymanifest spec, plugins should always specify their main file, but just in case
// by polymanifest spec, plugins should always specify their main file, but just in case
pluginJs = await (await this.pluginFetch(id + (pluginManifest.main || "index.js"))).text();
} catch { } // Empty catch, checked below
}
Expand Down Expand Up @@ -96,7 +98,7 @@ export const VdPluginManager = {
// Wrapping this with wrapSync is NOT an option.
storage: await createStorage<Record<string, any>>(createMMKVBackend(plugin.id)),
},
logger: new DiscordLogger(`Bunny » ${plugin.manifest.name}`),
logger: new LoggerClass(`Bunny » ${plugin.manifest.name}`),
};
const pluginString = `vendetta=>{return ${plugin.js}}\n//# sourceURL=${plugin.id}`;

Expand Down Expand Up @@ -166,7 +168,7 @@ export const VdPluginManager = {
const allIds = Object.keys(plugins);

if (!settings.safeMode?.enabled) {
// Loop over any plugin that is enabled, update it if allowed, then start it.
// Loop over any plugin that is enabled, update it if allowed, then start it.
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
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { patchJSX } from "@lib/api/jsx";
import { removeFile, writeFile } from "@lib/api/native/fs";
import { isPyonLoader, isThemeSupported } from "@lib/api/native/loader";
import { FileManager } from "@lib/api/native/modules";
import { updateFonts } from "@lib/fonts";
import { initPlugins, registerCorePlugins } from "@lib/plugins";
import { initThemes, patchChatBackground } from "@lib/themes";
import { updateFonts } from "@lib/addons/fonts";
import { initPlugins, registerCorePlugins } from "@lib/addons/plugins";
import { initThemes, patchChatBackground } from "@lib/addons/themes";
import { logger } from "@lib/utils/logger";
import initSafeMode from "@ui/safeMode";
import { patchSettings } from "@ui/settings";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/lib/plugins/types.ts → src/lib/addons/plugins/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createStorage } from "@lib/api/storage";
import { Logger } from "@lib/utils/logger";
import { Author } from "@lib/utils/types";
import { Author } from "../types";

export interface PluginRepo {
[id: string]: {
Expand All @@ -26,7 +26,7 @@ export interface BunnyPluginManifest {
readonly name: string;
readonly description: string;
readonly version: string;
readonly authors: (Author | string)[];
readonly authors: Author[];
}

export interface BunnyPluginManifestInternal extends BunnyPluginManifest {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/themes/index.ts → src/lib/addons/themes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { after, before, instead } from "@lib/api/patcher";
import { awaitStorage, createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@lib/api/storage";
import { findInReactTree, safeFetch } from "@lib/utils";
import { lazyDestructure, proxyLazy } from "@lib/utils/lazy";
import { Author } from "@lib/utils/types";
import { byMutableProp } from "@metro/filters";
import { createLazyModule } from "@metro/lazy";
import { findByNameLazy, findByProps, findByPropsLazy, findByStoreNameLazy } from "@metro/wrappers";
import chroma from "chroma-js";
import { ImageBackground, Platform, processColor } from "react-native";
import { Author } from "../types";

export interface ThemeData {
name: string;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/addons/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Author {
name: string;
id: string;
}
Loading

0 comments on commit f2f1f6a

Please sign in to comment.