diff --git a/plugins/rose-plugs/src/ui/PluginsBrowser.tsx b/plugins/rose-plugs/src/ui/PluginsBrowser.tsx index ffcfde2..ba9ed57 100644 --- a/plugins/rose-plugs/src/ui/PluginsBrowser.tsx +++ b/plugins/rose-plugs/src/ui/PluginsBrowser.tsx @@ -1,5 +1,5 @@ import { React, ReactNative } from "@vendetta/metro/common"; -import { plugins as installedPlugins, installPlugin } from "@vendetta/plugins"; +import { plugins as installedPlugins, installPlugin, removePlugin } from "@vendetta/plugins"; import { showToast } from "@vendetta/ui/toasts"; import SettingsScaffold from "@shared/ui/SettingsScaffold"; import NoteBox from "@shared/ui/NoteBox"; @@ -30,7 +30,7 @@ function withTimeout(promise: Promise, ms: number): Promise { export default function PluginsBrowser() { const [state, setState] = React.useState({ loading: true, error: null, plugins: [] }); - const [installingId, setInstallingId] = React.useState(null); + const [busyId, setBusyId] = React.useState(null); const load = React.useCallback(() => { setState((s) => ({ ...s, loading: true, error: null })); @@ -44,11 +44,23 @@ export default function PluginsBrowser() { }, [load]); const onInstall = React.useCallback((plugin: NexusPlugin) => { - setInstallingId(plugin.id); + setBusyId(plugin.id); withTimeout(installPlugin(plugin.installUrl), 20000) .then(() => showToast(`${plugin.name} installed`)) .catch((e: any) => showToast(`Install failed: ${e?.message ?? e}`)) - .finally(() => setInstallingId(null)); + .finally(() => setBusyId(null)); + }, []); + + const onUninstall = React.useCallback((plugin: NexusPlugin) => { + setBusyId(plugin.id); + try { + removePlugin(plugin.installUrl); + showToast(`${plugin.name} removed`); + } catch (e: any) { + showToast(`Remove failed: ${e?.message ?? e}`); + } finally { + setBusyId(null); + } }, []); if (state.loading) { @@ -81,12 +93,12 @@ export default function PluginsBrowser() { {plugins.map((plugin) => { const installed = plugin.installUrl in installedPlugins; - const installing = installingId === plugin.id; + const busy = busyId === plugin.id; return ( {plugin.status && plugin.status !== "default" && ( @@ -94,25 +106,23 @@ export default function PluginsBrowser() { {plugin.status.toUpperCase()} )} - {installed ? ( - ✓ - ) : ( - onInstall(plugin)} - style={{ - backgroundColor: "#5865F2", - borderRadius: 6, - paddingHorizontal: 10, - paddingVertical: 5, - opacity: installing ? 0.6 : 1, - }} - > - - {installing ? "Installing…" : "Install"} - - - )} + (installed ? onUninstall(plugin) : onInstall(plugin))} + style={{ + backgroundColor: installed ? "rgba(35,165,90,0.2)" : "#5865F2", + borderRadius: 6, + paddingHorizontal: 10, + paddingVertical: 5, + opacity: busy ? 0.6 : 1, + }} + > + + {busy + ? installed ? "Removing…" : "Installing…" + : installed ? "✓ Installed" : "Install"} + + } />