Skip to content

Commit

Permalink
chore: some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Oct 13, 2024
1 parent dc81e9c commit fd8ddce
Show file tree
Hide file tree
Showing 43 changed files with 127 additions and 151 deletions.
2 changes: 1 addition & 1 deletion src/core/plugins/badges/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { onJsxCreate } from "@lib/api/react/jsx";
import { after } from "@lib/api/patcher";
import { onJsxCreate } from "@lib/api/react/jsx";
import { findByName } from "@metro";
import { useEffect, useState } from "react";

Expand Down
6 changes: 3 additions & 3 deletions src/core/plugins/quickinstall/forumPost.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Strings } from "@core/i18n";
import { VdPluginManager } from "@core/vendetta/plugins";
import { useProxy } from "@core/vendetta/storage";
import { installTheme, removeTheme, themes } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
import { isThemeSupported } from "@lib/api/native/loader";
import { after } from "@lib/api/patcher";
import { useProxy } from "@core/vendetta/storage";
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 { HTTP_REGEX_MULTI, VD_DISCORD_SERVER_ID, VD_PLUGINS_CHANNEL_ID, VD_PROXY_PREFIX, VD_THEMES_CHANNEL_ID } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { Button } from "@metro/common/components";
import { findByProps, findByPropsLazy } from "@metro/wrappers";
Expand Down
6 changes: 3 additions & 3 deletions src/core/plugins/quickinstall/url.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { formatString, Strings } from "@core/i18n";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { VdPluginManager } from "@core/vendetta/plugins";
import { installTheme } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
import { isThemeSupported } from "@lib/api/native/loader";
import { after, instead } from "@lib/api/patcher";
import { installTheme } from "@lib/addons/themes";
import { VD_THEMES_CHANNEL_ID, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { VD_PROXY_PREFIX,VD_THEMES_CHANNEL_ID } 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 "@core/vendetta/alerts";
import { showToast } from "@ui/toasts";

const showSimpleActionSheet = findExports(byMutableProp("showSimpleActionSheet"));
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/components/AddonPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CardWrapper } from "@core/ui/components/AddonCard";
import { useProxy } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import AlertModal, { AlertActionButton } from "@lib/ui/components/wrappers/AlertModal";
import isValidHttpUrl from "@lib/utils/isValidHttpUrl";
import { lazyDestructure } from "@lib/utils/lazy";
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import PyoncordIcon from "@assets/icons/pyoncord.png";
import { Strings } from "@core/i18n";
import { useProxy } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { isFontSupported, isThemeSupported } from "@lib/api/native/loader";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { registerSection } from "@ui/settings";
import { version } from "bunny-build-info";

Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/pages/Developer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Strings } from "@core/i18n";
import { CheckState, useFileExists } from "@core/ui/hooks/useFS";
import AssetBrowser from "@core/ui/settings/pages/Developer/AssetBrowser";
import { useProxy } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { connectToDebugger } from "@lib/api/debug";
import { getReactDevToolsProp, getReactDevToolsVersion, isLoaderConfigSupported, isReactDevToolsPreloaded, isVendettaLoader } from "@lib/api/native/loader";
import { loaderConfig, settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { lazyDestructure } from "@lib/utils/lazy";
import { NavigationNative } from "@metro/common";
import { Button, LegacyFormText, Stack, TableRow, TableRowGroup, TableSwitchRow, TextInput } from "@metro/common/components";
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
@@ -1,15 +1,15 @@
import { Strings } from "@core/i18n";
import { CardWrapper } from "@core/ui/components/AddonCard";
import { findAssetId } from "@lib/api/assets";
import { BundleUpdaterManager } from "@lib/api/native/modules";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { useProxy } from "@core/vendetta/storage";
import { FontDefinition, fonts, selectFont } from "@lib/addons/fonts";
import { findAssetId } from "@lib/api/assets";
import { BundleUpdaterManager } from "@lib/api/native/modules";
import { lazyDestructure } from "@lib/utils/lazy";
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 "@core/vendetta/alerts";
import { TextStyleSheet } from "@ui/styles";
import { useMemo } from "react";
import { View } from "react-native";
Expand Down
2 changes: 1 addition & 1 deletion 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 "@core/vendetta/storage";
import { FontDefinition, fonts, removeFont, saveFont, validateFont } from "@lib/addons/fonts";
import { getCurrentTheme } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
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
@@ -1,9 +1,9 @@
import { Strings } from "@core/i18n";
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 "@core/vendetta/storage";
import { FontDefinition, fonts } from "@lib/addons/fonts";
import { settings } from "@lib/api/settings";
import { NavigationNative } from "@metro/common";

import FontCard from "./FontCard";
Expand Down
2 changes: 1 addition & 1 deletion 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 "@core/vendetta/storage";
import { getDebugInfo } from "@lib/api/debug";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { Stack, TableRowGroup } from "@metro/common/components";
import { Platform, ScrollView } from "react-native";

Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/pages/General/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Strings } from "@core/i18n";
import { PyoncordIcon } from "@core/ui/settings";
import About from "@core/ui/settings/pages/General/About";
import { useProxy } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { getDebugInfo, toggleSafeMode } from "@lib/api/debug";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
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/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/addons/plugins";
import { BunnyPluginManifest } from "@lib/addons/plugins/types";
import { findAssetId } from "@lib/api/assets";
import { showToast } from "@lib/ui/toasts";
import { safeFetch } from "@lib/utils";
import { OFFICIAL_PLUGINS_REPO_URL } from "@lib/utils/constants";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NavigationNative, tokens } from "@metro/common";
import { Card, IconButton, Stack, TableSwitch, Text } from "@metro/common/components";
import { showSheet } from "@ui/sheets";
import chroma from "chroma-js";
import { createContext, memo, useContext, useMemo } from "react";
import { createContext, useContext, useMemo } from "react";
import { Image, View } from "react-native";

import { UnifiedPluginModel } from "..";
Expand Down
32 changes: 7 additions & 25 deletions src/core/ui/settings/pages/Plugins/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,24 @@ import { Strings } from "@core/i18n";
import AddonPage from "@core/ui/components/AddonPage";
import PluginCard from "@core/ui/settings/pages/Plugins/components/PluginCard";
import { VdPluginManager } from "@core/vendetta/plugins";
import { useProxy } from "@core/vendetta/storage";
import { isCorePlugin, isPluginInstalled, pluginSettings, registeredPlugins } from "@lib/addons/plugins";
import { Author } from "@lib/addons/types";
import { findAssetId } from "@lib/api/assets";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { useObservable } from "@lib/api/storage";
import { showToast } from "@lib/ui/toasts";
import { BUNNY_PROXY_PREFIX, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { findByProps } from "@metro";
import { NavigationNative, tokens } from "@metro/common";
import { Card, FlashList, IconButton, PressableScale, Stack, Text } from "@metro/common/components";
import { NavigationNative } from "@metro/common";
import { Card, FlashList, IconButton, Text } from "@metro/common/components";
import { ComponentProps } from "react";
import { Image, View } from "react-native";
import { View } from "react-native";

import unifyVdPlugin from "./models/vendetta";
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";
import unifyVdPlugin from "./models/vendetta";

const useStyles = createStyles({
xButton: {
position: "absolute",
right: 8,
top: 8,
tintColor: tokens.colors.INTERACTIVE_NORMAL
}
});
export interface UnifiedPluginModel {
id: string;
name: string;
Expand Down Expand Up @@ -89,20 +80,11 @@ export default function Plugins() {
return [...vdPlugins, ...bnPlugins];
}}
ListHeaderComponent={() => {
const styles = useStyles();
const unproxiedPlugins = Object.values(VdPluginManager.plugins).filter(p => !p.id.startsWith(VD_PROXY_PREFIX) && !p.id.startsWith(BUNNY_PROXY_PREFIX));
if (!unproxiedPlugins.length) return null;

return <View style={{ marginVertical: 12, marginHorizontal: 10 }}>
<Card border="strong">
{/* <PressableScale
style={styles.xButton}
onPress={() => {
}}
>
<Image source={findAssetId("XSmallIcon")} />
</PressableScale> */}
<View style={{ flex: 1, justifyContent: "center", alignItems: "center", flexDirection: "row" }}>
<View style={{ gap: 6, flexShrink: 1 }}>
<Text variant="heading-md/bold">Unproxied Plugins Found</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui/settings/pages/Plugins/models/bunny.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { disablePlugin, enablePlugin, getId, getPluginSettingsComponent, isPluginEnabled, pluginSettings } from "@lib/addons/plugins";
import { BunnyPluginManifest } from "@lib/addons/plugins/types";
import { useObservable } from "@lib/api/storage";

import { UnifiedPluginModel } from "..";
import { useObservable } from "@lib/api/storage";

export default function unifyBunnyPlugin(manifest: BunnyPluginManifest): UnifiedPluginModel {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { formatString, Strings } from "@core/i18n";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { VdPluginManager } from "@core/vendetta/plugins";
import { findAssetId } from "@lib/api/assets";
import { purgeStorage } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { clipboard } from "@metro/common";
import { ActionSheet, ActionSheetRow, Button, TableRow, Text } from "@metro/common/components";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { hideSheet } from "@ui/sheets";
import { showToast } from "@ui/toasts";
import { ScrollView, View } from "react-native";
Expand Down
6 changes: 3 additions & 3 deletions src/core/ui/settings/pages/Themes/ThemeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { formatString, Strings } from "@core/i18n";
import AddonCard, { CardWrapper } from "@core/ui/components/AddonCard";
import { findAssetId } from "@lib/api/assets";
import { settings } from "@lib/api/settings";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { useProxy } from "@core/vendetta/storage";
import { applyTheme, fetchTheme, removeTheme, selectTheme, Theme, themes } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
import { settings } from "@lib/api/settings";
import { clipboard } from "@metro/common";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { showToast } from "@ui/toasts";

function selectAndApply(value: boolean, theme: Theme) {
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
@@ -1,11 +1,11 @@
import { formatString, Strings } from "@core/i18n";
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 "@core/vendetta/storage";
import { installTheme, Theme, themes } from "@lib/addons/themes";
import { Button } from "@metro/common/components";
import { Author } from "@lib/addons/types";
import { settings } from "@lib/api/settings";
import { Button } from "@metro/common/components";

export default function Themes() {
useProxy(settings);
Expand Down
8 changes: 4 additions & 4 deletions src/core/vendetta/api.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as alerts from "@core/vendetta/alerts";
import * as storage from "@core/vendetta/storage";
import { createStorage } from "@core/vendetta/storage";
import * as themes from "@lib/addons/themes";
import * as assets from "@lib/api/assets";
import * as commands from "@lib/api/commands";
import * as debug from "@lib/api/debug";
import { getVendettaLoaderIdentity, isPyonLoader } from "@lib/api/native/loader";
import patcher from "@lib/api/patcher";
import { loaderConfig, settings } from "@lib/api/settings";
import * as storage from "@core/vendetta/storage";
import { createStorage } from "@core/vendetta/storage";
import * as themes from "@lib/addons/themes";
import * as utils from "@lib/utils";
import { cyrb64Hash } from "@lib/utils/cyrb64";
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 "@core/vendetta/alerts";
import * as color from "@ui/color";
import * as components from "@ui/components";
import { createThemedStyleSheet } from "@ui/styles";
Expand Down
4 changes: 2 additions & 2 deletions src/core/vendetta/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { awaitStorage, createMMKVBackend, createStorage, purgeStorage, wrapSync } from "@core/vendetta/storage";
import { Author } from "@lib/addons/types";
import { settings } from "@lib/api/settings";
import { awaitStorage, createMMKVBackend, createStorage, purgeStorage, wrapSync } from "@core/vendetta/storage";
import { safeFetch } from "@lib/utils";
import { BUNNY_PROXY_PREFIX, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { LoggerClass, logger } from "@lib/utils/logger";
import { logger,LoggerClass } from "@lib/utils/logger";

type EvaledPlugin = {
onLoad?(): void;
Expand Down
2 changes: 1 addition & 1 deletion src/core/vendetta/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const createFileBackend = (file: string, defaultData = {}, migratePromise
await FileManager.writeFile("documents", filePathFixer(file), JSON.stringify(defaultData), "utf8");
return JSON.parse(await FileManager.readFile(path, "utf8"));
},
set: async (data) => {
set: async data => {
await migratePromise;
await FileManager.writeFile("documents", filePathFixer(file), JSON.stringify(data), "utf8");
}
Expand Down
41 changes: 20 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,36 @@ import { initFetchI18nStrings } from "@core/i18n";
import initSettings from "@core/ui/settings";
import { initVendettaObject } from "@core/vendetta/api";
import { VdPluginManager } from "@core/vendetta/plugins";
import { updateFonts } from "@lib/addons/fonts";
import { initPlugins, updatePlugins } from "@lib/addons/plugins";
import { initThemes, patchChatBackground } from "@lib/addons/themes";
import { patchCommands } from "@lib/api/commands";
import { patchLogHook } from "@lib/api/debug";
import { injectFluxInterceptor } from "@lib/api/flux";
import { patchJsx } from "@lib/api/react/jsx";
import { removeFile, writeFile } from "@lib/api/native/fs";
import { 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/addons/fonts";
import { initPlugins, registerCorePlugins } from "@lib/addons/plugins";
import { initThemes, patchChatBackground } from "@lib/addons/themes";
import { patchJsx } from "@lib/api/react/jsx";
import { logger } from "@lib/utils/logger";
import initSafeMode from "@ui/safeMode";
import { patchSettings } from "@ui/settings";

import * as lib from "./lib";

export default async () => {
// Themes
if (isThemeSupported()) {
try {
if (isPyonLoader()) {
if (FileManager.removeFile != null) {
removeFile("vendetta_theme.json", "");
} else {
writeFile("vendetta_theme.json", "null", "");
}
}
initThemes();
} catch (e) {
console.error("[Bunny] Failed to initialize themes...", e);
function maybeLoadThemes() {
if (!isThemeSupported()) return;

try {
if (isPyonLoader()) {
writeFile("../vendetta_theme.json", "null");
}
initThemes();
} catch (e) {
console.error("Failed to initialize themes", e);
}
}

export default async () => {
maybeLoadThemes();

// Load everything in parallel
await Promise.all([
Expand All @@ -49,7 +47,7 @@ export default async () => {
initSettings(),
initFixes(),
initSafeMode(),
registerCorePlugins()
updatePlugins()
]).then(
// Push them all to unloader
u => u.forEach(f => f && lib.unload.push(f))
Expand All @@ -63,6 +61,7 @@ export default async () => {
.then(u => lib.unload.push(u))
.catch(() => alert("Failed to initialize Vendetta plugins"));

// And then, load Bunny plugins
initPlugins();

// Update the fonts
Expand Down
2 changes: 1 addition & 1 deletion src/lib/addons/fonts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clearFolder, downloadFile, fileExists, removeFile, writeFile } from "@lib/api/native/fs";
import { awaitStorage, createMMKVBackend, createStorage, wrapSync } from "@core/vendetta/storage";
import { clearFolder, downloadFile, fileExists, removeFile, writeFile } from "@lib/api/native/fs";
import { safeFetch } from "@lib/utils";

type FontMap = Record<string, string>;
Expand Down
Loading

0 comments on commit fd8ddce

Please sign in to comment.