From 00d538b368cdc85d933206ddfedbc2c035dc3881 Mon Sep 17 00:00:00 2001
From: fourtf <tf.four@gmail.com>
Date: Thu, 21 Jun 2018 22:44:48 +0200
Subject: [PATCH] fixed creating messagebox on wrong thread

---
 src/singletons/updatemanager.cpp   | 15 +++--
 src/widgets/lastruncrashdialog.cpp | 91 +++++++++++++++---------------
 2 files changed, 56 insertions(+), 50 deletions(-)

diff --git a/src/singletons/updatemanager.cpp b/src/singletons/updatemanager.cpp
index feec5db1a..a0a5b9617 100644
--- a/src/singletons/updatemanager.cpp
+++ b/src/singletons/updatemanager.cpp
@@ -2,6 +2,7 @@
 
 #include "util/combine_path.hpp"
 #include "util/networkrequest.hpp"
+#include "util/posttothread.hpp"
 #include "version.hpp"
 
 #include <QMessageBox>
@@ -95,12 +96,14 @@ void UpdateManager::checkForUpdates()
             this->setStatus_(SearchFailed);
             qDebug() << "error updating";
 
-            QMessageBox *box =
-                new QMessageBox(QMessageBox::Information, "Chatterino Update",
-                                "Error while searching for updates.\n\nEither the service is down "
-                                "temporarily or everything is broken.");
-            box->setAttribute(Qt::WA_DeleteOnClose);
-            box->show();
+            util::postToThread([] {
+                QMessageBox *box = new QMessageBox(
+                    QMessageBox::Information, "Chatterino Update",
+                    "Error while searching for updates.\n\nEither the service is down "
+                    "temporarily or everything is broken.");
+                box->setAttribute(Qt::WA_DeleteOnClose);
+                box->show();
+            });
             return;
         }
 
diff --git a/src/widgets/lastruncrashdialog.cpp b/src/widgets/lastruncrashdialog.cpp
index 925d7b10a..a60153e97 100644
--- a/src/widgets/lastruncrashdialog.cpp
+++ b/src/widgets/lastruncrashdialog.cpp
@@ -26,60 +26,63 @@ LastRunCrashDialog::LastRunCrashDialog()
 
     layout->addSpacing(16);
 
-    auto update = layout.emplace<QLabel>();
+    //    auto update = layout.emplace<QLabel>();
     auto buttons = layout.emplace<QDialogButtonBox>();
 
-    auto *installUpdateButton = buttons->addButton("Install Update", QDialogButtonBox::NoRole);
-    installUpdateButton->setEnabled(false);
-    QObject::connect(installUpdateButton, &QPushButton::clicked, [this, update]() mutable {
-        auto &updateManager = singletons::UpdateManager::getInstance();
+    //    auto *installUpdateButton = buttons->addButton("Install Update",
+    //    QDialogButtonBox::NoRole); installUpdateButton->setEnabled(false);
+    //    QObject::connect(installUpdateButton, &QPushButton::clicked, [this, update]() mutable {
+    //        auto &updateManager = singletons::UpdateManager::getInstance();
 
-        updateManager.installUpdates();
-        this->setEnabled(false);
-        update->setText("Downloading updates...");
-    });
+    //        updateManager.installUpdates();
+    //        this->setEnabled(false);
+    //        update->setText("Downloading updates...");
+    //    });
 
     auto *okButton = buttons->addButton("Ignore", QDialogButtonBox::ButtonRole::NoRole);
     QObject::connect(okButton, &QPushButton::clicked, [this] { this->accept(); });
 
     // Updates
-    auto updateUpdateLabel = [update]() mutable {
-        auto &updateManager = singletons::UpdateManager::getInstance();
+    //    auto updateUpdateLabel = [update]() mutable {
+    //        auto &updateManager = singletons::UpdateManager::getInstance();
 
-        switch (updateManager.getStatus()) {
-            case singletons::UpdateManager::None: {
-                update->setText("Not checking for updates.");
-            } break;
-            case singletons::UpdateManager::Searching: {
-                update->setText("Checking for updates...");
-            } break;
-            case singletons::UpdateManager::UpdateAvailable: {
-                update->setText("Update available.");
-            } break;
-            case singletons::UpdateManager::NoUpdateAvailable: {
-                update->setText("No update abailable.");
-            } break;
-            case singletons::UpdateManager::SearchFailed: {
-                update->setText("Error while searching for update.\nEither the update service is "
-                                "temporarily down or there is an issue with your installation.");
-            } break;
-            case singletons::UpdateManager::Downloading: {
-                update->setText(
-                    "Downloading the update. Chatterino will close once the download is done.");
-            } break;
-            case singletons::UpdateManager::DownloadFailed: {
-                update->setText("Download failed.");
-            } break;
-            case singletons::UpdateManager::WriteFileFailed: {
-                update->setText("Writing the update file to the hard drive failed.");
-            } break;
-        }
-    };
+    //        switch (updateManager.getStatus()) {
+    //            case singletons::UpdateManager::None: {
+    //                update->setText("Not checking for updates.");
+    //            } break;
+    //            case singletons::UpdateManager::Searching: {
+    //                update->setText("Checking for updates...");
+    //            } break;
+    //            case singletons::UpdateManager::UpdateAvailable: {
+    //                update->setText("Update available.");
+    //            } break;
+    //            case singletons::UpdateManager::NoUpdateAvailable: {
+    //                update->setText("No update abailable.");
+    //            } break;
+    //            case singletons::UpdateManager::SearchFailed: {
+    //                update->setText("Error while searching for update.\nEither the update service
+    //                is "
+    //                                "temporarily down or there is an issue with your
+    //                                installation.");
+    //            } break;
+    //            case singletons::UpdateManager::Downloading: {
+    //                update->setText(
+    //                    "Downloading the update. Chatterino will close once the download is
+    //                    done.");
+    //            } break;
+    //            case singletons::UpdateManager::DownloadFailed: {
+    //                update->setText("Download failed.");
+    //            } break;
+    //            case singletons::UpdateManager::WriteFileFailed: {
+    //                update->setText("Writing the update file to the hard drive failed.");
+    //            } break;
+    //        }
+    //    };
 
-    updateUpdateLabel();
-    this->managedConnect(updateManager.statusUpdated, [updateUpdateLabel](auto) mutable {
-        util::postToThread([updateUpdateLabel]() mutable { updateUpdateLabel(); });
-    });
+    //    updateUpdateLabel();
+    //    this->managedConnect(updateManager.statusUpdated, [updateUpdateLabel](auto) mutable {
+    //        util::postToThread([updateUpdateLabel]() mutable { updateUpdateLabel(); });
+    //    });
 }
 
 }  // namespace widgets