From fd8ddce48b470cee7fa410ba956d2ae4fda0670f Mon Sep 17 00:00:00 2001 From: pylixonly <82711525+pylixonly@users.noreply.github.com> Date: Sun, 13 Oct 2024 14:03:20 +0800 Subject: [PATCH] chore: some cleanups --- src/core/plugins/badges/index.tsx | 2 +- src/core/plugins/quickinstall/forumPost.tsx | 6 +-- src/core/plugins/quickinstall/url.tsx | 6 +-- src/core/ui/components/AddonPage.tsx | 2 +- src/core/ui/settings/index.ts | 2 +- .../ui/settings/pages/Developer/index.tsx | 2 +- src/core/ui/settings/pages/Fonts/FontCard.tsx | 6 +-- .../ui/settings/pages/Fonts/FontEditor.tsx | 2 +- src/core/ui/settings/pages/Fonts/index.tsx | 2 +- src/core/ui/settings/pages/General/About.tsx | 2 +- src/core/ui/settings/pages/General/index.tsx | 2 +- .../ui/settings/pages/PluginBrowser/index.tsx | 2 +- .../pages/Plugins/components/PluginCard.tsx | 2 +- src/core/ui/settings/pages/Plugins/index.tsx | 32 +++---------- .../ui/settings/pages/Plugins/models/bunny.ts | 2 +- .../sheets/VdPluginInfoActionSheet.tsx | 4 +- .../ui/settings/pages/Themes/ThemeCard.tsx | 6 +-- src/core/ui/settings/pages/Themes/index.tsx | 4 +- src/core/vendetta/api.tsx | 8 ++-- src/core/vendetta/plugins.ts | 4 +- src/core/vendetta/storage.ts | 2 +- src/index.ts | 41 +++++++++-------- src/lib/addons/fonts/index.ts | 2 +- src/lib/addons/plugins/index.ts | 19 +++++++- src/lib/addons/plugins/types.ts | 2 +- src/lib/addons/themes/index.ts | 4 +- src/lib/addons/types.ts | 2 +- src/lib/api/debug.ts | 2 +- src/lib/api/index.ts | 2 +- src/lib/api/native/fs.ts | 45 +++++++------------ src/lib/api/native/modules/types.ts | 2 +- src/lib/api/react/index.ts | 2 +- src/lib/api/settings.ts | 2 +- src/lib/api/storage/index.ts | 4 +- src/lib/index.ts | 2 +- src/lib/ui/components/index.ts | 1 - src/lib/ui/components/wrappers/AlertModal.tsx | 24 ++++------ src/lib/ui/components/wrappers/index.ts | 2 +- src/lib/ui/index.ts | 2 +- src/lib/ui/settings/patches/panel.tsx | 2 +- src/lib/utils/findInTree.ts | 2 +- src/lib/utils/index.ts | 13 +++--- src/metro/internals/modules.ts | 1 - 43 files changed, 127 insertions(+), 151 deletions(-) diff --git a/src/core/plugins/badges/index.tsx b/src/core/plugins/badges/index.tsx index 9964c51..c8d7d10 100644 --- a/src/core/plugins/badges/index.tsx +++ b/src/core/plugins/badges/index.tsx @@ -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"; diff --git a/src/core/plugins/quickinstall/forumPost.tsx b/src/core/plugins/quickinstall/forumPost.tsx index 92234ef..25665ad 100644 --- a/src/core/plugins/quickinstall/forumPost.tsx +++ b/src/core/plugins/quickinstall/forumPost.tsx @@ -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"; diff --git a/src/core/plugins/quickinstall/url.tsx b/src/core/plugins/quickinstall/url.tsx index e02cc01..e2b8e12 100644 --- a/src/core/plugins/quickinstall/url.tsx +++ b/src/core/plugins/quickinstall/url.tsx @@ -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")); diff --git a/src/core/ui/components/AddonPage.tsx b/src/core/ui/components/AddonPage.tsx index 84d63d6..7122e39 100644 --- a/src/core/ui/components/AddonPage.tsx +++ b/src/core/ui/components/AddonPage.tsx @@ -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"; diff --git a/src/core/ui/settings/index.ts b/src/core/ui/settings/index.ts index 8c3e512..762d8d6 100644 --- a/src/core/ui/settings/index.ts +++ b/src/core/ui/settings/index.ts @@ -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"; diff --git a/src/core/ui/settings/pages/Developer/index.tsx b/src/core/ui/settings/pages/Developer/index.tsx index 4d3dff7..eccf76b 100644 --- a/src/core/ui/settings/pages/Developer/index.tsx +++ b/src/core/ui/settings/pages/Developer/index.tsx @@ -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"; diff --git a/src/core/ui/settings/pages/Fonts/FontCard.tsx b/src/core/ui/settings/pages/Fonts/FontCard.tsx index 4177204..c43c6b4 100644 --- a/src/core/ui/settings/pages/Fonts/FontCard.tsx +++ b/src/core/ui/settings/pages/Fonts/FontCard.tsx @@ -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"; diff --git a/src/core/ui/settings/pages/Fonts/FontEditor.tsx b/src/core/ui/settings/pages/Fonts/FontEditor.tsx index c7a8619..0f65caa 100644 --- a/src/core/ui/settings/pages/Fonts/FontEditor.tsx +++ b/src/core/ui/settings/pages/Fonts/FontEditor.tsx @@ -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"; diff --git a/src/core/ui/settings/pages/Fonts/index.tsx b/src/core/ui/settings/pages/Fonts/index.tsx index e0de3af..dac9a9d 100644 --- a/src/core/ui/settings/pages/Fonts/index.tsx +++ b/src/core/ui/settings/pages/Fonts/index.tsx @@ -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"; diff --git a/src/core/ui/settings/pages/General/About.tsx b/src/core/ui/settings/pages/General/About.tsx index 33cd504..35ec8c8 100644 --- a/src/core/ui/settings/pages/General/About.tsx +++ b/src/core/ui/settings/pages/General/About.tsx @@ -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"; diff --git a/src/core/ui/settings/pages/General/index.tsx b/src/core/ui/settings/pages/General/index.tsx index aa22431..6535325 100644 --- a/src/core/ui/settings/pages/General/index.tsx +++ b/src/core/ui/settings/pages/General/index.tsx @@ -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"; diff --git a/src/core/ui/settings/pages/PluginBrowser/index.tsx b/src/core/ui/settings/pages/PluginBrowser/index.tsx index 706cc4f..c1665de 100644 --- a/src/core/ui/settings/pages/PluginBrowser/index.tsx +++ b/src/core/ui/settings/pages/PluginBrowser/index.tsx @@ -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"; diff --git a/src/core/ui/settings/pages/Plugins/components/PluginCard.tsx b/src/core/ui/settings/pages/Plugins/components/PluginCard.tsx index 49b3495..a13330e 100644 --- a/src/core/ui/settings/pages/Plugins/components/PluginCard.tsx +++ b/src/core/ui/settings/pages/Plugins/components/PluginCard.tsx @@ -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 ".."; diff --git a/src/core/ui/settings/pages/Plugins/index.tsx b/src/core/ui/settings/pages/Plugins/index.tsx index 7e9b9de..05f852e 100644 --- a/src/core/ui/settings/pages/Plugins/index.tsx +++ b/src/core/ui/settings/pages/Plugins/index.tsx @@ -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; @@ -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 - {/* { - - }} - > - - */} Unproxied Plugins Found diff --git a/src/core/ui/settings/pages/Plugins/models/bunny.ts b/src/core/ui/settings/pages/Plugins/models/bunny.ts index f59db4f..5b5c583 100644 --- a/src/core/ui/settings/pages/Plugins/models/bunny.ts +++ b/src/core/ui/settings/pages/Plugins/models/bunny.ts @@ -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 { diff --git a/src/core/ui/settings/pages/Plugins/sheets/VdPluginInfoActionSheet.tsx b/src/core/ui/settings/pages/Plugins/sheets/VdPluginInfoActionSheet.tsx index 7e45498..7701c26 100644 --- a/src/core/ui/settings/pages/Plugins/sheets/VdPluginInfoActionSheet.tsx +++ b/src/core/ui/settings/pages/Plugins/sheets/VdPluginInfoActionSheet.tsx @@ -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"; diff --git a/src/core/ui/settings/pages/Themes/ThemeCard.tsx b/src/core/ui/settings/pages/Themes/ThemeCard.tsx index b8a90ec..4934d20 100644 --- a/src/core/ui/settings/pages/Themes/ThemeCard.tsx +++ b/src/core/ui/settings/pages/Themes/ThemeCard.tsx @@ -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) { diff --git a/src/core/ui/settings/pages/Themes/index.tsx b/src/core/ui/settings/pages/Themes/index.tsx index afb18ad..8bdb1cf 100644 --- a/src/core/ui/settings/pages/Themes/index.tsx +++ b/src/core/ui/settings/pages/Themes/index.tsx @@ -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); diff --git a/src/core/vendetta/api.tsx b/src/core/vendetta/api.tsx index dd7c8d6..456c063 100644 --- a/src/core/vendetta/api.tsx +++ b/src/core/vendetta/api.tsx @@ -1,12 +1,13 @@ +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"; @@ -14,7 +15,6 @@ 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"; diff --git a/src/core/vendetta/plugins.ts b/src/core/vendetta/plugins.ts index eca7e99..f091f66 100644 --- a/src/core/vendetta/plugins.ts +++ b/src/core/vendetta/plugins.ts @@ -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; diff --git a/src/core/vendetta/storage.ts b/src/core/vendetta/storage.ts index a21eaf7..19ce87c 100644 --- a/src/core/vendetta/storage.ts +++ b/src/core/vendetta/storage.ts @@ -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"); } diff --git a/src/index.ts b/src/index.ts index e496394..6785e50 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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([ @@ -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)) @@ -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 diff --git a/src/lib/addons/fonts/index.ts b/src/lib/addons/fonts/index.ts index 6d2c62e..157318d 100644 --- a/src/lib/addons/fonts/index.ts +++ b/src/lib/addons/fonts/index.ts @@ -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; diff --git a/src/lib/addons/plugins/index.ts b/src/lib/addons/plugins/index.ts index fe80c8c..d14363d 100644 --- a/src/lib/addons/plugins/index.ts +++ b/src/lib/addons/plugins/index.ts @@ -351,9 +351,24 @@ export function stopPlugin(id: string) { pluginInstances.delete(id); } -export async function registerCorePlugins() { +async function updateAllRepository() { + try { + await updateRepository(OFFICIAL_PLUGINS_REPO_URL); + } catch (error) { + console.error("Failed to update official plugins repository", error); + } + + await Promise.allSettled(Object.keys(pluginRepositories).map(async repo => { + if (repo !== OFFICIAL_PLUGINS_REPO_URL) { + await updateRepository(repo); + } + })); +} + +export async function updatePlugins() { await awaitStorage(pluginRepositories, pluginSettings); + // Register core plugins const corePlugins = getCorePlugins(); for (const id in corePlugins) { const { @@ -370,6 +385,8 @@ export async function registerCorePlugins() { manifestToId.set(instance.manifest, id); corePluginInstances.set(id, instance); } + + await updateAllRepository(); } /** diff --git a/src/lib/addons/plugins/types.ts b/src/lib/addons/plugins/types.ts index f519e1c..fb7027a 100644 --- a/src/lib/addons/plugins/types.ts +++ b/src/lib/addons/plugins/types.ts @@ -1,6 +1,6 @@ import { createStorage } from "@core/vendetta/storage"; +import { Author } from "@lib/addons/types"; import { Logger } from "@lib/utils/logger"; -import { Author } from "../types"; export interface PluginRepo { [id: string]: { diff --git a/src/lib/addons/themes/index.ts b/src/lib/addons/themes/index.ts index aaffeb6..b610474 100644 --- a/src/lib/addons/themes/index.ts +++ b/src/lib/addons/themes/index.ts @@ -2,10 +2,11 @@ * Theming system in Bunny is currently a prototype, expect an unreadable theme implementation below */ +import { awaitStorage, createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@core/vendetta/storage"; +import { Author } from "@lib/addons/types"; import { getStoredTheme, getThemeFilePath } from "@lib/api/native/loader"; import { ThemeManager } from "@lib/api/native/modules"; import { after, before, instead } from "@lib/api/patcher"; -import { awaitStorage, createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@core/vendetta/storage"; import { findInReactTree, safeFetch } from "@lib/utils"; import { lazyDestructure, proxyLazy } from "@lib/utils/lazy"; import { byMutableProp } from "@metro/filters"; @@ -13,7 +14,6 @@ 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; diff --git a/src/lib/addons/types.ts b/src/lib/addons/types.ts index 8294644..29065ea 100644 --- a/src/lib/addons/types.ts +++ b/src/lib/addons/types.ts @@ -1,4 +1,4 @@ export interface Author { name: string; id: string; -} \ No newline at end of file +} diff --git a/src/lib/api/debug.ts b/src/lib/api/debug.ts index f42659d..05de186 100644 --- a/src/lib/api/debug.ts +++ b/src/lib/api/debug.ts @@ -1,9 +1,9 @@ +import { getThemeFromLoader, selectTheme, themes } from "@lib/addons/themes"; import { findAssetId } from "@lib/api/assets"; import { getLoaderName, getLoaderVersion, isThemeSupported } from "@lib/api/native/loader"; import { BundleUpdaterManager, ClientInfoManager, DeviceManager } from "@lib/api/native/modules"; import { after } from "@lib/api/patcher"; import { settings } from "@lib/api/settings"; -import { getThemeFromLoader, selectTheme, themes } from "@lib/addons/themes"; import { logger } from "@lib/utils/logger"; import { showToast } from "@ui/toasts"; import { version } from "bunny-build-info"; diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 081fd14..4d9057a 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -4,6 +4,6 @@ export * as debug from "./debug"; export * as flux from "./flux"; export * as native from "./native"; export * as patcher from "./patcher"; +export * as react from "./react"; export * as settings from "./settings"; export * as storage from "./storage"; -export * as react from "./react"; diff --git a/src/lib/api/native/fs.ts b/src/lib/api/native/fs.ts index 43cd3d0..d32b835 100644 --- a/src/lib/api/native/fs.ts +++ b/src/lib/api/native/fs.ts @@ -4,7 +4,7 @@ import { FileManager } from "./modules"; * Removes all files in a directory from the path given * @param path Path to the targeted directory */ -export async function clearFolder(path: string, prefix = "pyoncord/") { +export async function clearFolder(path: string, { prefix = "pyoncord/" } = {}) { if (typeof FileManager.clearFolder !== "function") throw new Error("'fs.clearFolder' is not supported"); return void await FileManager.clearFolder("documents", `${prefix}${path}`); } @@ -13,7 +13,7 @@ export async function clearFolder(path: string, prefix = "pyoncord/") { * Remove file from given path, currently no check for any failure * @param path Path to the file */ -export async function removeFile(path: string, prefix = "pyoncord/") { +export async function removeFile(path: string, { prefix = "pyoncord/" } = {}) { if (typeof FileManager.removeFile !== "function") throw new Error("'fs.removeFile' is not supported"); return void await FileManager.removeFile("documents", `${prefix}${path}`); } @@ -22,7 +22,7 @@ export async function removeFile(path: string, prefix = "pyoncord/") { * Check if the file or directory given by the path exists * @param path Path to the file */ -export async function fileExists(path: string, prefix = "pyoncord/") { +export async function fileExists(path: string, { prefix = "pyoncord/" } = {}) { return await FileManager.fileExists(`${FileManager.getConstants().DocumentsDirPath}/${prefix}${path}`); } @@ -31,7 +31,7 @@ export async function fileExists(path: string, prefix = "pyoncord/") { * @param path Path to the file * @param data String data to write to the file */ -export async function writeFile(path: string, data: string, prefix = "pyoncord/"): Promise { +export async function writeFile(path: string, data: string, { prefix = "pyoncord/" } = {}): Promise { if (typeof data !== "string") throw new Error("Argument 'data' must be a string"); return void await FileManager.writeFile("documents", `${prefix}${path}`, data, "utf8"); } @@ -41,7 +41,7 @@ export async function writeFile(path: string, data: string, prefix = "pyoncord/" * @param path Path to the file * @param fallback Fallback data to return if the file doesn't exist, and will be written to the file */ -export async function readFile(path: string, prefix = "pyoncord/"): Promise { +export async function readFile(path: string, { prefix = "pyoncord/" } = {}): Promise { try { return await FileManager.readFile(`${FileManager.getConstants().DocumentsDirPath}/${prefix}${path}`, "utf8"); } catch (err) { @@ -49,30 +49,19 @@ export async function readFile(path: string, prefix = "pyoncord/"): Promise r.blob()); - const dataURL: string | null = await new Promise(r => { - const reader = new FileReader(); - reader.onload = () => r(reader.result as unknown as string); - reader.readAsDataURL(blob); - }); - - let data: string; - if (dataURL == null) { - throw new Error("Failed to convert blob to data URL"); - } else { - const index = dataURL.indexOf("base64,"); - if (index === -1) throw new Error("dataURL does not contain base64"); - data = dataURL.slice(index + 7); +/** + * Download a file from the given URL and save it to the path given + * @param url URL to download the file from + * @param path Path to save the file to + */ +export async function downloadFile(url: string, path: string, { prefix = "pyoncord/" } = {}) { + const response = await fetch(url); + if (!response.ok) { + throw new Error(`Failed to download file from ${url}: ${response.statusText}`); } + const arrayBuffer = await response.arrayBuffer(); + const data = Buffer.from(arrayBuffer).toString("base64"); + return void await FileManager.writeFile("documents", `${prefix}${path}`, data, "base64"); } - -// // thanks Rosie, doesnt work though -// export async function downloadFile(url: string, path: string, prefix = "pyoncord/") { -// const arrayBuffer = await fetch(url).then(r => r.arrayBuffer()); -// const data = Buffer.from(arrayBuffer).toString("base64"); - -// return void await FileManager.writeFile("documents", `${prefix}${path}`, data, "base64"); -// } diff --git a/src/lib/api/native/modules/types.ts b/src/lib/api/native/modules/types.ts index 99f83d7..4fd4501 100644 --- a/src/lib/api/native/modules/types.ts +++ b/src/lib/api/native/modules/types.ts @@ -86,4 +86,4 @@ export namespace RNModules { */ DocumentsDirPath: string; } -} \ No newline at end of file +} diff --git a/src/lib/api/react/index.ts b/src/lib/api/react/index.ts index e7c5695..03149cd 100644 --- a/src/lib/api/react/index.ts +++ b/src/lib/api/react/index.ts @@ -1 +1 @@ -export * as jsx from "./jsx"; \ No newline at end of file +export * as jsx from "./jsx"; diff --git a/src/lib/api/settings.ts b/src/lib/api/settings.ts index 183fcd9..a0feff5 100644 --- a/src/lib/api/settings.ts +++ b/src/lib/api/settings.ts @@ -1,5 +1,5 @@ -import { getLoaderConfigPath } from "@lib/api/native/loader"; import { createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@core/vendetta/storage"; +import { getLoaderConfigPath } from "@lib/api/native/loader"; export interface Settings { debuggerUrl: string; diff --git a/src/lib/api/storage/index.ts b/src/lib/api/storage/index.ts index 9ee33ad..f123466 100644 --- a/src/lib/api/storage/index.ts +++ b/src/lib/api/storage/index.ts @@ -1,6 +1,6 @@ +import { Emitter } from "@core/vendetta/Emitter"; import { Observable, ObserverOptions } from "@gullerya/object-observer"; import { fileExists, readFile, removeFile, writeFile } from "@lib/api/native/fs"; -import { Emitter } from "@core/vendetta/Emitter"; import { debounce } from "es-toolkit"; const storageInitErrorSymbol = Symbol.for("bunny.storage.initError"); @@ -187,4 +187,4 @@ export function awaitStorage(...proxies: any[]) { /** @internal */ export function getPreloadedStorage(path: string): T | undefined { return _loadedStorage[path]; -} \ No newline at end of file +} diff --git a/src/lib/index.ts b/src/lib/index.ts index 98c7edb..ba8ecac 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,10 +1,10 @@ import "../global.d.ts"; // eslint-disable-line import-alias/import-alias import "../modules.d.ts"; // eslint-disable-line import-alias/import-alias -export * as api from "./api"; export * as fonts from "./addons/fonts/index.js"; export * as plugins from "./addons/plugins/index.js"; export * as themes from "./addons/themes/index.js"; +export * as api from "./api"; export * as ui from "./ui"; export * as utils from "./utils"; export * as metro from "@metro"; diff --git a/src/lib/ui/components/index.ts b/src/lib/ui/components/index.ts index 4c938bd..b6d6f2e 100644 --- a/src/lib/ui/components/index.ts +++ b/src/lib/ui/components/index.ts @@ -1,5 +1,4 @@ export * as wrappers from "./wrappers"; - export { default as Codeblock } from "@ui/components/Codeblock"; export { default as ErrorBoundary } from "@ui/components/ErrorBoundary"; export { default as Search } from "@ui/components/Search"; diff --git a/src/lib/ui/components/wrappers/AlertModal.tsx b/src/lib/ui/components/wrappers/AlertModal.tsx index 7694407..58ab079 100644 --- a/src/lib/ui/components/wrappers/AlertModal.tsx +++ b/src/lib/ui/components/wrappers/AlertModal.tsx @@ -1,34 +1,28 @@ import { lazyDestructure } from "@lib/utils/lazy"; -import { findByProps } from "@metro"; +import { findByFilePath, findByProps } from "@metro"; import { Text } from "@metro/common/components"; import { Button } from "@metro/common/types/components"; import { ComponentProps, ComponentType, ReactNode } from "react"; -import { useWindowDimensions, View } from "react-native"; +import { View } from "react-native"; + +type ActionButtonProps = Omit, "onPress"> & { + onPress?: () => void | Promise; +}; const { AlertModal: _AlertModal, AlertActionButton: _AlertActionButton } = lazyDestructure(() => findByProps("AlertModal", "AlertActions")); -type ActionButtonProps = Omit, "onPress"> & { - onPress?: () => void | Promise; -}; - export const AlertActionButton = _AlertActionButton as ComponentType; export default function AlertModal(props: Record) { - const { width: windowWidth } = useWindowDimensions(); + const forwardFailedModal = findByFilePath("modules/forwarding/native/ForwardFailedAlertModal.tsx"); // ponyfill for extraContent - if ("extraContent" in props) { + if (!forwardFailedModal && "extraContent" in props) { props.content = ( - + {props.content as string} diff --git a/src/lib/ui/components/wrappers/index.ts b/src/lib/ui/components/wrappers/index.ts index 06db762..0a6cdd8 100644 --- a/src/lib/ui/components/wrappers/index.ts +++ b/src/lib/ui/components/wrappers/index.ts @@ -1,3 +1,3 @@ import AlertModal, { AlertActionButton } from "./AlertModal"; -export { AlertModal, AlertActionButton }; \ No newline at end of file +export { AlertActionButton, AlertModal }; diff --git a/src/lib/ui/index.ts b/src/lib/ui/index.ts index 8f250f0..f4c027e 100644 --- a/src/lib/ui/index.ts +++ b/src/lib/ui/index.ts @@ -1,6 +1,6 @@ export * as components from "./components"; export * as settings from "./settings"; +export * as sheets from "./sheets"; export * as styles from "./styles"; export * as toasts from "./toasts"; -export * as sheets from "./sheets"; diff --git a/src/lib/ui/settings/patches/panel.tsx b/src/lib/ui/settings/patches/panel.tsx index cad3a23..e54a2e4 100644 --- a/src/lib/ui/settings/patches/panel.tsx +++ b/src/lib/ui/settings/patches/panel.tsx @@ -1,7 +1,7 @@ import { after } from "@lib/api/patcher"; import { findInReactTree } from "@lib/utils"; import { i18n, NavigationNative } from "@metro/common"; -import { LegacyFormIcon, LegacyFormRow, LegacyFormSection, LegacyFormDivider } from "@metro/common/components"; +import { LegacyFormDivider,LegacyFormIcon, LegacyFormRow, LegacyFormSection } from "@metro/common/components"; import { findByNameLazy } from "@metro/wrappers"; import { registeredSections } from "@ui/settings"; diff --git a/src/lib/utils/findInTree.ts b/src/lib/utils/findInTree.ts index 279480c..5dae4a8 100644 --- a/src/lib/utils/findInTree.ts +++ b/src/lib/utils/findInTree.ts @@ -50,4 +50,4 @@ export default function findInTree( }: FindInTreeOptions = {}, ): any | undefined { return treeSearch(tree, filter, { walkable, ignore, maxDepth }, 0); -}; \ No newline at end of file +} diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 931e832..75f6d25 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -1,23 +1,20 @@ +import * as constants from "./constants"; import cyrb64 from "./cyrb64"; import findInReactTree from "./findInReactTree"; import findInTree from "./findInTree"; import hookDefineProperty from "./hookDefineProperty"; import invariant from "./invariant"; -import safeFetch from "./safeFetch"; - -import * as constants from "./constants"; import * as lazy from "./lazy"; import * as logger from "./logger"; +import safeFetch from "./safeFetch"; export { + constants, cyrb64, findInReactTree, findInTree, hookDefineProperty, invariant, - safeFetch, - - constants, lazy, - logger -}; \ No newline at end of file + logger, + safeFetch }; diff --git a/src/metro/internals/modules.ts b/src/metro/internals/modules.ts index 7bd65f0..d2a0cf8 100644 --- a/src/metro/internals/modules.ts +++ b/src/metro/internals/modules.ts @@ -100,7 +100,6 @@ function onModuleRequire(moduleExports: any, id: Metro.ModuleID) { patchedNativeComponentRegistry = true; } - // Hook DeveloperExperimentStore if (moduleExports?.default?.constructor?.displayName === "DeveloperExperimentStore") { moduleExports.default = new Proxy(moduleExports.default, {