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 {
|
||||
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
|
||||
|
||||
UpdateCheck::UpdateCheck(const Settings& settings)
|
||||
|
@ -78,10 +132,10 @@ void UpdateCheck::handleResponse(QNetworkReply* reply)
|
|||
return;
|
||||
}
|
||||
|
||||
// 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]+")};
|
||||
QString curVer = versionFormat.match(GIT_DESCRIBE).captured(0);
|
||||
if (latestVersion != curVer) {
|
||||
auto currentVer = tagToVersion(GIT_DESCRIBE);
|
||||
auto availableVer = tagToVersion(latestVersion);
|
||||
|
||||
if (isUpdateAvailable(currentVer, availableVer)) {
|
||||
qInfo() << "Update available to version" << latestVersion;
|
||||
QUrl link{mainMap["html_url"].toString()};
|
||||
emit updateAvailable(latestVersion, link);
|
||||
|
|
Loading…
Reference in New Issue
Block a user