feat: improve logic and ui of version checking module

This commit is contained in:
saturneric 2024-12-01 22:40:49 +01:00
parent fcc31759f8
commit 5ac4ee46c5
4 changed files with 72 additions and 36 deletions

View File

@ -38,7 +38,7 @@ UpdateTab::UpdateTab(QWidget* parent)
: QWidget(parent), current_version_(GFProjectVersion()) {
auto* layout = new QVBoxLayout();
auto* current_version_box = new QGroupBox(tr("Current Version Information"));
current_version_box_ = new QGroupBox(tr("Current Version Information"));
auto* current_version_layout = new QVBoxLayout();
current_version_label_ = new QLabel();
current_version_label_->setText("<center>" + tr("Current Version") +
@ -48,9 +48,9 @@ UpdateTab::UpdateTab(QWidget* parent)
latest_version_label_ = new QLabel();
current_version_layout->addWidget(current_version_label_);
current_version_layout->addWidget(latest_version_label_);
current_version_box->setLayout(current_version_layout);
current_version_box_->setLayout(current_version_layout);
auto* upgrade_info_box = new QGroupBox(tr("Upgrade Information"));
upgrade_info_box_ = new QGroupBox(tr("Upgrade Information"));
auto* upgrade_info_layout = new QVBoxLayout();
upgrade_label_ = new QLabel();
upgrade_label_->setWordWrap(true);
@ -61,20 +61,24 @@ UpdateTab::UpdateTab(QWidget* parent)
pb_->setTextVisible(false);
upgrade_info_layout->addWidget(upgrade_label_);
upgrade_info_layout->addWidget(pb_);
upgrade_info_box->setLayout(upgrade_info_layout);
upgrade_info_box_->setLayout(upgrade_info_layout);
auto* release_note_box = new QGroupBox(tr("Release Notes"));
release_note_box_ = new QGroupBox(tr("Release Notes"));
auto* release_note_layout = new QVBoxLayout();
release_note_viewer_ = new QTextEdit();
release_note_viewer_->setReadOnly(true);
release_note_viewer_->setAcceptRichText(true);
release_note_viewer_->hide();
release_note_layout->addWidget(release_note_viewer_);
release_note_box->setLayout(release_note_layout);
release_note_box_->setLayout(release_note_layout);
layout->addWidget(current_version_box);
layout->addWidget(upgrade_info_box);
layout->addWidget(release_note_box);
current_version_box_->hide();
release_note_box_->hide();
upgrade_info_box_->hide();
layout->addWidget(current_version_box_);
layout->addWidget(upgrade_info_box_);
layout->addWidget(release_note_box_);
setLayout(layout);
}
@ -107,6 +111,21 @@ void UpdateTab::slot_show_version_status() {
if (is_loading_done == 0) {
MLogDebug("version info loading haven't been done yet.");
upgrade_label_->setText(
"<center>" +
tr("Unable to retrieve the latest version information. This may be "
"due "
"to a network issue or the server being unavailable.") +
"</center><center>" +
tr("Please check your internet connection or try again later.") +
"</center><center>" + tr("Alternatively, you can visit the") +
" <a "
"href=\"https://www.gpgfrontend.bktus.com/overview/downloads/\">" +
tr("official download page") + "</a> " +
tr("to check for the latest stable version.") + "</center>");
upgrade_label_->show();
upgrade_info_box_->show();
return;
}
@ -131,61 +150,75 @@ void UpdateTab::slot_show_version_status() {
GFGetModuleID(), GFModuleStrDup("version.release_note"),
GFModuleStrDup("")));
FLOG_INFO("latest version from GitHub: %1", latest_version);
latest_version_label_->setText("<center><b>" +
tr("Latest Version From Github") + ": " +
latest_version + "</b></center>");
current_version_box_->show();
if (is_need_upgrade != 0) {
upgrade_label_->setText(
"<center>" + tr("Your current version is outdated.") +
"</center><center>" + tr("Click") +
" <a href=\"https://www.gpgfrontend.bktus.com/overview/downloads/\">" +
" <a "
"href=\"https://www.gpgfrontend.bktus.com/overview/downloads/\">" +
tr("here") + "</a> " + tr("to download the latest stable version.") +
"</center>");
upgrade_label_->show();
upgrade_info_box_->show();
} else if (is_current_a_withdrawn_version != 0) {
upgrade_label_->setText(
"<center>" +
tr("This version has critical issues and has been withdrawn. Please "
"stop using it immediately.") +
"</center><center>" + tr("Click") +
" <a href=\"https://www.gpgfrontend.bktus.com/overview/downloads/\">" +
" <a "
"href=\"https://www.gpgfrontend.bktus.com/overview/downloads/\">" +
tr("here") + "</a> " + tr("to download the latest stable version.") +
"</center>");
upgrade_label_->show();
} else if (is_current_version_released == 0) {
upgrade_info_box_->show();
} else if (!latest_version.trimmed().isEmpty() &&
is_current_version_released == 0) {
upgrade_label_->setText(
"<center>" +
tr("This is an unreleased version, possibly a beta. If stability is "
"important to you, please avoid using this version.") +
"</center><center>" + tr("Click") +
" <a href=\"https://www.gpgfrontend.bktus.com/overview/downloads/\">" +
" <a "
"href=\"https://www.gpgfrontend.bktus.com/overview/downloads/\">" +
tr("here") + "</a> " + tr("to download the latest stable version.") +
"</center>");
upgrade_label_->show();
upgrade_info_box_->show();
} else if (is_git_commit_hash_mismatch != 0) {
upgrade_label_->setText(
"<center>" +
tr("The current version's commit hash does not match the official "
"release. This may indicate a modified or unofficial build.") +
"</center><center>" + tr("Click") +
" <a href=\"https://www.gpgfrontend.bktus.com/overview/downloads/\">" +
" <a "
"href=\"https://www.gpgfrontend.bktus.com/overview/downloads/\">" +
tr("here") + "</a> " +
tr("to verify your installation or download the official version.") +
"</center>");
upgrade_label_->show();
upgrade_info_box_->show();
} else {
upgrade_label_->setText(
"<center>" +
tr("You are using the latest stable version. No action is required.") +
upgrade_label_->setText("<center>" +
tr("You are using the latest stable version. No "
"action is required.") +
"</center>");
upgrade_label_->show();
upgrade_info_box_->show();
}
if (!release_note.trimmed().isEmpty()) {
release_note_viewer_->clear();
release_note_viewer_->setMarkdown(release_note);
release_note_viewer_->show();
release_note_box_->show();
}
}

View File

@ -43,6 +43,9 @@ class UpdateTab : public QWidget {
QProgressBar* pb_; ///<
QTextEdit* release_note_viewer_; ///<
QString current_version_; ///<
QGroupBox* release_note_box_;
QGroupBox* upgrade_info_box_;
QGroupBox* current_version_box_;
public:
/**

View File

@ -73,11 +73,6 @@ auto VersionCheckTask::Run() -> int {
void VersionCheckTask::slot_parse_reply(QNetworkReply* reply) {
if (reply->error() == QNetworkReply::NoError) {
FLOG_DEBUG("get reply from url: %1", reply->url().toString());
} else {
FLOG_DEBUG("get reply from url: %1, error: %2", reply->url().toString(),
reply->errorString());
}
switch (replies_.indexOf(reply)) {
case 0:
slot_parse_latest_version_info(reply);
@ -89,6 +84,10 @@ void VersionCheckTask::slot_parse_reply(QNetworkReply* reply) {
slot_parse_current_tag_info(reply);
break;
}
} else {
FLOG_DEBUG("get reply from url: %1, error: %2 %3", reply->url().toString(),
reply->errorString(), reply->readAll());
}
replies_.removeAll(reply);
reply->deleteLater();
@ -113,15 +112,16 @@ void VersionCheckTask::slot_parse_latest_version_info(QNetworkReply* reply) {
}
QString latest_version = latest_reply_json["tag_name"].toString();
FLOG_DEBUG("raw tag name from github: %1", latest_version);
QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))");
auto version_match = re.match(latest_version);
if (version_match.hasMatch()) {
latest_version = version_match.captured(0);
} else {
latest_version = current_version_;
MLogWarn(QString("latest version unknown, set to current version: %1")
.arg(current_version_));
latest_version = "";
FLOG_WARN("the raw tag name from github: %1 cannot match regex rules",
latest_version);
}
bool prerelease = latest_reply_json["prerelease"].toBool();

View File

@ -44,7 +44,7 @@
#include "VersionCheckTask.h"
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.version_checking",
"VersionChecking", "1.2.0",
"VersionChecking", "1.2.1",
"Try checking GpgFrontend version.", "Saturneric");
DEFINE_TRANSLATIONS_STRUCTURE(ModuleVersionChecking);