diff --git a/src/core/ui/settings/pages/Plugins/PluginCard.tsx b/src/core/ui/settings/pages/Plugins/PluginCard.tsx index 5cc1d6b..038f9b7 100644 --- a/src/core/ui/settings/pages/Plugins/PluginCard.tsx +++ b/src/core/ui/settings/pages/Plugins/PluginCard.tsx @@ -1,27 +1,25 @@ 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 { lazyDestructure } from "@lib/utils/lazy"; -import { findByProps } from "@metro"; import { NavigationNative } from "@metro/common"; import { Card, IconButton, Stack, TableSwitch, Text } from "@metro/common/components"; import { showSheet } from "@ui/sheets"; import { createContext, memo, useContext } from "react"; import { Image, View } from "react-native"; +import { PluginManifest } from "."; import { usePluginCardStyles } from "./usePluginCardStyles"; -const { useToken } = lazyDestructure(() => findByProps("useToken")); -const PluginContext = createContext(null!); +const PluginContext = createContext(null!); const usePlugin = () => useContext(PluginContext); function Authors() { const plugin = usePlugin(); + if (!plugin.authors) return null; + const children = ["by "]; - for (const author of plugin.manifest.authors) { - children.push(author.name); + for (const author of plugin.authors) { + children.push(typeof author === "string" ? author : author.name); children.push(", "); } @@ -36,15 +34,14 @@ function Title() { const styles = usePluginCardStyles(); const plugin = usePlugin(); - const iconName = plugin.manifest.vendetta?.icon; - const icon = iconName && findAssetId(iconName); + const icon = plugin.icon && findAssetId(plugin.icon); const textElement = ( - {plugin.manifest.name} + {plugin.name} ); @@ -94,10 +91,10 @@ const Actions = memo(() => { size="sm" variant="secondary" icon={findAssetId("WrenchIcon")} - disabled={!VdPluginManager.getSettings(plugin.id)} + disabled={!plugin.getPluginSettingsComponent()} onPress={() => navigation.push("VendettaCustomPage", { - title: plugin.manifest.name, - render: VdPluginManager.getSettings(plugin.id), + title: plugin.name, + render: plugin.getPluginSettingsComponent(), })} /> { icon={findAssetId("CircleInformationIcon-primary")} onPress={() => void showSheet( "PluginInfoActionSheet", - import("./sheets/PluginInfoActionSheet"), + plugin.resolveSheetComponent(), { plugin, navigation } )} /> ; }); -export default function PluginCard({ item: plugin }: CardWrapper) { - useProxy(plugin); +export default function PluginCard({ item: plugin }: CardWrapper) { + plugin.usePluginState(); return ( @@ -130,17 +127,16 @@ export default function PluginCard({ item: plugin }: CardWrapper { - if (v) VdPluginManager.startPlugin(plugin.id); - else VdPluginManager.stopPlugin(plugin.id); + plugin.toggle(v); }} /> - {plugin.manifest.description} + {plugin.description} diff --git a/src/core/ui/settings/pages/Plugins/index.tsx b/src/core/ui/settings/pages/Plugins/index.tsx index b0b08b4..7510e61 100644 --- a/src/core/ui/settings/pages/Plugins/index.tsx +++ b/src/core/ui/settings/pages/Plugins/index.tsx @@ -6,19 +6,61 @@ import { settings } from "@lib/api/settings"; import { useProxy } from "@lib/api/storage"; import { Author } from "@lib/utils/types"; +export interface PluginManifest { + id: string; + name: string; + description?: string; + authors?: Array; + icon?: string; + + isEnabled(): boolean; + usePluginState(): void; + toggle(start: boolean): void; + resolveSheetComponent(): Promise<{ default: React.ComponentType; }>; + getPluginSettingsComponent(): React.ComponentType | null; +} + +function resolveFromVdPlugin(vdPlugin: VendettaPlugin): PluginManifest { + return { + id: vdPlugin.id, + name: vdPlugin.manifest.name, + description: vdPlugin.manifest.description, + authors: vdPlugin.manifest.authors, + icon: vdPlugin.manifest.vendetta?.icon, + isEnabled() { + return vdPlugin.enabled; + }, + usePluginState() { + useProxy(VdPluginManager.plugins[vdPlugin.id]); + }, + toggle(start: boolean) { + start + ? VdPluginManager.startPlugin(vdPlugin.id) + : VdPluginManager.stopPlugin(vdPlugin.id); + }, + resolveSheetComponent() { + return import("./sheets/VdPluginInfoActionSheet"); + }, + getPluginSettingsComponent() { + return VdPluginManager.getSettings(vdPlugin.id); + }, + }; +} + export default function Plugins() { useProxy(settings); return ( - + title={Strings.PLUGINS} searchKeywords={[ - "manifest.name", - "manifest.description", - p => p.manifest.authors?.map((a: Author) => a.name).join() + "name", + "description", + p => p.authors?.map((a: Author | string) => typeof a === "string" ? a : a.name).join() ]} items={VdPluginManager.plugins} - fetchFunction={VdPluginManager.installPlugin.bind(VdPluginManager)} + resolveItem={resolveFromVdPlugin} + fetchFunction={async () => { /** TODO */ }} safeModeMessage={Strings.SAFE_MODE_NOTICE_PLUGINS} card={PluginCard} /> diff --git a/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx b/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx index 235cbeb..94f9961 100644 --- a/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx +++ b/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx @@ -1,141 +1,3 @@ -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 { 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 { hideSheet } from "@ui/sheets"; -import { showToast } from "@ui/toasts"; -import { ScrollView, View } from "react-native"; - -interface InfoProps { - plugin: VendettaPlugin; - navigation: any; -} - -export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps) { - useProxy(plugin); - - const Settings = VdPluginManager.getSettings(plugin.id); - - return - - - - {plugin.manifest.name} - - - {Settings &&