|
29 | 29 |
|
30 | 30 | #include <QDebug> |
31 | 31 | #include <QJsonValue> |
| 32 | +#include <QJsonArray> |
32 | 33 | #include <QJsonObject> |
33 | 34 | #include <QMessageBox> |
34 | 35 | #include <QApplication> |
@@ -361,18 +362,58 @@ void Updater::onReply (QNetworkReply* reply) |
361 | 362 | return; |
362 | 363 | } |
363 | 364 |
|
364 | | - /* Get the platform information */ |
365 | | - QJsonObject updates = document.object().value ("updates").toObject(); |
366 | | - QJsonObject platform = updates.value (platformKey()).toObject(); |
| 365 | + /* Get latest GitHub Release */ |
| 366 | + QJsonArray githubReleases = document.array(); |
| 367 | + QJsonObject latestGithubRelese = githubReleases.at(0).toObject(); |
| 368 | + QString tagName = latestGithubRelese.value("tag_name").toString(); |
| 369 | + QString htmlUrl = latestGithubRelese.value("html_url").toString(); |
| 370 | + QString body = latestGithubRelese.value("body").toString(); |
367 | 371 |
|
368 | | - /* Get update information */ |
369 | | - m_openUrl = platform.value ("open-url").toString(); |
370 | | - m_changelog = platform.value ("changelog").toString(); |
371 | | - m_downloadUrl = platform.value ("download-url").toString(); |
372 | | - m_latestVersion = platform.value ("latest-version").toString(); |
| 372 | + QString releaseFileSuffix; |
| 373 | + if (platformKey().compare("osx") == 0) |
| 374 | + releaseFileSuffix = ".dmg"; |
373 | 375 |
|
374 | | - /* Compare latest and current version */ |
375 | | - setUpdateAvailable (latestVersion() != moduleVersion()); |
| 376 | + if (platformKey().compare("linux") == 0) |
| 377 | + releaseFileSuffix = ".deb"; |
| 378 | + |
| 379 | + if (platformKey().compare("windows") == 0) |
| 380 | + releaseFileSuffix = ".exe"; |
| 381 | + |
| 382 | + if (releaseFileSuffix.isEmpty()) |
| 383 | + { |
| 384 | + qWarning() << "Automatic updates are not suppurted in this platform " << platformKey(); |
| 385 | + setUpdateAvailable(false); |
| 386 | + emit checkingFinished (url()); |
| 387 | + return; |
| 388 | + } |
| 389 | + |
| 390 | + QJsonArray githubReleaseAssets = latestGithubRelese.value("assets").toArray(); |
| 391 | + bool releaseFound = false; |
| 392 | + QString releaseName; |
| 393 | + QString downloadUrl; |
| 394 | + for (QJsonValue jsonValue : githubReleaseAssets) |
| 395 | + { |
| 396 | + QJsonObject releaseAsset = jsonValue.toObject(); |
| 397 | + releaseName = releaseAsset.value("name").toString(); |
| 398 | + |
| 399 | + if (releaseName.endsWith(releaseFileSuffix)) |
| 400 | + { |
| 401 | + releaseFound = true; |
| 402 | + downloadUrl = releaseAsset.value("browser_download_url").toString(); |
| 403 | + break; |
| 404 | + } |
| 405 | + } |
| 406 | + if (releaseFound) |
| 407 | + { |
| 408 | + m_openUrl = htmlUrl; |
| 409 | + m_changelog = body; |
| 410 | + m_downloadUrl = downloadUrl; |
| 411 | + m_latestVersion = tagName; |
| 412 | + qDebug() << m_downloadUrl; |
| 413 | + |
| 414 | + /* Compare latest and current version */ |
| 415 | + setUpdateAvailable (latestVersion() != moduleVersion()); |
| 416 | + } |
376 | 417 | emit checkingFinished (url()); |
377 | 418 | } |
378 | 419 |
|
@@ -401,15 +442,14 @@ void Updater::setUpdateAvailable (const bool available) |
401 | 442 | box.setDefaultButton (QMessageBox::Yes); |
402 | 443 |
|
403 | 444 | if (box.exec() == QMessageBox::Yes) { |
404 | | - if (!openUrl().isEmpty()) |
| 445 | + if (downloadUrl().isEmpty()) |
405 | 446 | QDesktopServices::openUrl (QUrl (openUrl())); |
406 | 447 |
|
407 | | - else if (downloaderEnabled()) { |
| 448 | + if (downloaderEnabled()) { |
408 | 449 | m_downloader->setUrlId (url()); |
409 | 450 | m_downloader->setFileName (downloadUrl().split ("/").last()); |
410 | 451 | m_downloader->startDownload (QUrl (downloadUrl())); |
411 | 452 | } |
412 | | - |
413 | 453 | else |
414 | 454 | QDesktopServices::openUrl (QUrl (downloadUrl())); |
415 | 455 | } |
|
0 commit comments