From 25d32ce2922f276f1a7f67c8d3be978a8d360042 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Mon, 23 Jan 2023 22:43:25 +0100 Subject: [PATCH] Settings: Fix plugin switch state not updating (fixes #209) --- src/components/PluginSettings/index.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/PluginSettings/index.tsx b/src/components/PluginSettings/index.tsx index 58058b14..4b6abdd9 100644 --- a/src/components/PluginSettings/index.tsx +++ b/src/components/PluginSettings/index.tsx @@ -92,12 +92,9 @@ interface PluginCardProps extends React.HTMLProps { } function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLeave, isNew }: PluginCardProps) { - const settings = useSettings(); - const pluginSettings = settings.plugins[plugin.name]; + const settings = useSettings([`plugins.${plugin.name}`]).plugins[plugin.name]; - function isEnabled() { - return pluginSettings?.enabled || plugin.started; - } + const isEnabled = () => settings.enabled ?? false; function openModal() { openModalLazy(async () => { @@ -119,7 +116,7 @@ function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLe return; } else if (restartNeeded) { // If any dependencies have patches, don't start the plugin yet. - pluginSettings.enabled = true; + settings.enabled = true; onRestartNeeded(plugin.name); return; } @@ -127,14 +124,14 @@ function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLe // if the plugin has patches, dont use stopPlugin/startPlugin. Wait for restart to apply changes. if (plugin.patches) { - pluginSettings.enabled = !wasEnabled; + settings.enabled = !wasEnabled; onRestartNeeded(plugin.name); return; } // If the plugin is enabled, but hasn't been started, then we can just toggle it off. if (wasEnabled && !plugin.started) { - pluginSettings.enabled = !wasEnabled; + settings.enabled = !wasEnabled; return; } @@ -147,7 +144,7 @@ function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLe return; } - pluginSettings.enabled = !wasEnabled; + settings.enabled = !wasEnabled; } return (