diff options
| author | saturneric <[email protected]> | 2026-09-22 21:19:07 +0200 |
|---|---|---|
| committer | saturneric <[email protected]> | 2026-09-22 21:19:07 +0200 |
| commit | 4e4635a4b8d2034287b59a215c099b44821480ad (patch) | |
| tree | 642a4269950cc7cc30b912d3cf8670b3de217d8e /src | |
| parent | refactor(pgp-inspect): migrate to context-aware SDK APIs (diff) | |
| download | modules-4e4635a4b8d2034287b59a215c099b44821480ad.tar.gz modules-4e4635a4b8d2034287b59a215c099b44821480ad.zip | |
refactor(version-check): migrate to SDK context APIs
- replace legacy version, cache, state, and settings APIs
- pass the module SDK context to application helpers
- update version comparisons to avoid temporary allocations
- declare the storage capability in the module manifest
Diffstat (limited to 'src')
| -rw-r--r-- | src/m_ver_check/BKTUSVersionCheckTask.cpp | 18 | ||||
| -rw-r--r-- | src/m_ver_check/GitHubVersionCheckTask.cpp | 18 | ||||
| -rw-r--r-- | src/m_ver_check/SoftwareVersion.cpp | 7 | ||||
| -rw-r--r-- | src/m_ver_check/UpdateTab.cpp | 46 | ||||
| -rw-r--r-- | src/m_ver_check/Utils.cpp | 74 | ||||
| -rw-r--r-- | src/m_ver_check/VersionCheckingModule.cpp | 27 | ||||
| -rw-r--r-- | src/m_ver_check/module.json | 5 |
7 files changed, 103 insertions, 92 deletions
diff --git a/src/m_ver_check/BKTUSVersionCheckTask.cpp b/src/m_ver_check/BKTUSVersionCheckTask.cpp index 3fe9c0e..6f2da63 100644 --- a/src/m_ver_check/BKTUSVersionCheckTask.cpp +++ b/src/m_ver_check/BKTUSVersionCheckTask.cpp @@ -28,8 +28,6 @@ #include "BKTUSVersionCheckTask.h" -#include <GFSDKBasic.h> -#include <GFSDKExtra.h> #include <GFSDKLog.h> #include <qobject.h> @@ -43,16 +41,16 @@ BKTUSVersionCheckTask::BKTUSVersionCheckTask() : network_manager_(new QNetworkAccessManager(this)), - current_version_(GFProjectVersion()) { + current_version_(GFAppVersion(GFModuleSdkContext())) { qRegisterMetaType<SoftwareVersion>("SoftwareVersion"); meta_.api = "BKTUS.com"; meta_.current_version = current_version_; - meta_.local_commit_hash = GFProjectGitCommitHash(); + meta_.local_commit_hash = GFAppGitCommitHash(GFModuleSdkContext()); connect(this, &BKTUSVersionCheckTask::SignalUpgradeVersion, this, [](const SoftwareVersion& sv) { - GFDurableCacheSave( - "update_checking_cache", + gf::sdk::SetCacheText( + GFModuleSdkContext(), GF_STORE_DURABLE, "update_checking_cache", (QJsonDocument(sv.ToJson()).toJson()).constData()); }); } @@ -75,7 +73,7 @@ auto BKTUSVersionCheckTask::Run() -> int { for (const QUrl& url : urls) { QNetworkRequest request(url); request.setHeader(QNetworkRequest::UserAgentHeader, - GFHttpRequestUserAgent()); + GFAppUserAgent(GFModuleSdkContext())); auto* reply = network_manager_->get(request); reply->setProperty("GFCheckIndex", index++); replies_.append(reply); @@ -164,9 +162,9 @@ void BKTUSVersionCheckTask::slot_parse_latest_version_info( if (!SoftwareVersion::SameSeries(version, current_version_)) continue; if (!meta_.latest_version.isEmpty() && - GFCompareSoftwareVersion( - GFModuleStrDup(version.toUtf8()), - GFModuleStrDup(meta_.latest_version.toUtf8())) <= 0) { + GFCompareSoftwareVersion(version.toUtf8().constData(), + meta_.latest_version.toUtf8().constData()) <= + 0) { continue; } diff --git a/src/m_ver_check/GitHubVersionCheckTask.cpp b/src/m_ver_check/GitHubVersionCheckTask.cpp index cb9ca63..e0ba9d9 100644 --- a/src/m_ver_check/GitHubVersionCheckTask.cpp +++ b/src/m_ver_check/GitHubVersionCheckTask.cpp @@ -28,8 +28,6 @@ #include "GitHubVersionCheckTask.h" -#include <GFSDKBasic.h> -#include <GFSDKExtra.h> #include <GFSDKLog.h> #include <qobject.h> @@ -42,16 +40,16 @@ GitHubVersionCheckTask::GitHubVersionCheckTask() : network_manager_(new QNetworkAccessManager(this)), - current_version_(GFProjectVersion()) { + current_version_(GFAppVersion(GFModuleSdkContext())) { qRegisterMetaType<SoftwareVersion>("SoftwareVersion"); meta_.api = "GitHub"; meta_.current_version = current_version_; - meta_.local_commit_hash = GFProjectGitCommitHash(); + meta_.local_commit_hash = GFAppGitCommitHash(GFModuleSdkContext()); connect(this, &GitHubVersionCheckTask::SignalUpgradeVersion, this, [](const SoftwareVersion& sv) { - GFDurableCacheSave( - "update_checking_cache", + gf::sdk::SetCacheText( + GFModuleSdkContext(), GF_STORE_DURABLE, "update_checking_cache", (QJsonDocument(sv.ToJson()).toJson()).constData()); }); } @@ -74,7 +72,7 @@ auto GitHubVersionCheckTask::Run() -> int { for (const QUrl& url : urls) { QNetworkRequest request(url); request.setHeader(QNetworkRequest::UserAgentHeader, - GFHttpRequestUserAgent()); + GFAppUserAgent(GFModuleSdkContext())); QNetworkReply* reply = network_manager_->get(request); reply->setProperty("GFCheckIndex", index++); replies_.append(reply); @@ -148,9 +146,9 @@ void GitHubVersionCheckTask::slot_parse_latest_version_info( if (!SoftwareVersion::SameSeries(version, current_version_)) continue; if (!meta_.latest_version.isEmpty() && - GFCompareSoftwareVersion( - GFModuleStrDup(version.toUtf8()), - GFModuleStrDup(meta_.latest_version.toUtf8())) <= 0) { + GFCompareSoftwareVersion(version.toUtf8().constData(), + meta_.latest_version.toUtf8().constData()) <= + 0) { continue; } diff --git a/src/m_ver_check/SoftwareVersion.cpp b/src/m_ver_check/SoftwareVersion.cpp index a91d096..ed74cb3 100644 --- a/src/m_ver_check/SoftwareVersion.cpp +++ b/src/m_ver_check/SoftwareVersion.cpp @@ -28,8 +28,7 @@ #include "SoftwareVersion.h" -#include <GFSDKBasic.h> -#include <GFSDKExtra.h> +#include <GFModule.h> #include <GFSDKLog.h> #include <QJsonDocument> @@ -38,8 +37,8 @@ auto SoftwareVersion::NeedUpgrade() const -> bool { return !latest_version.isEmpty() && - GFCompareSoftwareVersion(GFModuleStrDup(current_version.toUtf8()), - GFModuleStrDup(latest_version.toUtf8())) < 0; + GFCompareSoftwareVersion(current_version.toUtf8().constData(), + latest_version.toUtf8().constData()) < 0; } auto SoftwareVersion::VersionWithdrawn() const -> bool { diff --git a/src/m_ver_check/UpdateTab.cpp b/src/m_ver_check/UpdateTab.cpp index 7391513..02727d0 100644 --- a/src/m_ver_check/UpdateTab.cpp +++ b/src/m_ver_check/UpdateTab.cpp @@ -29,8 +29,6 @@ #include "UpdateTab.h" #include "GFModule.h" -#include "GFSDKBasic.h" -#include "GFSDKModule.h" #include "VersionCheckingModule.h" // @@ -38,7 +36,7 @@ #include "GitHubVersionCheckTask.h" UpdateTab::UpdateTab(QWidget* parent) - : QWidget(parent), current_version_(GFProjectVersion()) { + : QWidget(parent), current_version_(GFAppVersion(GFModuleSdkContext())) { auto* layout = new QVBoxLayout(); current_version_box_ = new QGroupBox(tr("Current Version Information")); @@ -105,8 +103,8 @@ void UpdateTab::slot_show_version_status() { check_update_btn_->setEnabled(true); this->pb_->setHidden(true); - auto is_loading_done = GFModuleRetrieveRTValueOrDefaultBool( - GFGetModuleID(), "version.loading_done", 0); + auto is_loading_done = gf::sdk::StateBool( + GFModuleSdkContext(), GFGetModuleID(), "version.loading_done", 0); if (is_loading_done == 0) { MLogDebug("version info loading haven't been done yet."); @@ -127,25 +125,25 @@ void UpdateTab::slot_show_version_status() { return; } - auto is_need_upgrade = GFModuleRetrieveRTValueOrDefaultBool( - GFGetModuleID(), "version.need_upgrade", 0); + auto is_need_upgrade = gf::sdk::StateBool( + GFModuleSdkContext(), GFGetModuleID(), "version.need_upgrade", 0); auto is_current_version_publish_in_remote = - GFModuleRetrieveRTValueOrDefaultBool( - GFGetModuleID(), "version.current_version_publish_in_remote", 0); + gf::sdk::StateBool(GFModuleSdkContext(), GFGetModuleID(), + "version.current_version_publish_in_remote", 0); auto is_current_commit_hash_publish_in_remote = - GFModuleRetrieveRTValueOrDefaultBool( - GFGetModuleID(), "version.current_commit_hash_publish_in_remote", 0); + gf::sdk::StateBool(GFModuleSdkContext(), GFGetModuleID(), + "version.current_commit_hash_publish_in_remote", 0); - QString const latest_version = UDUP(GFModuleRetrieveRTValueOrDefault( - GFGetModuleID(), "version.latest_version", "")); + QString const latest_version = gf::sdk::StateText( + GFModuleSdkContext(), GFGetModuleID(), "version.latest_version", ""); - QString const release_note = UDUP(GFModuleRetrieveRTValueOrDefault( - GFGetModuleID(), "version.release_note", "")); + QString const release_note = gf::sdk::StateText( + GFModuleSdkContext(), GFGetModuleID(), "version.release_note", ""); - QString const api = UDUP(GFModuleRetrieveRTValueOrDefault( - GFGetModuleID(), "version.api", "Unknown")); + QString const api = gf::sdk::StateText(GFModuleSdkContext(), GFGetModuleID(), + "version.api", "Unknown"); FLOG_INFO("latest version from remote: %1", latest_version); @@ -213,8 +211,9 @@ void UpdateTab::slot_check_version_update() { check_update_btn_->setEnabled(false); pb_->show(); - auto api = UDUP(GFModuleRetrieveRTValueOrDefault( - "ui", "settings.network.update_checking_api", "github")); + auto api = + gf::sdk::StateText(GFModuleSdkContext(), "ui", + "settings.network.update_checking_api", "github"); if (api == "bktus") { auto* task = new BKTUSVersionCheckTask(); @@ -238,11 +237,12 @@ void UpdateTab::slot_check_version_update() { void UpdateTab::showEvent(QShowEvent* event) { QWidget::showEvent(event); - auto is_loading_done = GFModuleRetrieveRTValueOrDefaultBool( - GFGetModuleID(), "version.loading_done", 0); + auto is_loading_done = gf::sdk::StateBool( + GFModuleSdkContext(), GFGetModuleID(), "version.loading_done", 0); - auto prohibit = GFModuleRetrieveRTValueOrDefaultBool( - "ui", "settings.network.prohibit_update_checking", 0); + auto prohibit = + gf::sdk::StateBool(GFModuleSdkContext(), "ui", + "settings.network.prohibit_update_checking", 0); if ((prohibit == 0) && is_loading_done == 0) { slot_check_version_update(); diff --git a/src/m_ver_check/Utils.cpp b/src/m_ver_check/Utils.cpp index b8a6643..2cc417e 100644 --- a/src/m_ver_check/Utils.cpp +++ b/src/m_ver_check/Utils.cpp @@ -28,8 +28,6 @@ #include "Utils.h" -#include <GFSDKBasic.h> -#include <GFSDKExtra.h> #include <GFSDKLog.h> #include <QRegularExpression> @@ -44,38 +42,54 @@ auto ExtractVersionFromRawTag(const QString& raw_tag) -> QString { } void FillGrtWithVersionInfo(const SoftwareVersion& version) { - GFModuleUpsertRTValue(GFGetModuleID(), - GFModuleStrDup("version.current_version"), - GFModuleStrDup(version.current_version.toUtf8())); - GFModuleUpsertRTValue(GFGetModuleID(), - GFModuleStrDup("version.latest_version"), - GFModuleStrDup(version.latest_version.toUtf8())); - GFModuleUpsertRTValue(GFGetModuleID(), - GFModuleStrDup("version.local_commit_hash"), - GFModuleStrDup(version.local_commit_hash.toUtf8())); + gf::sdk::SetStateText(GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + "version.current_version"), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + version.current_version.toUtf8())); + gf::sdk::SetStateText(GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + "version.latest_version"), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + version.latest_version.toUtf8())); + gf::sdk::SetStateText(GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + "version.local_commit_hash"), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + version.local_commit_hash.toUtf8())); - GFModuleUpsertRTValueBool( - GFGetModuleID(), - GFModuleStrDup("version.current_version_publish_in_remote"), + gf::sdk::SetStateBool( + GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + "version.current_version_publish_in_remote"), version.current_version_publish_in_remote ? 1 : 0); - GFModuleUpsertRTValueBool( - GFGetModuleID(), - GFModuleStrDup("version.current_commit_hash_publish_in_remote"), + gf::sdk::SetStateBool( + GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + "version.current_commit_hash_publish_in_remote"), version.current_commit_hash_publish_in_remote ? 1 : 0); - GFModuleUpsertRTValueBool(GFGetModuleID(), - GFModuleStrDup("version.need_upgrade"), - version.NeedUpgrade() ? 1 : 0); - GFModuleUpsertRTValueBool(GFGetModuleID(), - GFModuleStrDup("version.current_version_released"), - version.CurrentVersionReleased() ? 1 : 0); + gf::sdk::SetStateBool(GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + "version.need_upgrade"), + version.NeedUpgrade() ? 1 : 0); + gf::sdk::SetStateBool(GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + "version.current_version_released"), + version.CurrentVersionReleased() ? 1 : 0); - GFModuleUpsertRTValue(GFGetModuleID(), GFModuleStrDup("version.release_note"), - GFModuleStrDup(version.release_note.toUtf8())); + gf::sdk::SetStateText(GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + "version.release_note"), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + version.release_note.toUtf8())); - GFModuleUpsertRTValue(GFGetModuleID(), GFModuleStrDup("version.api"), - GFModuleStrDup(version.api.toUtf8())); + gf::sdk::SetStateText( + GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, "version.api"), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, version.api.toUtf8())); - GFModuleUpsertRTValueBool(GFGetModuleID(), - GFModuleStrDup("version.loading_done"), - version.IsInfoValid() ? 1 : 0); + gf::sdk::SetStateBool(GFModuleSdkContext(), GFGetModuleID(), + GFMemStrDup(GFModuleSdkContext(), GF_ARENA_NORMAL, + "version.loading_done"), + version.IsInfoValid() ? 1 : 0); }
\ No newline at end of file diff --git a/src/m_ver_check/VersionCheckingModule.cpp b/src/m_ver_check/VersionCheckingModule.cpp index 7642746..078df10 100644 --- a/src/m_ver_check/VersionCheckingModule.cpp +++ b/src/m_ver_check/VersionCheckingModule.cpp @@ -28,9 +28,7 @@ #include "VersionCheckingModule.h" -#include <GFSDKBasic.h> #include <GFSDKBuildInfo.h> -#include <GFSDKExtra.h> #include <GFSDKLog.h> #include <GFSDKUI.h> @@ -59,8 +57,9 @@ auto CheckUpdate(const GFEvent& event) -> GFEventResult { QObject::connect( task, &BKTUSVersionCheckTask::SignalUpgradeVersion, QThread::currentThread(), [event](const SoftwareVersion& sv) { - GFDurableCacheSave("update_checking_cache", - (QJsonDocument(sv.ToJson()).toJson()).constData()); + gf::sdk::SetCacheText( + GFModuleSdkContext(), GF_STORE_DURABLE, "update_checking_cache", + (QJsonDocument(sv.ToJson()).toJson()).constData()); return GFEventResult::Ok(); }); QObject::connect(task, &BKTUSVersionCheckTask::SignalUpgradeVersion, task, @@ -72,8 +71,9 @@ auto CheckUpdate(const GFEvent& event) -> GFEventResult { QObject::connect( task, &GitHubVersionCheckTask::SignalUpgradeVersion, QCoreApplication::instance(), [event](const SoftwareVersion& sv) { - GFDurableCacheSave("update_checking_cache", - (QJsonDocument(sv.ToJson()).toJson()).constData()); + gf::sdk::SetCacheText( + GFModuleSdkContext(), GF_STORE_DURABLE, "update_checking_cache", + (QJsonDocument(sv.ToJson()).toJson()).constData()); return GFEventResult::Ok(); }); QObject::connect(task, &GitHubVersionCheckTask::SignalUpgradeVersion, task, @@ -173,8 +173,8 @@ auto OnApplicationLoaded(const GFEvent& event) -> GFEventResult { } // check version information - auto settings = - qobject_cast<QSettings*>(static_cast<QObject*>(GFUIGlobalSettings())); + auto settings = qobject_cast<QSettings*>( + static_cast<QObject*>(GFStorageSettingsRoot(GFModuleSdkContext()))); if (!settings) { LOG_ERROR("application loaded: global settings handle invalid"); return GFEventResult::Bad("global settings handle invalid"); @@ -204,7 +204,8 @@ auto OnApplicationLoaded(const GFEvent& event) -> GFEventResult { return GFEventResult::Ok(); } - auto cache = UDUP(GFDurableCacheGet("update_checking_cache")); + auto cache = gf::sdk::CacheText(GFModuleSdkContext(), GF_STORE_DURABLE, + "update_checking_cache"); auto json = QJsonDocument::fromJson(cache.toUtf8()); if (json.isEmpty() || !json.isObject()) { @@ -307,8 +308,8 @@ auto OnNetworkSettingsTabUiCreated(const GFEvent& event) -> GFEventResult { auto OnNetworkSettingsTabApplySettings(const GFEvent& event) -> GFEventResult { LOG_DEBUG("network settings tab apply settings event: processing"); - auto* settings = - qobject_cast<QSettings*>(static_cast<QObject*>(GFUIGlobalSettings())); + auto* settings = qobject_cast<QSettings*>( + static_cast<QObject*>(GFStorageSettingsRoot(GFModuleSdkContext()))); if (!settings) { LOG_ERROR( "network settings tab apply settings: global settings handle " @@ -379,8 +380,8 @@ auto OnNetworkSettingsTabApplySettings(const GFEvent& event) -> GFEventResult { auto OnNetworkSettingsTabLoadSettings(const GFEvent& event) -> GFEventResult { LOG_DEBUG("network settings tab load settings event: processing"); - auto* settings = - qobject_cast<QSettings*>(static_cast<QObject*>(GFUIGlobalSettings())); + auto* settings = qobject_cast<QSettings*>( + static_cast<QObject*>(GFStorageSettingsRoot(GFModuleSdkContext()))); if (!settings) { LOG_ERROR( diff --git a/src/m_ver_check/module.json b/src/m_ver_check/module.json index d092b7d..6148d8f 100644 --- a/src/m_ver_check/module.json +++ b/src/m_ver_check/module.json @@ -6,8 +6,9 @@ "description": "Try checking GpgFrontend version.", "author": "Saturneric", "capabilities": [ - "ui", - "network" + "network", + "storage", + "ui" ], "events": [ "APPLICATION_LOADED", |
