Skip to content

Commit 17ad77f

Browse files
Don't unload/remove plugins immediately, instead require a restart to prevent unclean unload/crash
1 parent 6f55f0e commit 17ad77f

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

PluginManager.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,38 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
127127

128128
unsigned int plugin_idx;
129129

130+
/*---------------------------------------------------------------------*\
131+
| Open plugin settings |
132+
\*---------------------------------------------------------------------*/
133+
json plugin_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Plugins");
134+
135+
/*---------------------------------------------------------------------*\
136+
| Check if this plugin is on the remove list |
137+
\*---------------------------------------------------------------------*/
138+
if(plugin_settings.contains("plugins_remove"))
139+
{
140+
for(unsigned int plugin_remove_idx = 0; plugin_remove_idx < plugin_settings["plugins_remove"].size(); plugin_remove_idx++)
141+
{
142+
LOG_WARNING("[PluginManager] Checking remove %d, %s", plugin_remove_idx, to_string(plugin_settings["plugins_remove"][plugin_remove_idx]).c_str());
143+
144+
if(plugin_settings["plugins_remove"][plugin_remove_idx] == path.generic_u8string())
145+
{
146+
/*---------------------------------------------------------*\
147+
| Delete the plugin file |
148+
\*---------------------------------------------------------*/
149+
filesystem::remove(path);
150+
}
151+
152+
/*-----------------------------------------------------------------*\
153+
| Erase the plugin from the remove list |
154+
\*-----------------------------------------------------------------*/
155+
plugin_settings["plugins_remove"].erase(plugin_remove_idx);
156+
157+
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
158+
ResourceManager::get()->GetSettingsManager()->SaveSettings();
159+
}
160+
}
161+
130162
/*---------------------------------------------------------------------*\
131163
| Search active plugins to see if this path already exists |
132164
\*---------------------------------------------------------------------*/
@@ -182,11 +214,6 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
182214
bool found = false;
183215
unsigned int plugin_ct = 0;
184216

185-
/*-----------------------------------------------------*\
186-
| Open plugin list and check if plugin is in the list |
187-
\*-----------------------------------------------------*/
188-
json plugin_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Plugins");
189-
190217
if(plugin_settings.contains("plugins"))
191218
{
192219
plugin_ct = (unsigned int)plugin_settings["plugins"].size();

qt/OpenRGBPluginsPage/OpenRGBPluginsPage.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,17 @@ void Ui::OpenRGBPluginsPage::on_RemovePluginButton_clicked()
235235
if((plugin_settings["plugins"][plugin_idx]["name"] == entries[cur_row]->ui->NameValue->text().toStdString())
236236
&&(plugin_settings["plugins"][plugin_idx]["description"] == entries[cur_row]->ui->DescriptionValue->text().toStdString()))
237237
{
238-
plugin_settings["plugins"].erase(plugin_idx);
238+
/*-----------------------------------------------------*\
239+
| Mark plugin to be removed on next restart |
240+
\*-----------------------------------------------------*/
241+
plugin_settings["plugins_remove"][plugin_settings["plugins_remove"].size()] = entries[cur_row]->ui->PathValue->text().toStdString();
239242

240243
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
241244
ResourceManager::get()->GetSettingsManager()->SaveSettings();
242245

243-
break;
246+
QMessageBox::information(this, tr("Restart Needed"), tr("The plugin will be fully removed after restarting OpenRGB."), QMessageBox::Ok);
247+
248+
return;
244249
}
245250
}
246251
}

0 commit comments

Comments
 (0)