diff --git a/include/ui/updatepromoter.h b/include/ui/updatepromoter.h index 4465e0dc..b3abd381 100644 --- a/include/ui/updatepromoter.h +++ b/include/ui/updatepromoter.h @@ -37,8 +37,7 @@ private: void resetDialog(); void get(const QUrl &url); void processWebpage(const QJsonDocument &data, const QUrl &nextUrl); - void disableRequestsUntil(const QDateTime time); - void error(const QString &err); + void error(const QString &err, const QDateTime time = QDateTime()); bool isNewerVersion(int major, int minor, int patch); private slots: diff --git a/src/core/network.cpp b/src/core/network.cpp index 901d291f..94594d68 100644 --- a/src/core/network.cpp +++ b/src/core/network.cpp @@ -147,7 +147,7 @@ void NetworkAccessManager::processReply(QNetworkReply * reply, NetworkReplyData this->cache.insert(url, cacheEntry); } auto eTagHeader = reply->header(QNetworkRequest::ETagHeader); - if (eTagHeader.isValid()) + if (eTagHeader.canConvert()) cacheEntry->eTag = eTagHeader.toString(); cacheEntry->data = data->m_body = reply->readAll(); diff --git a/src/ui/updatepromoter.cpp b/src/ui/updatepromoter.cpp index 71f4dce9..5305a647 100644 --- a/src/ui/updatepromoter.cpp +++ b/src/ui/updatepromoter.cpp @@ -69,8 +69,7 @@ void UpdatePromoter::get(const QUrl &url) { auto reply = this->manager->get(url); connect(reply, &NetworkReplyData::finished, [this, reply] () { if (!reply->errorString().isEmpty()) { - this->error(reply->errorString()); - this->disableRequestsUntil(reply->retryAfter()); + this->error(reply->errorString(), reply->retryAfter()); } else { this->processWebpage(QJsonDocument::fromJson(reply->body()), reply->nextUrl()); } @@ -79,8 +78,7 @@ void UpdatePromoter::get(const QUrl &url) { } // Read all the items on the releases page, ignoring entries without a version identifier tag. -// Objects in the releases page data are sorted newest to oldest. -// Returns true when finished, returns false to request processing for the next page. +// Objects in the releases page data are sorted newest to oldest. void UpdatePromoter::processWebpage(const QJsonDocument &data, const QUrl &nextUrl) { const QJsonArray releases = data.array(); int i; @@ -156,21 +154,23 @@ void UpdatePromoter::processWebpage(const QJsonDocument &data, const QUrl &nextU } } -void UpdatePromoter::disableRequestsUntil(const QDateTime time) { - this->button_Retry->setEnabled(false); - - auto timeUntil = QDateTime::currentDateTime().msecsTo(time); - if (timeUntil < 0) timeUntil = 0; - QTimer::singleShot(timeUntil, Qt::VeryCoarseTimer, [this]() { - this->button_Retry->setEnabled(true); - }); -} - -void UpdatePromoter::error(const QString &err) { +void UpdatePromoter::error(const QString &err, const QDateTime retryAfter) { const QString message = QString("Failed to check for version update: %1").arg(err); ui->label_Status->setText(message); if (!this->isVisible()) logWarn(message); + + // If a "retry after" date/time is provided, disable the Retry button until then. + // Otherwise users are allowed to retry after an error. + auto timeUntil = QDateTime::currentDateTime().msecsTo(retryAfter); + if (timeUntil > 0) { + this->button_Retry->setEnabled(false); + QTimer::singleShot(timeUntil, Qt::VeryCoarseTimer, [this]() { + this->button_Retry->setEnabled(true); + }); + } else { + this->button_Retry->setEnabled(true); + } } bool UpdatePromoter::isNewerVersion(int major, int minor, int patch) {