mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(ui): don't notify of available update if local version is newer
This could happen between the time when the release tag is pushed and the time when the release binaries are published. Fix #6112
This commit is contained in:
parent
abd62b638a
commit
82547263f8
|
@ -31,6 +31,60 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const QString versionUrl{QStringLiteral("https://api.github.com/repos/qTox/qTox/releases/latest")};
|
const QString versionUrl{QStringLiteral("https://api.github.com/repos/qTox/qTox/releases/latest")};
|
||||||
|
|
||||||
|
struct Version {
|
||||||
|
int major;
|
||||||
|
int minor;
|
||||||
|
int patch;
|
||||||
|
};
|
||||||
|
|
||||||
|
Version tagToVersion(QString tagName)
|
||||||
|
{
|
||||||
|
// capture tag name to avoid showing update available on dev builds which include hash as part of describe
|
||||||
|
QRegularExpression versionFormat{QStringLiteral("v([0-9]+)\\.([0-9]+)\\.([0-9]+)")};
|
||||||
|
auto matches = versionFormat.match(tagName);
|
||||||
|
assert(matches.lastCapturedIndex() == 3);
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
auto major = matches.captured(1).toInt(&ok);
|
||||||
|
assert(ok);
|
||||||
|
auto minor = matches.captured(2).toInt(&ok);
|
||||||
|
assert(ok);
|
||||||
|
auto patch = matches.captured(3).toInt(&ok);
|
||||||
|
assert(ok);
|
||||||
|
|
||||||
|
return {major, minor, patch};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isUpdateAvailable(Version current, Version available)
|
||||||
|
{
|
||||||
|
// A user may have a version greater than our latest release in the time between a tag being pushed and the release
|
||||||
|
// being published. Don't notify about an update in that case.
|
||||||
|
|
||||||
|
if (current.major < available.major) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (current.major > available.major) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.minor < available.minor) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (current.minor > available.minor) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.patch < available.patch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (current.patch > available.patch) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
UpdateCheck::UpdateCheck(const Settings& settings)
|
UpdateCheck::UpdateCheck(const Settings& settings)
|
||||||
|
@ -78,10 +132,10 @@ void UpdateCheck::handleResponse(QNetworkReply* reply)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// capture tag name to avoid showing update available on dev builds which include hash as part of describe
|
auto currentVer = tagToVersion(GIT_DESCRIBE);
|
||||||
QRegularExpression versionFormat{QStringLiteral("v[0-9]+.[0-9]+.[0-9]+")};
|
auto availableVer = tagToVersion(latestVersion);
|
||||||
QString curVer = versionFormat.match(GIT_DESCRIBE).captured(0);
|
|
||||||
if (latestVersion != curVer) {
|
if (isUpdateAvailable(currentVer, availableVer)) {
|
||||||
qInfo() << "Update available to version" << latestVersion;
|
qInfo() << "Update available to version" << latestVersion;
|
||||||
QUrl link{mainMap["html_url"].toString()};
|
QUrl link{mainMap["html_url"].toString()};
|
||||||
emit updateAvailable(latestVersion, link);
|
emit updateAvailable(latestVersion, link);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user