* @brief Uninstalls an extension by selecting it and triggering an irreversible directory * removal. With dryRun:true, reports what would be removed without mutating; otherwise * the manager's removal result plus the post-removal install state decide the outcome. */
| 238 | * the manager's removal result plus the post-removal install state decide the outcome. |
| 239 | */ |
| 240 | API::CommandResponse API::Handlers::ExtensionHandler::uninstallExtension(const QString& id, |
| 241 | const QJsonObject& params) |
| 242 | { |
| 243 | const int index = params.value("addonIndex").toInt(-1); |
| 244 | if (index < 0) |
| 245 | return CommandResponse::makeError( |
| 246 | id, QStringLiteral("INVALID_PARAMS"), "Missing or invalid addonIndex"); |
| 247 | |
| 248 | auto& mgr = Misc::ExtensionManager::instance(); |
| 249 | mgr.setSelectedIndex(index); |
| 250 | |
| 251 | const auto selected = mgr.selectedExtension(); |
| 252 | const QString addonId = selected.value("id").toString(); |
| 253 | const QString addonName = selected.value("name").toString(); |
| 254 | |
| 255 | if (addonId.isEmpty()) |
| 256 | return CommandResponse::makeError( |
| 257 | id, QStringLiteral("NOT_FOUND"), "No extension at addonIndex: " + QString::number(index)); |
| 258 | |
| 259 | if (!mgr.isInstalled(addonId)) |
| 260 | return CommandResponse::makeError( |
| 261 | id, QStringLiteral("NOT_FOUND"), "Extension is not installed: " + addonId); |
| 262 | |
| 263 | const bool isDryRun = params.value("dryRun").toBool(false); |
| 264 | if (isDryRun) |
| 265 | return CommandResponse::makeSuccess(id, |
| 266 | QJsonObject{ |
| 267 | { "dryRun",true }, |
| 268 | { "id", addonId}, |
| 269 | { "name", addonName}, |
| 270 | {"willRemove", true}, |
| 271 | { "warning", |
| 272 | "DRY RUN: no files were removed. Re-call " |
| 273 | "without dryRun:true to uninstall."} |
| 274 | }); |
| 275 | |
| 276 | const bool removed = mgr.uninstallExtension(); |
| 277 | if (!removed || mgr.isInstalled(addonId)) |
| 278 | return CommandResponse::makeError( |
| 279 | id, QStringLiteral("OPERATION_FAILED"), "Failed to uninstall extension: " + addonId); |
| 280 | |
| 281 | return CommandResponse::makeSuccess( |
| 282 | id, |
| 283 | QJsonObject{ |
| 284 | { "id", addonId}, |
| 285 | { "name", addonName}, |
| 286 | {"uninstalled", true} |
| 287 | }); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * @brief Returns the list of configured repository URLs. |
nothing calls this directly
no test coverage detected