fixed creating messagebox on wrong thread

This commit is contained in:
fourtf 2018-06-21 22:44:48 +02:00
parent 713d0c9599
commit 00d538b368
2 changed files with 56 additions and 50 deletions

View file

@ -2,6 +2,7 @@
#include "util/combine_path.hpp" #include "util/combine_path.hpp"
#include "util/networkrequest.hpp" #include "util/networkrequest.hpp"
#include "util/posttothread.hpp"
#include "version.hpp" #include "version.hpp"
#include <QMessageBox> #include <QMessageBox>
@ -95,12 +96,14 @@ void UpdateManager::checkForUpdates()
this->setStatus_(SearchFailed); this->setStatus_(SearchFailed);
qDebug() << "error updating"; qDebug() << "error updating";
QMessageBox *box = util::postToThread([] {
new QMessageBox(QMessageBox::Information, "Chatterino Update", QMessageBox *box = new QMessageBox(
QMessageBox::Information, "Chatterino Update",
"Error while searching for updates.\n\nEither the service is down " "Error while searching for updates.\n\nEither the service is down "
"temporarily or everything is broken."); "temporarily or everything is broken.");
box->setAttribute(Qt::WA_DeleteOnClose); box->setAttribute(Qt::WA_DeleteOnClose);
box->show(); box->show();
});
return; return;
} }

View file

@ -26,60 +26,63 @@ LastRunCrashDialog::LastRunCrashDialog()
layout->addSpacing(16); layout->addSpacing(16);
auto update = layout.emplace<QLabel>(); // auto update = layout.emplace<QLabel>();
auto buttons = layout.emplace<QDialogButtonBox>(); auto buttons = layout.emplace<QDialogButtonBox>();
auto *installUpdateButton = buttons->addButton("Install Update", QDialogButtonBox::NoRole); // auto *installUpdateButton = buttons->addButton("Install Update",
installUpdateButton->setEnabled(false); // QDialogButtonBox::NoRole); installUpdateButton->setEnabled(false);
QObject::connect(installUpdateButton, &QPushButton::clicked, [this, update]() mutable { // QObject::connect(installUpdateButton, &QPushButton::clicked, [this, update]() mutable {
auto &updateManager = singletons::UpdateManager::getInstance(); // auto &updateManager = singletons::UpdateManager::getInstance();
updateManager.installUpdates(); // updateManager.installUpdates();
this->setEnabled(false); // this->setEnabled(false);
update->setText("Downloading updates..."); // update->setText("Downloading updates...");
}); // });
auto *okButton = buttons->addButton("Ignore", QDialogButtonBox::ButtonRole::NoRole); auto *okButton = buttons->addButton("Ignore", QDialogButtonBox::ButtonRole::NoRole);
QObject::connect(okButton, &QPushButton::clicked, [this] { this->accept(); }); QObject::connect(okButton, &QPushButton::clicked, [this] { this->accept(); });
// Updates // Updates
auto updateUpdateLabel = [update]() mutable { // auto updateUpdateLabel = [update]() mutable {
auto &updateManager = singletons::UpdateManager::getInstance(); // auto &updateManager = singletons::UpdateManager::getInstance();
switch (updateManager.getStatus()) { // switch (updateManager.getStatus()) {
case singletons::UpdateManager::None: { // case singletons::UpdateManager::None: {
update->setText("Not checking for updates."); // update->setText("Not checking for updates.");
} break; // } break;
case singletons::UpdateManager::Searching: { // case singletons::UpdateManager::Searching: {
update->setText("Checking for updates..."); // update->setText("Checking for updates...");
} break; // } break;
case singletons::UpdateManager::UpdateAvailable: { // case singletons::UpdateManager::UpdateAvailable: {
update->setText("Update available."); // update->setText("Update available.");
} break; // } break;
case singletons::UpdateManager::NoUpdateAvailable: { // case singletons::UpdateManager::NoUpdateAvailable: {
update->setText("No update abailable."); // update->setText("No update abailable.");
} break; // } break;
case singletons::UpdateManager::SearchFailed: { // case singletons::UpdateManager::SearchFailed: {
update->setText("Error while searching for update.\nEither the update service is " // update->setText("Error while searching for update.\nEither the update service
"temporarily down or there is an issue with your installation."); // is "
} break; // "temporarily down or there is an issue with your
case singletons::UpdateManager::Downloading: { // installation.");
update->setText( // } break;
"Downloading the update. Chatterino will close once the download is done."); // case singletons::UpdateManager::Downloading: {
} break; // update->setText(
case singletons::UpdateManager::DownloadFailed: { // "Downloading the update. Chatterino will close once the download is
update->setText("Download failed."); // done.");
} break; // } break;
case singletons::UpdateManager::WriteFileFailed: { // case singletons::UpdateManager::DownloadFailed: {
update->setText("Writing the update file to the hard drive failed."); // update->setText("Download failed.");
} break; // } break;
} // case singletons::UpdateManager::WriteFileFailed: {
}; // update->setText("Writing the update file to the hard drive failed.");
// } break;
// }
// };
updateUpdateLabel(); // updateUpdateLabel();
this->managedConnect(updateManager.statusUpdated, [updateUpdateLabel](auto) mutable { // this->managedConnect(updateManager.statusUpdated, [updateUpdateLabel](auto) mutable {
util::postToThread([updateUpdateLabel]() mutable { updateUpdateLabel(); }); // util::postToThread([updateUpdateLabel]() mutable { updateUpdateLabel(); });
}); // });
} }
} // namespace widgets } // namespace widgets