@@ -288,7 +288,7 @@ bool ConfigManager::addConfigs(const QStringList &serializedConfigs)
288288 return false ;
289289 }
290290
291- // If there's no active config, activate the first added one
291+ // If there's no active config, activate the first added one
292292 if (activeUuid.isEmpty () && !firstUuid.isEmpty ())
293293 {
294294 Logger::getInstance ().info (QString (" No active config, activating first added config: %1" ).arg (firstUuid));
@@ -316,12 +316,25 @@ bool ConfigManager::removeConfig(const QString &uuid)
316316 .arg (configToRemove[" name" ].toString ())
317317 .arg (configToRemove[" protocol" ].toString ()));
318318
319+ // Store current active config UUID
320+ bool needToActivateNew = (getActiveConfigUuid () == uuid);
321+
322+ // Remove config from the list
319323 configs.remove (uuid);
320-
321- // If removing active config, activate another one first
322- if (getActiveConfigUuid () == uuid)
324+
325+ // Save updated configs list (without changing activeConfigUuid)
326+ configsInfo[" configs" ] = configs;
327+ Logger::getInstance ().debug (" Writing updated configs info to file" );
328+ if (!writeConfigsInfo (configsInfo))
329+ {
330+ Logger::getInstance ().error (" Failed to write configs info" );
331+ return false ;
332+ }
333+
334+ // If active config was removed, activate a new one
335+ if (needToActivateNew)
323336 {
324- Logger::getInstance ().info (" Removing active config, need to activate another one" );
337+ Logger::getInstance ().info (" Removed active config, need to activate a new one" );
325338 if (configs.isEmpty ())
326339 {
327340 Logger::getInstance ().info (" No configs left, clearing active config" );
@@ -342,10 +355,8 @@ bool ConfigManager::removeConfig(const QString &uuid)
342355 }
343356 }
344357 }
345-
346- configsInfo[" configs" ] = configs;
347- Logger::getInstance ().debug (" Writing updated configs info to file" );
348- return writeConfigsInfo (configsInfo);
358+
359+ return true ;
349360}
350361
351362bool ConfigManager::activateConfig (const QString &uuid)
0 commit comments