diff options
author | Robert Griebl <robert.griebl@pelagicore.com> | 2019-06-26 15:32:11 +0200 |
---|---|---|
committer | Bernd Weimer <bernd.weimer@pelagicore.com> | 2019-08-01 13:21:13 +0200 |
commit | ecf00cd214a771799717d9f2b24c300d8c50cccc (patch) | |
tree | 1328975fd024afcd106c30aa1ab242525fe84681 | |
parent | ef66fc9984a21cb5ef5d4f660172848c19603caf (diff) | |
download | qtapplicationmanager-ecf00cd214a771799717d9f2b24c300d8c50cccc.tar.gz |
Wait for apps to stop before actually uninstalling them
Cherry-picked from dev: f6a895c
Change-Id: Iaf4b3da0c622079ccb79886875134af58175bd43
Task-number: AUTOSUITE-1075
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r-- | src/installer-lib/deinstallationtask.cpp | 16 | ||||
-rw-r--r-- | src/installer-lib/deinstallationtask.h | 5 | ||||
-rw-r--r-- | src/window-lib/window.h | 4 |
3 files changed, 23 insertions, 2 deletions
diff --git a/src/installer-lib/deinstallationtask.cpp b/src/installer-lib/deinstallationtask.cpp index fd8c56f7..cb03cb83 100644 --- a/src/installer-lib/deinstallationtask.cpp +++ b/src/installer-lib/deinstallationtask.cpp @@ -63,6 +63,13 @@ DeinstallationTask::DeinstallationTask(ApplicationInfo *app, const InstallationL m_applicationId = m_app->id(); // in base class } +bool DeinstallationTask::cancel() +{ + if (m_canBeCanceled) + m_canceled = true; + return m_canceled; +} + void DeinstallationTask::execute() { // these have been checked in ApplicationInstaller::removePackage() already @@ -84,6 +91,15 @@ void DeinstallationTask::execute() if (!managerApproval) throw Exception("ApplicationManager rejected the removal of app %1").arg(m_app->id()); + // if the app was running before, we now need to wait until is has actually stopped + while (!m_canceled && + (ApplicationManager::instance()->applicationRunState(m_app->id()) != Am::NotRunning)) { + QThread::msleep(30); + } + // there's a small race condition here, but not doing a planned cancellation isn't harmful + m_canBeCanceled = false; + if (m_canceled) + throw Exception(Error::Canceled, "canceled"); ScopedRenamer docDirRename; ScopedRenamer appDirRename; diff --git a/src/installer-lib/deinstallationtask.h b/src/installer-lib/deinstallationtask.h index 912a34a1..f990cee7 100644 --- a/src/installer-lib/deinstallationtask.h +++ b/src/installer-lib/deinstallationtask.h @@ -56,6 +56,9 @@ class DeinstallationTask : public AsynchronousTask public: DeinstallationTask(ApplicationInfo *app, const InstallationLocation &installationLocation, bool forceDeinstallation, bool keepDocuments, QObject *parent = nullptr); + + bool cancel() override; + protected: void execute() override; @@ -64,6 +67,8 @@ private: const InstallationLocation &m_installationLocation; bool m_forceDeinstallation; bool m_keepDocuments; + bool m_canBeCanceled = true; + bool m_canceled = false; }; QT_END_NAMESPACE_AM diff --git a/src/window-lib/window.h b/src/window-lib/window.h index a856b4d3..b9a7c69d 100644 --- a/src/window-lib/window.h +++ b/src/window-lib/window.h @@ -48,10 +48,10 @@ #include <QQuickItem> #include <QSet> #include <QtAppManCommon/global.h> +#include <QtAppManManager/application.h> QT_BEGIN_NAMESPACE_AM -class AbstractApplication; class WindowItem; // A Window object exists for every application window that is managed by the application-manager @@ -117,7 +117,7 @@ signals: void _windowDestroyed(); protected: - AbstractApplication *m_application; + QPointer<AbstractApplication> m_application; QSet<WindowItem*> m_items; WindowItem *m_primaryItem{nullptr}; |