Skip to content

Commit

Permalink
update notifier improvements and better tags
Browse files Browse the repository at this point in the history
  • Loading branch information
coder3101 committed Jan 28, 2020
1 parent 72ab517 commit 26e754a
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/UpdateNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ QString UpdateNotifier::currentVersionStr()

return QString::fromStdString(version);
}

bool compareVersion(QString const & a, QString const & b)
{
// returns true if a is higher version than b;

auto aV = a.split(".");
auto bV = b.split(".");

if (aV.size() < 3 && bV.size() < 3)
return false; // invalid versions;

int aMajor = aV[0].toInt();
int aMinor = aV[1].toInt();
int aPatch = aV[2].toInt();

int bMajor = bV[0].toInt();
int bMinor = bV[1].toInt();
int bPatch = bV[2].toInt();

if (aMajor > bMajor)
return true;
if (aMinor > bMinor)
return true;
if (aPatch > bPatch)
return true;

return false;
}

void UpdateNotifier::managerFinished(QNetworkReply *reply)
{
if (reply->error())
Expand All @@ -66,29 +95,30 @@ void UpdateNotifier::managerFinished(QNetworkReply *reply)
bool isBeta = false;
QString latestRelease = "0.0.0";

for (auto e : doc.array().toVariantList())
for (auto const &e : doc.array().toVariantList())
{
release = QJsonDocument::fromVariant(e);

if (release["prerelease"].toBool())
{
if (beta)
{
latestRelease = release["tag_name"].toString();
latestRelease = release["tag_name"].toString().remove("-beta").remove("-rc");
isBeta = true;
downloadUrl = release["html_url"].toString();
break;
}
}
else // stable
{
latestRelease = release["tag_name"].toString();
latestRelease = release["tag_name"].toString().remove("-stable");
isBeta = false;
downloadUrl = release["html_url"].toString();
break;
}
}
bool isUpdateAvailable = (latestRelease > currentVersionStr());

bool isUpdateAvailable = compareVersion(latestRelease, currentVersionStr());

if (beta && isBeta && isUpdateAvailable)
{
Expand Down

0 comments on commit 26e754a

Please sign in to comment.