From c1a5fff98cab4adf04210ba8120459b8e87a8fa3 Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 15 Oct 2023 16:17:28 +0800 Subject: fix: solve some issues on linux .desktop file --- src/ui/thread/VersionCheckTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/thread/VersionCheckTask.cpp') diff --git a/src/ui/thread/VersionCheckTask.cpp b/src/ui/thread/VersionCheckTask.cpp index e9490e1c..f9929837 100644 --- a/src/ui/thread/VersionCheckTask.cpp +++ b/src/ui/thread/VersionCheckTask.cpp @@ -46,7 +46,7 @@ VersionCheckTask::VersionCheckTask() } void VersionCheckTask::Run() { - SetFinishAfterRun(false); + HoldOnLifeCycle(true); try { using namespace nlohmann; -- cgit v1.2.3 From 7c21fdd97132e63572a6aca6fa0492d2ce74e777 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 16 Oct 2023 03:47:52 +0800 Subject: feat: start to add plugin system and do some improve on project configuration --- src/ui/thread/VersionCheckTask.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ui/thread/VersionCheckTask.cpp') diff --git a/src/ui/thread/VersionCheckTask.cpp b/src/ui/thread/VersionCheckTask.cpp index f9929837..d5ab1f7d 100644 --- a/src/ui/thread/VersionCheckTask.cpp +++ b/src/ui/thread/VersionCheckTask.cpp @@ -29,6 +29,7 @@ #include "VersionCheckTask.h" #include +#include #include #include "GpgFrontendBuildInfo.h" -- cgit v1.2.3 From 95997d27106daf91336847f50efaaa32279b7fc7 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 16 Oct 2023 17:54:05 +0800 Subject: fix: check and update copyright at files --- src/ui/thread/VersionCheckTask.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui/thread/VersionCheckTask.cpp') diff --git a/src/ui/thread/VersionCheckTask.cpp b/src/ui/thread/VersionCheckTask.cpp index d5ab1f7d..84f21317 100644 --- a/src/ui/thread/VersionCheckTask.cpp +++ b/src/ui/thread/VersionCheckTask.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Saturneric + * Copyright (C) 2021 Saturneric * * This file is part of GpgFrontend. * @@ -20,7 +20,7 @@ * the gpg4usb project, which is under GPL-3.0-or-later. * * All the source code of GpgFrontend was modified and released by - * Saturneric starting on May 12, 2021. + * Saturneric starting on May 12, 2021. * * SPDX-License-Identifier: GPL-3.0-or-later * -- cgit v1.2.3 From 70196cf01757824a578e4d9c49a210bf136de266 Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 18 Oct 2023 22:45:33 +0800 Subject: feat: using pool for concurrent executions, not stable yet --- src/ui/thread/VersionCheckTask.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ui/thread/VersionCheckTask.cpp') diff --git a/src/ui/thread/VersionCheckTask.cpp b/src/ui/thread/VersionCheckTask.cpp index 84f21317..c03ccb16 100644 --- a/src/ui/thread/VersionCheckTask.cpp +++ b/src/ui/thread/VersionCheckTask.cpp @@ -66,7 +66,7 @@ void VersionCheckTask::Run() { } catch (...) { SPDLOG_ERROR("unknown error occurred"); - emit SignalTaskRunnableEnd(-1); + emit SignalTaskShouldEnd(-1); } } @@ -130,7 +130,7 @@ void VersionCheckTask::slot_parse_latest_version_info() { &VersionCheckTask::slot_parse_current_version_info); } catch (...) { SPDLOG_ERROR("current version request create error"); - emit SignalTaskRunnableEnd(-1); + emit SignalTaskShouldEnd(-1); } } @@ -173,7 +173,7 @@ void VersionCheckTask::slot_parse_current_version_info() { } emit SignalUpgradeVersion(version_); - emit SignalTaskRunnableEnd(0); + emit SignalTaskShouldEnd(0); } } // namespace GpgFrontend::UI -- cgit v1.2.3 From 8fdeb3af49999f29e017b7f7a70bd36f020ba721 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 23 Oct 2023 18:27:25 +0800 Subject: perf: reduce header includes and improve build speed --- src/ui/thread/VersionCheckTask.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/ui/thread/VersionCheckTask.cpp') diff --git a/src/ui/thread/VersionCheckTask.cpp b/src/ui/thread/VersionCheckTask.cpp index c03ccb16..72857ae3 100644 --- a/src/ui/thread/VersionCheckTask.cpp +++ b/src/ui/thread/VersionCheckTask.cpp @@ -28,9 +28,7 @@ #include "VersionCheckTask.h" -#include -#include -#include +#include #include "GpgFrontendBuildInfo.h" -- cgit v1.2.3 From fa2e87a48acbc32650ca9db073b991729dfba622 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Tue, 24 Oct 2023 21:22:13 +0800 Subject: feat: use module instead of integrated code at version checking task --- src/ui/thread/VersionCheckTask.cpp | 177 ------------------------------------- 1 file changed, 177 deletions(-) delete mode 100644 src/ui/thread/VersionCheckTask.cpp (limited to 'src/ui/thread/VersionCheckTask.cpp') diff --git a/src/ui/thread/VersionCheckTask.cpp b/src/ui/thread/VersionCheckTask.cpp deleted file mode 100644 index 72857ae3..00000000 --- a/src/ui/thread/VersionCheckTask.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * This file is part of GpgFrontend. - * - * GpgFrontend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GpgFrontend is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GpgFrontend. If not, see . - * - * The initial version of the source code is inherited from - * the gpg4usb project, which is under GPL-3.0-or-later. - * - * All the source code of GpgFrontend was modified and released by - * Saturneric starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "VersionCheckTask.h" - -#include - -#include "GpgFrontendBuildInfo.h" - -namespace GpgFrontend::UI { - -VersionCheckTask::VersionCheckTask() - : Task("version_check_task"), - network_manager_(new QNetworkAccessManager(this)), - current_version_(std::string("v") + std::to_string(VERSION_MAJOR) + "." + - std::to_string(VERSION_MINOR) + "." + - std::to_string(VERSION_PATCH)) { - qRegisterMetaType("SoftwareVersion"); - version_.current_version = current_version_; -} - -void VersionCheckTask::Run() { - HoldOnLifeCycle(true); - - try { - using namespace nlohmann; - SPDLOG_DEBUG("current version: {}", current_version_); - std::string latest_version_url = - "https://api.github.com/repos/saturneric/gpgfrontend/releases/latest"; - - QNetworkRequest latest_request; - latest_request.setUrl(QUrl(latest_version_url.c_str())); - latest_reply_ = network_manager_->get(latest_request); - connect(latest_reply_, &QNetworkReply::finished, this, - &VersionCheckTask::slot_parse_latest_version_info); - - // loading done - version_.load_info_done = true; - - } catch (...) { - SPDLOG_ERROR("unknown error occurred"); - emit SignalTaskShouldEnd(-1); - } -} - -void VersionCheckTask::slot_parse_latest_version_info() { - version_.current_version = current_version_; - - try { - if (latest_reply_ == nullptr || - latest_reply_->error() != QNetworkReply::NoError) { - SPDLOG_ERROR("latest version request error"); - version_.latest_version = current_version_; - } else { - latest_reply_bytes_ = latest_reply_->readAll(); - - auto latest_reply_json = - nlohmann::json::parse(latest_reply_bytes_.toStdString()); - - std::string latest_version = latest_reply_json["tag_name"]; - - SPDLOG_INFO("latest version from Github: {}", latest_version); - - QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))"); - auto version_match = re.match(latest_version.c_str()); - if (version_match.hasMatch()) { - latest_version = version_match.captured(0).toStdString(); - SPDLOG_DEBUG("latest version matched: {}", latest_version); - } else { - latest_version = current_version_; - SPDLOG_WARN("latest version unknown"); - } - - bool prerelease = latest_reply_json["prerelease"], - draft = latest_reply_json["draft"]; - 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_.publish_date = publish_date; - version_.release_note = release_note; - } - } catch (...) { - SPDLOG_ERROR("unknown error occurred"); - version_.load_info_done = false; - } - - if (latest_reply_ != nullptr) { - latest_reply_->deleteLater(); - } - - try { - std::string current_version_url = - "https://api.github.com/repos/saturneric/gpgfrontend/releases/tags/" + - current_version_; - - QNetworkRequest current_request; - current_request.setUrl(QUrl(current_version_url.c_str())); - current_reply_ = network_manager_->get(current_request); - - connect(current_reply_, &QNetworkReply::finished, this, - &VersionCheckTask::slot_parse_current_version_info); - } catch (...) { - SPDLOG_ERROR("current version request create error"); - emit SignalTaskShouldEnd(-1); - } -} - -void VersionCheckTask::slot_parse_current_version_info() { - try { - if (current_reply_ == nullptr || - current_reply_->error() != QNetworkReply::NoError) { - if (current_reply_ != nullptr) { - SPDLOG_ERROR("current version request network error: {}", - current_reply_->errorString().toStdString()); - } else { - SPDLOG_ERROR( - "current version request network error, null reply object"); - } - - version_.current_version_found = false; - version_.load_info_done = false; - } else { - version_.current_version_found = true; - current_reply_bytes_ = current_reply_->readAll(); - SPDLOG_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; - } - } catch (...) { - SPDLOG_ERROR("unknown error occurred"); - version_.load_info_done = false; - } - - SPDLOG_DEBUG("current version parse done: {}", - version_.current_version_found); - - if (current_reply_ != nullptr) { - current_reply_->deleteLater(); - } - - emit SignalUpgradeVersion(version_); - emit SignalTaskShouldEnd(0); -} - -} // namespace GpgFrontend::UI -- cgit v1.2.3