feat: improve logic and ui of version checking module
This commit is contained in:
parent
fcc31759f8
commit
5ac4ee46c5
@ -38,7 +38,7 @@ UpdateTab::UpdateTab(QWidget* parent)
|
|||||||
: QWidget(parent), current_version_(GFProjectVersion()) {
|
: QWidget(parent), current_version_(GFProjectVersion()) {
|
||||||
auto* layout = new QVBoxLayout();
|
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();
|
auto* current_version_layout = new QVBoxLayout();
|
||||||
current_version_label_ = new QLabel();
|
current_version_label_ = new QLabel();
|
||||||
current_version_label_->setText("<center>" + tr("Current Version") +
|
current_version_label_->setText("<center>" + tr("Current Version") +
|
||||||
@ -48,9 +48,9 @@ UpdateTab::UpdateTab(QWidget* parent)
|
|||||||
latest_version_label_ = new QLabel();
|
latest_version_label_ = new QLabel();
|
||||||
current_version_layout->addWidget(current_version_label_);
|
current_version_layout->addWidget(current_version_label_);
|
||||||
current_version_layout->addWidget(latest_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();
|
auto* upgrade_info_layout = new QVBoxLayout();
|
||||||
upgrade_label_ = new QLabel();
|
upgrade_label_ = new QLabel();
|
||||||
upgrade_label_->setWordWrap(true);
|
upgrade_label_->setWordWrap(true);
|
||||||
@ -61,20 +61,24 @@ UpdateTab::UpdateTab(QWidget* parent)
|
|||||||
pb_->setTextVisible(false);
|
pb_->setTextVisible(false);
|
||||||
upgrade_info_layout->addWidget(upgrade_label_);
|
upgrade_info_layout->addWidget(upgrade_label_);
|
||||||
upgrade_info_layout->addWidget(pb_);
|
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();
|
auto* release_note_layout = new QVBoxLayout();
|
||||||
release_note_viewer_ = new QTextEdit();
|
release_note_viewer_ = new QTextEdit();
|
||||||
release_note_viewer_->setReadOnly(true);
|
release_note_viewer_->setReadOnly(true);
|
||||||
release_note_viewer_->setAcceptRichText(true);
|
release_note_viewer_->setAcceptRichText(true);
|
||||||
release_note_viewer_->hide();
|
release_note_viewer_->hide();
|
||||||
release_note_layout->addWidget(release_note_viewer_);
|
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);
|
current_version_box_->hide();
|
||||||
layout->addWidget(upgrade_info_box);
|
release_note_box_->hide();
|
||||||
layout->addWidget(release_note_box);
|
upgrade_info_box_->hide();
|
||||||
|
|
||||||
|
layout->addWidget(current_version_box_);
|
||||||
|
layout->addWidget(upgrade_info_box_);
|
||||||
|
layout->addWidget(release_note_box_);
|
||||||
|
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
@ -107,6 +111,21 @@ void UpdateTab::slot_show_version_status() {
|
|||||||
|
|
||||||
if (is_loading_done == 0) {
|
if (is_loading_done == 0) {
|
||||||
MLogDebug("version info loading haven't been done yet.");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,61 +150,75 @@ void UpdateTab::slot_show_version_status() {
|
|||||||
GFGetModuleID(), GFModuleStrDup("version.release_note"),
|
GFGetModuleID(), GFModuleStrDup("version.release_note"),
|
||||||
GFModuleStrDup("")));
|
GFModuleStrDup("")));
|
||||||
|
|
||||||
|
FLOG_INFO("latest version from GitHub: %1", latest_version);
|
||||||
|
|
||||||
latest_version_label_->setText("<center><b>" +
|
latest_version_label_->setText("<center><b>" +
|
||||||
tr("Latest Version From Github") + ": " +
|
tr("Latest Version From Github") + ": " +
|
||||||
latest_version + "</b></center>");
|
latest_version + "</b></center>");
|
||||||
|
current_version_box_->show();
|
||||||
|
|
||||||
if (is_need_upgrade != 0) {
|
if (is_need_upgrade != 0) {
|
||||||
upgrade_label_->setText(
|
upgrade_label_->setText(
|
||||||
"<center>" + tr("Your current version is outdated.") +
|
"<center>" + tr("Your current version is outdated.") +
|
||||||
"</center><center>" + tr("Click") +
|
"</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.") +
|
tr("here") + "</a> " + tr("to download the latest stable version.") +
|
||||||
"</center>");
|
"</center>");
|
||||||
upgrade_label_->show();
|
upgrade_label_->show();
|
||||||
|
upgrade_info_box_->show();
|
||||||
} else if (is_current_a_withdrawn_version != 0) {
|
} else if (is_current_a_withdrawn_version != 0) {
|
||||||
upgrade_label_->setText(
|
upgrade_label_->setText(
|
||||||
"<center>" +
|
"<center>" +
|
||||||
tr("This version has critical issues and has been withdrawn. Please "
|
tr("This version has critical issues and has been withdrawn. Please "
|
||||||
"stop using it immediately.") +
|
"stop using it immediately.") +
|
||||||
"</center><center>" + tr("Click") +
|
"</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.") +
|
tr("here") + "</a> " + tr("to download the latest stable version.") +
|
||||||
"</center>");
|
"</center>");
|
||||||
upgrade_label_->show();
|
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(
|
upgrade_label_->setText(
|
||||||
"<center>" +
|
"<center>" +
|
||||||
tr("This is an unreleased version, possibly a beta. If stability is "
|
tr("This is an unreleased version, possibly a beta. If stability is "
|
||||||
"important to you, please avoid using this version.") +
|
"important to you, please avoid using this version.") +
|
||||||
"</center><center>" + tr("Click") +
|
"</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.") +
|
tr("here") + "</a> " + tr("to download the latest stable version.") +
|
||||||
"</center>");
|
"</center>");
|
||||||
upgrade_label_->show();
|
upgrade_label_->show();
|
||||||
|
upgrade_info_box_->show();
|
||||||
} else if (is_git_commit_hash_mismatch != 0) {
|
} else if (is_git_commit_hash_mismatch != 0) {
|
||||||
upgrade_label_->setText(
|
upgrade_label_->setText(
|
||||||
"<center>" +
|
"<center>" +
|
||||||
tr("The current version's commit hash does not match the official "
|
tr("The current version's commit hash does not match the official "
|
||||||
"release. This may indicate a modified or unofficial build.") +
|
"release. This may indicate a modified or unofficial build.") +
|
||||||
"</center><center>" + tr("Click") +
|
"</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("here") + "</a> " +
|
||||||
tr("to verify your installation or download the official version.") +
|
tr("to verify your installation or download the official version.") +
|
||||||
"</center>");
|
"</center>");
|
||||||
upgrade_label_->show();
|
upgrade_label_->show();
|
||||||
|
upgrade_info_box_->show();
|
||||||
} else {
|
} else {
|
||||||
upgrade_label_->setText(
|
upgrade_label_->setText("<center>" +
|
||||||
"<center>" +
|
tr("You are using the latest stable version. No "
|
||||||
tr("You are using the latest stable version. No action is required.") +
|
"action is required.") +
|
||||||
"</center>");
|
"</center>");
|
||||||
upgrade_label_->show();
|
upgrade_label_->show();
|
||||||
|
upgrade_info_box_->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!release_note.trimmed().isEmpty()) {
|
if (!release_note.trimmed().isEmpty()) {
|
||||||
release_note_viewer_->clear();
|
release_note_viewer_->clear();
|
||||||
release_note_viewer_->setMarkdown(release_note);
|
release_note_viewer_->setMarkdown(release_note);
|
||||||
release_note_viewer_->show();
|
release_note_viewer_->show();
|
||||||
|
release_note_box_->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,9 @@ class UpdateTab : public QWidget {
|
|||||||
QProgressBar* pb_; ///<
|
QProgressBar* pb_; ///<
|
||||||
QTextEdit* release_note_viewer_; ///<
|
QTextEdit* release_note_viewer_; ///<
|
||||||
QString current_version_; ///<
|
QString current_version_; ///<
|
||||||
|
QGroupBox* release_note_box_;
|
||||||
|
QGroupBox* upgrade_info_box_;
|
||||||
|
QGroupBox* current_version_box_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -73,21 +73,20 @@ auto VersionCheckTask::Run() -> int {
|
|||||||
void VersionCheckTask::slot_parse_reply(QNetworkReply* reply) {
|
void VersionCheckTask::slot_parse_reply(QNetworkReply* reply) {
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
if (reply->error() == QNetworkReply::NoError) {
|
||||||
FLOG_DEBUG("get reply from url: %1", reply->url().toString());
|
FLOG_DEBUG("get reply from url: %1", reply->url().toString());
|
||||||
|
switch (replies_.indexOf(reply)) {
|
||||||
|
case 0:
|
||||||
|
slot_parse_latest_version_info(reply);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
slot_parse_current_version_info(reply);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
slot_parse_current_tag_info(reply);
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
FLOG_DEBUG("get reply from url: %1, error: %2", reply->url().toString(),
|
FLOG_DEBUG("get reply from url: %1, error: %2 %3", reply->url().toString(),
|
||||||
reply->errorString());
|
reply->errorString(), reply->readAll());
|
||||||
}
|
|
||||||
|
|
||||||
switch (replies_.indexOf(reply)) {
|
|
||||||
case 0:
|
|
||||||
slot_parse_latest_version_info(reply);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
slot_parse_current_version_info(reply);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
slot_parse_current_tag_info(reply);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
replies_.removeAll(reply);
|
replies_.removeAll(reply);
|
||||||
@ -113,15 +112,16 @@ void VersionCheckTask::slot_parse_latest_version_info(QNetworkReply* reply) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString latest_version = latest_reply_json["tag_name"].toString();
|
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+))");
|
QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))");
|
||||||
auto version_match = re.match(latest_version);
|
auto version_match = re.match(latest_version);
|
||||||
if (version_match.hasMatch()) {
|
if (version_match.hasMatch()) {
|
||||||
latest_version = version_match.captured(0);
|
latest_version = version_match.captured(0);
|
||||||
} else {
|
} else {
|
||||||
latest_version = current_version_;
|
latest_version = "";
|
||||||
MLogWarn(QString("latest version unknown, set to current version: %1")
|
FLOG_WARN("the raw tag name from github: %1 cannot match regex rules",
|
||||||
.arg(current_version_));
|
latest_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool prerelease = latest_reply_json["prerelease"].toBool();
|
bool prerelease = latest_reply_json["prerelease"].toBool();
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
#include "VersionCheckTask.h"
|
#include "VersionCheckTask.h"
|
||||||
|
|
||||||
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.version_checking",
|
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.version_checking",
|
||||||
"VersionChecking", "1.2.0",
|
"VersionChecking", "1.2.1",
|
||||||
"Try checking GpgFrontend version.", "Saturneric");
|
"Try checking GpgFrontend version.", "Saturneric");
|
||||||
|
|
||||||
DEFINE_TRANSLATIONS_STRUCTURE(ModuleVersionChecking);
|
DEFINE_TRANSLATIONS_STRUCTURE(ModuleVersionChecking);
|
||||||
|
Loading…
Reference in New Issue
Block a user