1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #6250

powerjungle (3):
      feat(logging): check if current code is tagged
      fix(logging): check if version is stable before other checks
      refactor(logging): change VERSION_REGEX_STRING to a const
This commit is contained in:
sudden6 2020-11-18 23:55:51 +01:00
commit b0f37063e7
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 36 additions and 1 deletions

View File

@ -214,6 +214,24 @@ add_definitions(
-DGIT_VERSION="${GIT_VERSION}"
)
if (NOT GIT_DESCRIBE_EXACT)
execute_process(
COMMAND git describe --exact-match --tags HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_EXACT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_DESCRIBE_EXACT)
set(GIT_DESCRIBE_EXACT "Nightly")
endif()
endif()
add_definitions(
-DGIT_DESCRIBE_EXACT="${GIT_DESCRIBE_EXACT}"
)
set(APPLE_EXT False)
if (FOUNDATION_FOUND AND IOKIT_FOUND)
set(APPLE_EXT True)

View File

@ -31,6 +31,7 @@
namespace {
const QString versionUrl{QStringLiteral("https://api.github.com/repos/qTox/qTox/releases/latest")};
const QString versionRegexString{QStringLiteral("v([0-9]+)\\.([0-9]+)\\.([0-9]+)")};
struct Version {
int major;
@ -41,7 +42,7 @@ struct Version {
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]+)")};
QRegularExpression versionFormat(versionRegexString);
auto matches = versionFormat.match(tagName);
assert(matches.lastCapturedIndex() == 3);
@ -85,6 +86,17 @@ bool isUpdateAvailable(Version current, Version available)
return false;
}
bool isCurrentVersionStable()
{
QRegularExpression versionRegex(versionRegexString);
auto currentVer = versionRegex.match(GIT_DESCRIBE_EXACT);
if (currentVer.hasMatch()){
return true;
} else {
return false;
}
}
} // namespace
UpdateCheck::UpdateCheck(const Settings& settings)
@ -108,6 +120,10 @@ void UpdateCheck::checkForUpdate()
void UpdateCheck::handleResponse(QNetworkReply* reply)
{
if (isCurrentVersionStable() == false) {
qWarning() << "qTox is running an unstable version";
}
assert(reply != nullptr);
if (reply == nullptr) {
qWarning() << "Update check returned null reply, ignoring";
@ -143,5 +159,6 @@ void UpdateCheck::handleResponse(QNetworkReply* reply)
qInfo() << "qTox is up to date";
emit upToDate();
}
reply->deleteLater();
}