Don't unload/remove plugins immediately, instead require a restart to prevent unclean unload/crash

This commit is contained in:
Adam Honse 2024-05-16 21:38:01 -05:00
parent 6f55f0e0c0
commit 17ad77f07a
2 changed files with 39 additions and 7 deletions

View file

@ -127,6 +127,38 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
unsigned int plugin_idx;
/*---------------------------------------------------------------------*\
| Open plugin settings |
\*---------------------------------------------------------------------*/
json plugin_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Plugins");
/*---------------------------------------------------------------------*\
| Check if this plugin is on the remove list |
\*---------------------------------------------------------------------*/
if(plugin_settings.contains("plugins_remove"))
{
for(unsigned int plugin_remove_idx = 0; plugin_remove_idx < plugin_settings["plugins_remove"].size(); plugin_remove_idx++)
{
LOG_WARNING("[PluginManager] Checking remove %d, %s", plugin_remove_idx, to_string(plugin_settings["plugins_remove"][plugin_remove_idx]).c_str());
if(plugin_settings["plugins_remove"][plugin_remove_idx] == path.generic_u8string())
{
/*---------------------------------------------------------*\
| Delete the plugin file |
\*---------------------------------------------------------*/
filesystem::remove(path);
}
/*-----------------------------------------------------------------*\
| Erase the plugin from the remove list |
\*-----------------------------------------------------------------*/
plugin_settings["plugins_remove"].erase(plugin_remove_idx);
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
ResourceManager::get()->GetSettingsManager()->SaveSettings();
}
}
/*---------------------------------------------------------------------*\
| Search active plugins to see if this path already exists |
\*---------------------------------------------------------------------*/
@ -182,11 +214,6 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
bool found = false;
unsigned int plugin_ct = 0;
/*-----------------------------------------------------*\
| Open plugin list and check if plugin is in the list |
\*-----------------------------------------------------*/
json plugin_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Plugins");
if(plugin_settings.contains("plugins"))
{
plugin_ct = (unsigned int)plugin_settings["plugins"].size();