From 0fe5d30bbc514626d22cee0b38d98fd103129dbc Mon Sep 17 00:00:00 2001 From: Beef Date: Thu, 5 Jan 2023 23:07:58 +0000 Subject: [PATCH] [Plugins] Basic implementation of plugin settings --- src/def.d.ts | 3 ++- src/lib/plugins.ts | 3 +++ src/ui/components.ts | 3 ++- src/ui/settings/components/PluginCard.tsx | 29 +++++++++++++++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/def.d.ts b/src/def.d.ts index eff8a91..277ffdc 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -101,7 +101,8 @@ interface VendettaObject { } ui: { components: { - Forms: PropIntellisense<"FormSection">; + Forms: PropIntellisense<"Form" | "FormSection">; + General: PropIntellisense<"Button" | "Text" | "View">; } toasts: { showToast: (content: string, asset: number) => void; diff --git a/src/lib/plugins.ts b/src/lib/plugins.ts index ac534f8..6857f74 100644 --- a/src/lib/plugins.ts +++ b/src/lib/plugins.ts @@ -4,6 +4,7 @@ import logger from "./logger"; type EvaledPlugin = { onLoad?(): void; onUnload(): void; + settings: JSX.Element; }; export const plugins: Indexable = {}; @@ -92,5 +93,7 @@ export function stopPlugin(id: string) { plugin.enabled = false; } +export const getSettings = (id: string) => loadedPlugins[id]?.settings; + // TODO: When startAllPlugins exists, return this so cleanup in index.ts is easier const stopAllPlugins = () => Object.keys(loadedPlugins).forEach(stopPlugin); \ No newline at end of file diff --git a/src/ui/components.ts b/src/ui/components.ts index 0acad0a..6e88552 100644 --- a/src/ui/components.ts +++ b/src/ui/components.ts @@ -1,3 +1,4 @@ import { findByProps } from "@metro/filters"; -export const Forms = findByProps("FormSection"); \ No newline at end of file +export const Forms = findByProps("Form", "FormSection"); +export const General = findByProps("Button", "Text", "View"); \ No newline at end of file diff --git a/src/ui/settings/components/PluginCard.tsx b/src/ui/settings/components/PluginCard.tsx index 79f0e8a..505813b 100644 --- a/src/ui/settings/components/PluginCard.tsx +++ b/src/ui/settings/components/PluginCard.tsx @@ -1,10 +1,13 @@ import { ReactNative as RN, stylesheet } from "@metro/common"; -import { Forms } from "@ui/components"; +import { Forms, General } from "@ui/components"; import { Plugin } from "@types"; import { getAssetIDByName } from "@ui/assets"; -import { startPlugin, stopPlugin } from "@lib/plugins"; +import { getSettings, startPlugin, stopPlugin } from "@lib/plugins"; +import { findByProps } from "@metro/filters"; const { FormRow, FormSwitch } = Forms; +const { TouchableOpacity, Image } = General; +const navigation = findByProps("pushLazy"); const styles = stylesheet.createThemedStyleSheet({ card: { @@ -16,6 +19,16 @@ const styles = stylesheet.createThemedStyleSheet({ backgroundColor: stylesheet.ThemeColorMap.BACKGROUND_TERTIARY, borderTopLeftRadius: 5, borderTopRightRadius: 5, + }, + actions: { + justifyContent: "flex-end", + flexDirection: "row", + alignItems: "center", + }, + icon: { + width: 22, + height: 22, + tintColor: stylesheet.ThemeColorMap.INTERACTIVE_NORMAL, } }) @@ -25,6 +38,7 @@ interface PluginCardProps { export default function PluginCard({ plugin }: PluginCardProps) { const [enabled, setEnabled] = React.useState(plugin.enabled); + const Settings = getSettings(plugin.id); return ( @@ -44,6 +58,17 @@ export default function PluginCard({ plugin }: PluginCardProps) { /> + {Settings && { + navigation.push(Settings); + }} + > + + } + + } /> )