Skip to content

Commit

Permalink
ENH: Update ExtensionsManager install API to check for update
Browse files Browse the repository at this point in the history
Add support for the `update` parameter in the
`qSlicerExtensionsManagerModel::installExtensionFromServer` function.

Users can now set the `update` parameter to `true` to schedule the
update of an already installed extension to the latest version available
on the server.

The update will take effect during the next application restart.

If the extension is not already installed, this parameter has no effect.

Co-authored-by: Andras Lasso <lasso@queensu.ca>
  • Loading branch information
jcfr and lassoan committed Aug 4, 2023
1 parent 7ef5961 commit 14b4330
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Base/QTCore/qSlicerExtensionsManagerModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1714,13 +1714,21 @@ bool qSlicerExtensionsManagerModel::downloadAndInstallExtensionByName(const QStr
}

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

if (this->isExtensionInstalled(extensionName))
{
// Already installed; nothing to do
if (update)
{
// Ensure extension metadata is retrieved from the server or cache.
if (!this->updateExtensionsMetadataFromServer(/* force= */ true, /* waitForCompletion= */ true))
{
return false;
}
this->scheduleExtensionForUpdate(extensionName);
}
return true;
}

Expand Down
9 changes: 8 additions & 1 deletion Base/QTCore/qSlicerExtensionsManagerModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,22 @@ public slots:
/// To prevent the application from automatically restarting after the
/// installation is completed, set the \a restart parameter to false.
///
/// To schedule the update of the extension and its dependencies to
/// the latest version available if already installed, set the \a update
/// parameter to true.
/// The update will take effect during the next application restart.
///
/// \param extensionName The name of the extension to be installed.
/// \param restart Set to false to prevent automatic application restart (default: true).
/// \param update Set to true to schedule the extension for an update on the next application restart (default: false).
///
/// \return \c true if the extension is successfully installed or already installed.
///
/// \sa setInteractive
/// \sa isExtensionInstalled, installExtension, updateExtensionsMetadataFromServer, downloadAndInstallExtensionByName
/// \sa scheduleExtensionForUpdate
/// \sa qSlicerCoreApplication::testAttribute, qSlicerCoreApplication::AA_EnableTesting, qSlicerCoreApplication::restart
bool installExtensionFromServer(const QString& extensionName, bool restart = true);
bool installExtensionFromServer(const QString& extensionName, bool restart = true, bool update = false);

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

0 comments on commit 14b4330

Please sign in to comment.