MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / uninstallExtension

Method uninstallExtension

app/src/API/Handlers/ExtensionHandler.cpp:240–288  ·  view source on GitHub ↗

* @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. */

Source from the content-addressed store, hash-verified

238 * the manager's removal result plus the post-removal install state decide the outcome.
239 */
240API::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.

Callers

nothing calls this directly

Calls 5

selectedExtensionMethod · 0.80
isEmptyMethod · 0.80
isInstalledMethod · 0.80
valueMethod · 0.45
setSelectedIndexMethod · 0.45

Tested by

no test coverage detected