diff --git a/Studio/Interface/UpdateChecker.cpp b/Studio/Interface/UpdateChecker.cpp index 84fc426038..f861029c6f 100644 --- a/Studio/Interface/UpdateChecker.cpp +++ b/Studio/Interface/UpdateChecker.cpp @@ -57,49 +57,56 @@ void UpdateChecker::run_update_check() { void UpdateChecker::handleNetworkReply(QNetworkReply* reply) { std::string response = QString(reply->readAll()).toStdString(); + response = ""; + // get the json response - auto j = json::parse(response); - - std::string platform = StudioUtils::get_platform_string().toStdString(); - - int major = j[platform]["major"].get(); - int minor = j[platform]["minor"].get(); - int patch = j[platform]["patch"].get(); - QString message = QString::fromStdString(j[platform]["message"].get()); - - bool update_available = false; - if (major > SHAPEWORKS_MAJOR_VERSION) { - update_available = true; - } else if (major == SHAPEWORKS_MAJOR_VERSION && minor > SHAPEWORKS_MINOR_VERSION) { - update_available = true; - } else if (major == SHAPEWORKS_MAJOR_VERSION && minor == SHAPEWORKS_MINOR_VERSION && - patch > SHAPEWORKS_PATCH_VERSION) { - update_available = true; - } + try { + auto j = json::parse(response); + std::string platform = StudioUtils::get_platform_string().toStdString(); + + int major = j[platform]["major"].get(); + int minor = j[platform]["minor"].get(); + int patch = j[platform]["patch"].get(); + QString message = QString::fromStdString(j[platform]["message"].get()); + + bool update_available = false; + if (major > SHAPEWORKS_MAJOR_VERSION) { + update_available = true; + } else if (major == SHAPEWORKS_MAJOR_VERSION && minor > SHAPEWORKS_MINOR_VERSION) { + update_available = true; + } else if (major == SHAPEWORKS_MAJOR_VERSION && minor == SHAPEWORKS_MINOR_VERSION && + patch > SHAPEWORKS_PATCH_VERSION) { + update_available = true; + } - if (update_available) { - auto url = QString("https://github.com/SCIInstitute/ShapeWorks/releases/latest"); - - auto title = QString("New version available"); - setWindowTitle(title); - ui_->label->setTextFormat(Qt::RichText); - ui_->label->setOpenExternalLinks(true); - ui_->label->setTextInteractionFlags(Qt::TextBrowserInteraction); - ui_->label->setText(QString("A new version of ShapeWorks is available.

" - "To download the latest version, please visit:

%1

" + - message) - .arg(url)); - - show(); - raise(); - - } else { - if (manual_trigger_) { - // show a messagebox saying there is no update - auto title = QString("No update available"); - auto info = QString("You are running the latest version of ShapeWorks."); - QMessageBox::information(nullptr, title, info, QMessageBox::Ok); + if (update_available) { + auto url = QString("https://github.com/SCIInstitute/ShapeWorks/releases/latest"); + + auto title = QString("New version available"); + setWindowTitle(title); + ui_->label->setTextFormat(Qt::RichText); + ui_->label->setOpenExternalLinks(true); + ui_->label->setTextInteractionFlags(Qt::TextBrowserInteraction); + ui_->label->setText(QString("A new version of ShapeWorks is available.

" + "To download the latest version, please visit:

%1

" + + message) + .arg(url)); + + show(); + raise(); + + } else { + if (manual_trigger_) { + // show a messagebox saying there is no update + auto title = QString("No update available"); + auto info = QString("You are running the latest version of ShapeWorks."); + QMessageBox::information(nullptr, title, info, QMessageBox::Ok); + } } + + } catch (json::exception& e) { + SW_LOG("Unable to check for updates: " + std::string(e.what())); + return; } } } // namespace shapeworks \ No newline at end of file diff --git a/Studio/Interface/UpdateChecker.h b/Studio/Interface/UpdateChecker.h index 2fd6042411..0393efe353 100644 --- a/Studio/Interface/UpdateChecker.h +++ b/Studio/Interface/UpdateChecker.h @@ -1,10 +1,10 @@ #pragma once +#include + #include #include -#include - namespace Ui { class UpdateChecker; } @@ -25,7 +25,6 @@ class UpdateChecker : public QDialog { void run_auto_update_check(); void run_manual_update_check(); - public Q_SLOTS: void handleNetworkReply(QNetworkReply* reply); @@ -38,7 +37,6 @@ class UpdateChecker : public QDialog { Ui::UpdateChecker* ui_; Preferences& prefs_; - }; } // namespace shapeworks \ No newline at end of file