diff options
author | saturneric <[email protected]> | 2025-04-17 19:59:01 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-04-17 19:59:01 +0000 |
commit | 92be7f8da6076311b996a184c76781c07608cc9f (patch) | |
tree | 1088b3f5ad7c086e7f462287c14624e2202adbf0 | |
parent | feat: check scd version (diff) | |
download | GpgFrontend-92be7f8da6076311b996a184c76781c07608cc9f.tar.gz GpgFrontend-92be7f8da6076311b996a184c76781c07608cc9f.zip |
fix: issues found on linux platform
-rw-r--r-- | .github/workflows/release.yml | 2 | ||||
-rw-r--r-- | src/core/GpgCoreInit.cpp | 18 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.cpp | 11 | ||||
-rw-r--r-- | src/core/utils/GpgUtils.cpp | 18 | ||||
-rw-r--r-- | src/ui/dialog/controller/SmartCardControllerDialog.cpp | 5 | ||||
-rw-r--r-- | src/ui/dialog/settings/SettingsKeyServer.cpp | 6 | ||||
-rw-r--r-- | src/ui/thread/KeyServerImportTask.cpp | 2 |
7 files changed, 50 insertions, 12 deletions
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4fd609cc..8ee5ac1a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -271,7 +271,7 @@ jobs: - name: Build GpgFrontend (Linux) # Build your GpgFrontend with the given configuration run: | - cmake -B ${{github.workspace}}/build -G Ninja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDGPGFRONTEND_BUILD_TYPE_ONLY_APPLICATION=ON + cmake -B ${{github.workspace}}/build -G Ninja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DGPGFRONTEND_BUILD_TYPE_ONLY_APPLICATION=ON cmake --build ${{github.workspace}}/build --config {{$env.BUILD_TYPE}} -- -v if: runner.os == 'Linux' diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index a5f86207..18fa2965 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -75,6 +75,7 @@ auto GetDefaultKeyDatabasePath(const QString& gpgconf_path) -> QString { if (GlobalSettingStation::GetInstance().IsProtableMode()) { default_db_path = GlobalSettingStation::GetInstance().GetAppDataPath() + "/db"; + LOG_D() << "default key db in protable mode:" << default_db_path; } else { if (gpgconf_path.isEmpty()) return {}; @@ -516,15 +517,26 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int { } auto key_dbs = GetKeyDatabaseInfoBySettings(); + assert(!key_dbs.isEmpty()); + + if (key_dbs.isEmpty()) { + FLOG_E() << "Cannot find any valid key database!" + << "GpgFrontend cannot start under this situation!"; + Module::UpsertRTValue("core", "env.state.ctx", -1); + CoreSignalStation::GetInstance()->SignalBadGnupgEnv( + QCoreApplication::tr("No valid KEy Database")); + } // load default context auto& default_ctx = GpgFrontend::GpgContext::CreateInstance( kGpgFrontendDefaultChannel, [=]() -> ChannelObjectPtr { GpgFrontend::GpgContextInitArgs args; - const auto& default_key_db_info = key_dbs.front(); - args.db_name = default_key_db_info.name; - args.db_path = default_key_db_info.path; + if (!key_dbs.isEmpty()) { + const auto& default_key_db_info = key_dbs.front(); + args.db_name = default_key_db_info.name; + args.db_path = default_key_db_info.path; + } args.offline_mode = forbid_all_gnupg_connection; args.auto_import_missing_key = auto_import_missing_key; diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index 62b24331..3c0dda88 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -48,6 +48,15 @@ class GlobalSettingStation::Impl { Module::UpsertRTValue("core", "env.state.portable", 1); LOG_I() << "GpgFrontend runs in the portable mode now"; +#if defined(__linux__) + if (!qEnvironmentVariable("APPIMAGE").isEmpty()) { + LOG_I() << "app image path: " << qEnvironmentVariable("APPIMAGE"); + QFileInfo info( + QString::fromUtf8(qEnvironmentVariable("APPIMAGE").toUtf8())); + app_path_ = info.canonicalPath(); + } +#endif + app_data_path_ = QDir(app_path_ + "/../").canonicalPath(); app_config_path_ = app_data_path_ + "/config"; @@ -197,7 +206,7 @@ class GlobalSettingStation::Impl { } bool portable_mode_ = false; - const QString app_path_ = QCoreApplication::applicationDirPath(); + QString app_path_ = QCoreApplication::applicationDirPath(); QString working_path_ = QDir::currentPath(); QString app_data_path_ = QString{ QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)}; diff --git a/src/core/utils/GpgUtils.cpp b/src/core/utils/GpgUtils.cpp index ad93fe67..b8824673 100644 --- a/src/core/utils/GpgUtils.cpp +++ b/src/core/utils/GpgUtils.cpp @@ -289,7 +289,13 @@ auto GetCanonicalKeyDatabasePath(const QDir& app_path, << "to absolute path: " << target_path; } - auto info = QFileInfo(target_path); + QFileInfo info(target_path); + if (!info.exists()) { + LOG_W() << "key database not exists:" << info.canonicalFilePath() + << ", making a new directory..."; + QDir().mkdir(info.canonicalFilePath()); + } + if (VerifyKeyDatabasePath(info)) { auto key_database_fs_path = info.canonicalFilePath(); LOG_D() << "load gpg key database:" << key_database_fs_path; @@ -310,10 +316,18 @@ auto GetKeyDatabaseInfoBySettings() -> QContainer<KeyDatabaseInfo> { // try to use user defined key database for (const auto& key_database : key_dbs) { + if (key_database.path.isEmpty()) continue; + + LOG_D() << "got key database:" << key_database.path; + auto key_database_fs_path = GetCanonicalKeyDatabasePath(app_path, key_database.path); - if (key_database_fs_path.isEmpty()) continue; + if (key_database_fs_path.isEmpty()) { + LOG_E() << "cannot use target path" << key_database.path + << "as key database"; + continue; + } KeyDatabaseInfo key_db_info; key_db_info.name = key_database.name; diff --git a/src/ui/dialog/controller/SmartCardControllerDialog.cpp b/src/ui/dialog/controller/SmartCardControllerDialog.cpp index 254ed83c..530f2e7e 100644 --- a/src/ui/dialog/controller/SmartCardControllerDialog.cpp +++ b/src/ui/dialog/controller/SmartCardControllerDialog.cpp @@ -148,7 +148,10 @@ SmartCardControllerDialog::SmartCardControllerDialog(QWidget* parent) timer_ = new QTimer(this); connect(timer_, &QTimer::timeout, this, &SmartCardControllerDialog::slot_listen_smart_card_changes); - timer_->start(3000); + + if (scd_version_supported_) { + timer_->start(3000); + } setWindowTitle(tr("Smart Card Controller")); } diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp index c35900cc..8088b690 100644 --- a/src/ui/dialog/settings/SettingsKeyServer.cpp +++ b/src/ui/dialog/settings/SettingsKeyServer.cpp @@ -234,10 +234,10 @@ void KeyserverTab::slot_test_listed_key_server() { &GpgFrontend::UI::ListedKeyServerTestTask::SignalKeyServerListTestResult, this, [=](QContainer<ListedKeyServerTestTask::KeyServerTestResultType> result) { - const size_t row_size = ui_->keyServerListTable->rowCount(); - if (result.size() != row_size) return; + const auto row_size = ui_->keyServerListTable->rowCount(); + if (result.size() != static_cast<qsizetype>(row_size)) return; ui_->keyServerListTable->blockSignals(true); - for (size_t i = 0; i < row_size; i++) { + for (auto i = 0; i < row_size; i++) { const auto status = result[i]; auto* status_iem = ui_->keyServerListTable->item(i, 3); if (status == ListedKeyServerTestTask::kTEST_RESULT_TYPE_SUCCESS) { diff --git a/src/ui/thread/KeyServerImportTask.cpp b/src/ui/thread/KeyServerImportTask.cpp index d6450e83..f977fe62 100644 --- a/src/ui/thread/KeyServerImportTask.cpp +++ b/src/ui/thread/KeyServerImportTask.cpp @@ -96,7 +96,7 @@ void GpgFrontend::UI::KeyServerImportTask::dealing_reply_from_server() { emit SignalKeyServerImportResult(current_gpg_context_channel_, true, tr("Success"), buffer, info); - if (static_cast<size_t>(result_count_++) == keyids_.size() - 1) { + if (static_cast<qsizetype>(result_count_++) == keyids_.size() - 1) { emit SignalTaskShouldEnd(0); } }
\ No newline at end of file |