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

View File

@ -92,12 +92,9 @@ interface PluginCardProps extends React.HTMLProps<HTMLDivElement> {
}
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 (