Skip to content

Commit

Permalink
ENH: Update ExtensionsManager install API to return a boolean
Browse files Browse the repository at this point in the history
Enhance the installExtensionFromServer function by updating its API
to return a boolean value. Return a true or false response based on
the success or failure of the extension installation.

This is a follow-up of bda5198 (ENH: Add extensions manager API for
downloading and installing an extension (Slicer#7145))
  • Loading branch information
jcfr committed Aug 4, 2023
1 parent bade4c6 commit 151a7b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 8 additions & 6 deletions Base/QTCore/qSlicerExtensionsManagerModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1714,13 +1714,14 @@ bool qSlicerExtensionsManagerModel::downloadAndInstallExtensionByName(const QStr
}

//-----------------------------------------------------------------------------
void qSlicerExtensionsManagerModel::installExtensionFromServer(const QString& extensionName, bool restart)
bool qSlicerExtensionsManagerModel::installExtensionFromServer(const QString& extensionName, bool restart)
{
Q_D(qSlicerExtensionsManagerModel);

if (this->isExtensionInstalled(extensionName))
{
return;
// Already installed; nothing to do
return true;
}

bool isTestingEnabled = qSlicerCoreApplication::testAttribute(qSlicerCoreApplication::AA_EnableTesting);
Expand All @@ -1745,25 +1746,25 @@ void qSlicerExtensionsManagerModel::installExtensionFromServer(const QString& ex
}
if (!installationConfirmed)
{
return;
return false;
}

// Ensure extension metadata is retrieved from the server or cache.
if (!this->updateExtensionsMetadataFromServer(/* force= */ true, /* waitForCompletion= */ true))
{
return;
return false;
}

// Install extension and its dependencies
if (!this->downloadAndInstallExtensionByName(extensionName, /* installDependencies= */ true, /* waitForCompletion= */ true))
{
d->critical(tr("Failed to install %1 extension").arg(extensionName));
return;
return false;
}

if (!restart)
{
return;
return true;
}

// Handle restart confirmation
Expand All @@ -1790,6 +1791,7 @@ void qSlicerExtensionsManagerModel::installExtensionFromServer(const QString& ex
{
qSlicerCoreApplication::application()->restart();
}
return true;
}

// --------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion Base/QTCore/qSlicerExtensionsManagerModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,12 @@ public slots:
/// \param extensionName The name of the extension to be installed.
/// \param restart Set to false to prevent automatic application restart (default: true).
///
/// \return \c true if the extension is successfully installed or already installed.
///
/// \sa setInteractive
/// \sa isExtensionInstalled, installExtension, updateExtensionsMetadataFromServer, downloadAndInstallExtensionByName
/// \sa qSlicerCoreApplication::testAttribute, qSlicerCoreApplication::AA_EnableTesting, qSlicerCoreApplication::restart
void installExtensionFromServer(const QString& extensionName, bool restart = true);
bool installExtensionFromServer(const QString& extensionName, bool restart = true);

/// \brief Schedule \a extensionName of uninstall
/// Tell the application to uninstall \a extensionName when it will restart
Expand Down

0 comments on commit 151a7b9

Please sign in to comment.