| 35 | } |
| 36 | |
| 37 | void UpdateChecker::checkLatestRelease() { |
| 38 | // Abandon any in-flight check. abort() makes that reply emit finished() with |
| 39 | // OperationCanceledError, which handleReply() drops silently; and because each |
| 40 | // handler captures its own `reply`, superseding a check can never make an old |
| 41 | // reply's handler act on the new request. |
| 42 | if (pending_reply_ && pending_reply_->isRunning()) { |
| 43 | pending_reply_->abort(); |
| 44 | } |
| 45 | |
| 46 | QNetworkRequest request(release_api_url_); |
| 47 | request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); |
| 48 | // api.github.com rejects requests without a User-Agent (HTTP 403). |
| 49 | request.setHeader(QNetworkRequest::UserAgentHeader, QStringLiteral("PlotJuggler")); |
| 50 | request.setRawHeader("Accept", "application/vnd.github+json"); |
| 51 | request.setTransferTimeout(kTransferTimeoutMs); |
| 52 | |
| 53 | QNetworkReply* reply = network_->get(request); |
| 54 | pending_reply_ = reply; |
| 55 | connect(reply, &QNetworkReply::finished, this, [this, reply]() { |
| 56 | if (pending_reply_ == reply) { |
| 57 | pending_reply_ = nullptr; |
| 58 | } |
| 59 | handleReply(reply); |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | void UpdateChecker::handleReply(QNetworkReply* reply) { |
| 64 | if (!reply) { |