Settings: Fix plugin switch state not updating (fixes #209)

This commit is contained in:
Vendicated 2023-01-23 22:43:25 +01:00
parent cb4c50842f
commit 25d32ce292
No known key found for this signature in database
GPG Key ID: A1DC0CFB5615D905

@ -92,12 +92,9 @@ interface PluginCardProps extends React.HTMLProps<HTMLDivElement> {
} }
function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLeave, isNew }: PluginCardProps) { function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLeave, isNew }: PluginCardProps) {
const settings = useSettings(); const settings = useSettings([`plugins.${plugin.name}`]).plugins[plugin.name];
const pluginSettings = settings.plugins[plugin.name];
function isEnabled() { const isEnabled = () => settings.enabled ?? false;
return pluginSettings?.enabled || plugin.started;
}
function openModal() { function openModal() {
openModalLazy(async () => { openModalLazy(async () => {
@ -119,7 +116,7 @@ function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLe
return; return;
} else if (restartNeeded) { } else if (restartNeeded) {
// If any dependencies have patches, don't start the plugin yet. // If any dependencies have patches, don't start the plugin yet.
pluginSettings.enabled = true; settings.enabled = true;
onRestartNeeded(plugin.name); onRestartNeeded(plugin.name);
return; 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 the plugin has patches, dont use stopPlugin/startPlugin. Wait for restart to apply changes.
if (plugin.patches) { if (plugin.patches) {
pluginSettings.enabled = !wasEnabled; settings.enabled = !wasEnabled;
onRestartNeeded(plugin.name); onRestartNeeded(plugin.name);
return; return;
} }
// If the plugin is enabled, but hasn't been started, then we can just toggle it off. // If the plugin is enabled, but hasn't been started, then we can just toggle it off.
if (wasEnabled && !plugin.started) { if (wasEnabled && !plugin.started) {
pluginSettings.enabled = !wasEnabled; settings.enabled = !wasEnabled;
return; return;
} }
@ -147,7 +144,7 @@ function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLe
return; return;
} }
pluginSettings.enabled = !wasEnabled; settings.enabled = !wasEnabled;
} }
return ( return (