From 77dd4503b7bacc2c752078a8cec698f52741282f Mon Sep 17 00:00:00 2001 From: Beef Date: Mon, 20 Feb 2023 18:43:50 +0000 Subject: [PATCH] [Plugins] Properly handle errors in UI --- src/lib/plugins.ts | 2 +- src/ui/settings/components/PluginCard.tsx | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/plugins.ts b/src/lib/plugins.ts index 0aa02bc..c1c16a1 100644 --- a/src/lib/plugins.ts +++ b/src/lib/plugins.ts @@ -100,7 +100,7 @@ export function stopPlugin(id: string, disable = true) { if (!pluginRet) throw new Error("Attempted to stop a non-started plugin"); try { - loadedPlugins[plugin.id]?.onUnload?.(); + pluginRet.onUnload?.(); } catch(e) { logger.error(`Plugin ${plugin.id} errored whilst unloading`, e); } diff --git a/src/ui/settings/components/PluginCard.tsx b/src/ui/settings/components/PluginCard.tsx index acaf30c..b259318 100644 --- a/src/ui/settings/components/PluginCard.tsx +++ b/src/ui/settings/components/PluginCard.tsx @@ -71,7 +71,11 @@ export default function PluginCard({ plugin }: PluginCardProps) { style={RN.Platform.OS === "android" && { marginVertical: -15 }} value={plugin.enabled} onValueChange={(v: boolean) => { - if (v) startPlugin(plugin.id); else stopPlugin(plugin.id); + try { + if (v) startPlugin(plugin.id); else stopPlugin(plugin.id); + } catch (e) { + showToast((e as Error).message, getAssetIDByName("Small")); + } }} /> } @@ -88,8 +92,12 @@ export default function PluginCard({ plugin }: PluginCardProps) { cancelText: "Cancel", confirmColor: "red", onConfirm: () => { - removePlugin(plugin.id); - setRemoved(true); + try { + removePlugin(plugin.id); + setRemoved(true); + } catch (e) { + showToast((e as Error).message, getAssetIDByName("Small")); + } } })} >