Browse Source

Fixed dangling process if application waas closed during download

Ivan Arkhipov 4 years ago
parent
commit
9a19c0922e

+ 3 - 1
src/Legacy/legacyapplication.cpp

@@ -31,7 +31,9 @@ LegacyApplication::LegacyApplication() {
 LegacyApplication::~LegacyApplication() {
     // gui will be deleted automatically on close due to Qt::WA_DeleteOnClose attribute
     patch_managers_thread_->terminate();
-    patch_managers_thread_->wait(10 * 1000); // Waiting 10 seconds
+    if (!patch_managers_thread_->wait(2 * 1000)) {
+        patch_managers_thread_->requestInterruption();
+    }
     delete patch_managers_thread_;
 }
 

+ 1 - 0
src/Legacy/models/downloader.cpp

@@ -29,6 +29,7 @@ void Downloader::waitForDownloaded() const
         return;
 
     QEventLoop loop;
+    connect(qApp, &QApplication::aboutToQuit, &loop, &QEventLoop::quit);
     connect(this, &Downloader::downloadFinished, &loop, &QEventLoop::quit);
     loop.exec();
 }

+ 3 - 1
src/Legacy/utils.cpp

@@ -11,6 +11,7 @@
 #include <QDir>
 #include <QMessageBox>
 #include <QProcess>
+#include <QApplication>
 
 #include <LotroDat/datfile.h>
 
@@ -22,11 +23,12 @@ bool checkInternetConnection(QUrl url) {
     QNetworkRequest req(url);
     QNetworkReply* reply = nam.get(req);
     QEventLoop loop;
+    QObject::connect(qApp, &QApplication::aboutToQuit, &loop, &QEventLoop::quit);
     QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
 
     QTimer request_timeout_timer;
     QObject::connect(&request_timeout_timer, &QTimer::timeout, &loop, &QEventLoop::quit);
-    request_timeout_timer.start(5000); // 5 seconds connection timeout
+    request_timeout_timer.start(2000); // 2 seconds connection timeout
     loop.exec();
     return reply->bytesAvailable();
 }

+ 1 - 0
src/LegacyLauncher/downloader.cpp

@@ -29,6 +29,7 @@ void Downloader::waitForDownloaded() const
         return;
 
     QEventLoop loop;
+    connect(qApp, &QApplication::aboutToQuit, &loop, &QEventLoop::quit);
     connect(this, &Downloader::downloadFinished, &loop, &QEventLoop::quit);
     loop.exec();
 }