diff options
Diffstat (limited to 'src')
7 files changed, 139 insertions, 62 deletions
diff --git a/src/module/integrated/version_checking_module/SoftwareVersion.cpp b/src/module/integrated/version_checking_module/SoftwareVersion.cpp index f77687d5..23b50dae 100644 --- a/src/module/integrated/version_checking_module/SoftwareVersion.cpp +++ b/src/module/integrated/version_checking_module/SoftwareVersion.cpp @@ -79,18 +79,20 @@ bool VersionCheckingModule::SoftwareVersion::NeedUpgrade() const { current_version, latest_version, version_compare(current_version, latest_version)); - MODULE_LOG_DEBUG("load done: {}, pre-release: {}, draft: {}", load_info_done, - latest_prerelease, latest_draft); - return load_info_done && !latest_prerelease && !latest_draft && + MODULE_LOG_DEBUG("load done: {}, pre-release: {}, draft: {}", loading_done, + latest_prerelease_version_from_remote, + latest_draft_from_remote); + return loading_done && !latest_prerelease_version_from_remote && + !latest_draft_from_remote && version_compare(current_version, latest_version) < 0; } -bool VersionCheckingModule::SoftwareVersion::VersionWithDrawn() const { - return load_info_done && !current_version_found && current_prerelease && - !current_draft; +bool VersionCheckingModule::SoftwareVersion::VersionWithdrawn() const { + return loading_done && !current_version_publish_in_remote && + current_version_is_a_prerelease && !current_version_is_drafted; } bool VersionCheckingModule::SoftwareVersion::CurrentVersionReleased() const { - return load_info_done && current_version_found; + return loading_done && current_version_publish_in_remote; } } // namespace GpgFrontend::Module::Integrated::VersionCheckingModule
\ No newline at end of file diff --git a/src/module/integrated/version_checking_module/SoftwareVersion.h b/src/module/integrated/version_checking_module/SoftwareVersion.h index a95c8b20..513ab1b9 100644 --- a/src/module/integrated/version_checking_module/SoftwareVersion.h +++ b/src/module/integrated/version_checking_module/SoftwareVersion.h @@ -36,16 +36,16 @@ namespace GpgFrontend::Module::Integrated::VersionCheckingModule { * */ struct SoftwareVersion { - std::string latest_version; ///< - std::string current_version; ///< - bool latest_prerelease = false; ///< - bool latest_draft = false; ///< - bool current_prerelease = false; ///< - bool current_draft = false; ///< - bool load_info_done = false; ///< - bool current_version_found = false; ///< - std::string publish_date; ///< - std::string release_note; ///< + std::string latest_version; ///< + std::string current_version; ///< + bool latest_prerelease_version_from_remote = false; ///< + bool latest_draft_from_remote = false; ///< + bool current_version_is_a_prerelease = false; ///< + bool current_version_is_drafted = false; ///< + bool loading_done = false; ///< + bool current_version_publish_in_remote = false; ///< + std::string publish_date; ///< + std::string release_note; ///< /** * @brief @@ -53,7 +53,7 @@ struct SoftwareVersion { * @return true * @return false */ - [[nodiscard]] bool InfoValid() const { return load_info_done; } + [[nodiscard]] bool InfoValid() const { return loading_done; } /** * @brief @@ -69,7 +69,7 @@ struct SoftwareVersion { * @return true * @return false */ - [[nodiscard]] bool VersionWithDrawn() const; + [[nodiscard]] bool VersionWithdrawn() const; /** * @brief diff --git a/src/module/integrated/version_checking_module/VersionCheckTask.cpp b/src/module/integrated/version_checking_module/VersionCheckTask.cpp index 163bae6f..c3b61339 100644 --- a/src/module/integrated/version_checking_module/VersionCheckTask.cpp +++ b/src/module/integrated/version_checking_module/VersionCheckTask.cpp @@ -62,7 +62,7 @@ void VersionCheckTask::Run() { &VersionCheckTask::slot_parse_latest_version_info); // loading done - version_.load_info_done = true; + version_.loading_done = true; } catch (...) { MODULE_LOG_ERROR("unknown error occurred"); @@ -103,14 +103,14 @@ void VersionCheckTask::slot_parse_latest_version_info() { std::string publish_date = latest_reply_json["published_at"]; std::string release_note = latest_reply_json["body"]; version_.latest_version = latest_version; - version_.latest_prerelease = prerelease; - version_.latest_draft = draft; + version_.latest_prerelease_version_from_remote = prerelease; + version_.latest_draft_from_remote = draft; version_.publish_date = publish_date; version_.release_note = release_note; } } catch (...) { MODULE_LOG_ERROR("unknown error occurred"); - version_.load_info_done = false; + version_.loading_done = false; } if (latest_reply_ != nullptr) { @@ -145,28 +145,27 @@ void VersionCheckTask::slot_parse_current_version_info() { MODULE_LOG_ERROR( "current version request network error, null reply object"); } - - version_.current_version_found = false; - version_.load_info_done = false; + version_.current_version_publish_in_remote = false; + version_.loading_done = false; } else { - version_.current_version_found = true; + version_.current_version_publish_in_remote = true; current_reply_bytes_ = current_reply_->readAll(); MODULE_LOG_DEBUG("current version: {}", current_reply_bytes_.size()); auto current_reply_json = nlohmann::json::parse(current_reply_bytes_.toStdString()); bool current_prerelease = current_reply_json["prerelease"], current_draft = current_reply_json["draft"]; - version_.latest_prerelease = current_prerelease; - version_.latest_draft = current_draft; - version_.load_info_done = true; + version_.latest_prerelease_version_from_remote = current_prerelease; + version_.latest_draft_from_remote = current_draft; + version_.loading_done = true; } } catch (...) { MODULE_LOG_ERROR("unknown error occurred"); - version_.load_info_done = false; + version_.loading_done = false; } MODULE_LOG_DEBUG("current version parse done: {}", - version_.current_version_found); + version_.current_version_publish_in_remote); if (current_reply_ != nullptr) { current_reply_->deleteLater(); diff --git a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp index 7ab02ef2..233b4225 100644 --- a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp +++ b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp @@ -28,14 +28,25 @@ #include "VersionCheckingModule.h" +#include <qobject.h> + +#include "Log.h" +#include "SoftwareVersion.h" #include "VersionCheckTask.h" +#include "core/module/Module.h" +#include "core/module/ModuleManager.h" namespace GpgFrontend::Module::Integrated::VersionCheckingModule { VersionCheckingModule::VersionCheckingModule() : Module("com.bktus.gpgfrontend.module.integrated.versionchecking", "1.0.0", ModuleMetaData{{"description", "try to check gpgfrontend version"}, - {"author", "saturneric"}}) {} + {"author", "saturneric"}}) { + connect(this, &VersionCheckingModule::SignalVersionCheckDone, this, + &VersionCheckingModule::SlotVersionCheckDone); +} + +VersionCheckingModule::~VersionCheckingModule() = default; bool VersionCheckingModule::Register() { MODULE_LOG_INFO("version checking module registering"); @@ -52,9 +63,44 @@ int VersionCheckingModule::Exec(EventRefrernce event) { MODULE_LOG_INFO("version checking module executing, event id: {}", event->GetIdentifier()); - getTaskRunner()->PostTask(new VersionCheckTask()); + auto* task = new VersionCheckTask(); + connect(task, &VersionCheckTask::SignalUpgradeVersion, this, + &VersionCheckingModule::SignalVersionCheckDone); + getTaskRunner()->PostTask(task); return 0; } bool VersionCheckingModule::Deactive() { return true; } + +void VersionCheckingModule::SlotVersionCheckDone(SoftwareVersion version) { + MODULE_LOG_DEBUG("registering software information info to rt"); + ModuleManager::GetInstance()->UpsertRTValue(GetModuleIdentifier(), + "version.current_version", + version.current_version); + ModuleManager::GetInstance()->UpsertRTValue( + GetModuleIdentifier(), "version.loading_done", version.loading_done); + ModuleManager::GetInstance()->UpsertRTValue( + GetModuleIdentifier(), "version.latest_version", version.latest_version); + ModuleManager::GetInstance()->UpsertRTValue( + GetModuleIdentifier(), "version.current_version_is_drafted", + version.current_version_is_drafted); + ModuleManager::GetInstance()->UpsertRTValue( + GetModuleIdentifier(), "version.current_version_is_a_prerelease", + version.current_version_is_a_prerelease); + ModuleManager::GetInstance()->UpsertRTValue( + GetModuleIdentifier(), "version.current_version_publish_in_remote", + version.current_version_publish_in_remote); + ModuleManager::GetInstance()->UpsertRTValue( + GetModuleIdentifier(), "version.latest_prerelease_version_from_remote", + version.latest_prerelease_version_from_remote); + ModuleManager::GetInstance()->UpsertRTValue( + GetModuleIdentifier(), "version.need_upgrade", version.NeedUpgrade()); + ModuleManager::GetInstance()->UpsertRTValue( + GetModuleIdentifier(), "version.current_version_released", + version.CurrentVersionReleased()); + ModuleManager::GetInstance()->UpsertRTValue( + GetModuleIdentifier(), "version.current_a_withdrawn_version", + version.VersionWithdrawn()); + MODULE_LOG_DEBUG("register software information to rt done"); +} } // namespace GpgFrontend::Module::Integrated::VersionCheckingModule diff --git a/src/module/integrated/version_checking_module/VersionCheckingModule.h b/src/module/integrated/version_checking_module/VersionCheckingModule.h index 83775541..53119529 100644 --- a/src/module/integrated/version_checking_module/VersionCheckingModule.h +++ b/src/module/integrated/version_checking_module/VersionCheckingModule.h @@ -30,14 +30,19 @@ #include <module/sdk/GpgFrontendModuleSDK.h> +#include <memory> + #include "SoftwareVersion.h" namespace GpgFrontend::Module::Integrated::VersionCheckingModule { class GPGFRONTEND_MODULE_SDK_EXPORT VersionCheckingModule : public Module { + Q_OBJECT public: VersionCheckingModule(); + ~VersionCheckingModule(); + virtual bool Register() override; virtual bool Active() override; @@ -45,5 +50,13 @@ class GPGFRONTEND_MODULE_SDK_EXPORT VersionCheckingModule : public Module { virtual int Exec(EventRefrernce) override; virtual bool Deactive() override; + + signals: + + void SignalVersionCheckDone(SoftwareVersion); + + public slots: + + void SlotVersionCheckDone(SoftwareVersion); }; } // namespace GpgFrontend::Module::Integrated::VersionCheckingModule diff --git a/src/ui/dialog/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp index 098c7ad0..acd76c97 100644 --- a/src/ui/dialog/help/AboutDialog.cpp +++ b/src/ui/dialog/help/AboutDialog.cpp @@ -30,9 +30,13 @@ #include <openssl/opensslv.h> +#include <string> + #include "GpgFrontendBuildInfo.h" #include "core/function/GlobalSettingStation.h" +#include "core/module/ModuleManager.h" #include "core/thread/TaskRunnerGetter.h" +#include "spdlog/spdlog.h" #include "ui/dialog/help/GnupgTab.h" #include "ui/thread/VersionCheckTask.h" @@ -73,10 +77,7 @@ AboutDialog::AboutDialog(int defaultIndex, QWidget* parent) this->show(); } -void AboutDialog::showEvent(QShowEvent* ev) { - QDialog::showEvent(ev); - update_tab_->getLatestVersion(); -} +void AboutDialog::showEvent(QShowEvent* ev) { QDialog::showEvent(ev); } InfoTab::InfoTab(QWidget* parent) : QWidget(parent) { auto* pixmap = new QPixmap(":gpgfrontend-logo.png"); @@ -203,28 +204,50 @@ UpdateTab::UpdateTab(QWidget* parent) : QWidget(parent) { setLayout(layout); } -void UpdateTab::getLatestVersion() { - this->pb_->setHidden(false); - - SPDLOG_DEBUG("try to get latest version"); +void UpdateTab::slot_show_version_status() { + this->pb_->setHidden(true); + SPDLOG_DEBUG("loading version info from rt"); - auto* version_task = new VersionCheckTask(); + auto is_loading_done = + std::any_cast<bool>(Module::ModuleManager::GetInstance()->RetrieveRTValue( + "__module_com.bktus.gpgfrontend.module.integrated." + "versionchecking", + "version.loading_done")); - connect(version_task, &VersionCheckTask::SignalUpgradeVersion, this, - &UpdateTab::slot_show_version_status); + if (!is_loading_done) { + SPDLOG_DEBUG("version info loading havn't been done yet"); + this->pb_->setHidden(false); + } - Thread::TaskRunnerGetter::GetInstance() - .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network) - ->PostTask(version_task); -} + auto is_need_upgrade = + std::any_cast<bool>(Module::ModuleManager::GetInstance()->RetrieveRTValue( + "__module_com.bktus.gpgfrontend.module.integrated." + "versionchecking", + "version.need_upgrade")); + + auto is_current_a_withdrawn_version = + std::any_cast<bool>(Module::ModuleManager::GetInstance()->RetrieveRTValue( + "__module_com.bktus.gpgfrontend.module.integrated." + "versionchecking", + "version.current_a_withdrawn_version")); + + auto is_current_version_released = + std::any_cast<bool>(Module::ModuleManager::GetInstance()->RetrieveRTValue( + "__module_com.bktus.gpgfrontend.module.integrated." + "versionchecking", + "version.current_version_released")); + + auto latest_version = std::any_cast<std::string>( + Module::ModuleManager::GetInstance()->RetrieveRTValue( + "__module_com.bktus.gpgfrontend.module.integrated." + "versionchecking", + "version.latest_version")); -void UpdateTab::slot_show_version_status(const SoftwareVersion& version) { - this->pb_->setHidden(true); latest_version_label_->setText( "<center><b>" + QString(_("Latest Version From Github")) + ": " + - version.latest_version.c_str() + "</b></center>"); + latest_version.c_str() + "</b></center>"); - if (version.NeedUpgrade()) { + if (is_need_upgrade) { upgrade_label_->setText( "<center>" + QString(_("The current version is less than the latest version on " @@ -235,7 +258,7 @@ void UpdateTab::slot_show_version_status(const SoftwareVersion& version) { _("Here") + "</a> " + _("to download the latest stable version.") + "</center>"); upgrade_label_->show(); - } else if (version.VersionWithDrawn()) { + } else if (is_current_a_withdrawn_version) { upgrade_label_->setText( "<center>" + QString(_("This version has serious problems and has been withdrawn. " @@ -246,7 +269,7 @@ void UpdateTab::slot_show_version_status(const SoftwareVersion& version) { _("Here") + "</a> " + _("to download the latest stable version.") + "</center>"); upgrade_label_->show(); - } else if (!version.CurrentVersionReleased()) { + } else if (!is_current_version_released) { upgrade_label_->setText( "<center>" + QString(_("This version has not been released yet, it may be a beta " diff --git a/src/ui/dialog/help/AboutDialog.h b/src/ui/dialog/help/AboutDialog.h index 0caaf64b..d8924011 100644 --- a/src/ui/dialog/help/AboutDialog.h +++ b/src/ui/dialog/help/AboutDialog.h @@ -88,19 +88,13 @@ class UpdateTab : public QWidget { */ explicit UpdateTab(QWidget* parent = nullptr); - /** - * @brief Get the Latest Version object - * - */ - void getLatestVersion(); - private slots: /** * @brief * * @param version */ - void slot_show_version_status(const SoftwareVersion& version); + void slot_show_version_status(); signals: /** |