diff options
author | saturneric <[email protected]> | 2024-04-28 17:02:17 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-04-28 17:02:17 +0000 |
commit | 2af2fff270c32837f8cce133268d96fa285a7b3e (patch) | |
tree | fbd43d12645fc2497841933a9b126d3abe86d742 | |
parent | Merge branch 'dev/2.1.2/main' into develop (diff) | |
download | GpgFrontend-2af2fff270c32837f8cce133268d96fa285a7b3e.tar.gz GpgFrontend-2af2fff270c32837f8cce133268d96fa285a7b3e.zip |
feat: load both integrated and external modules
-rw-r--r-- | src/core/function/GlobalSettingStation.cpp | 14 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.h | 7 | ||||
-rw-r--r-- | src/core/module/ModuleInit.cpp | 76 |
3 files changed, 73 insertions, 24 deletions
diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index 7b21ebca..45ab11f9 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -69,6 +69,7 @@ class GlobalSettingStation::Impl { if (!QDir(app_data_path_).exists()) QDir(app_data_path_).mkpath("."); if (!QDir(app_log_path_).exists()) QDir(app_log_path_).mkpath("."); + if (!QDir(GetModulesDir()).exists()) QDir(GetModulesDir()).mkpath("."); } [[nodiscard]] auto GetSettings() -> QSettings { @@ -124,6 +125,15 @@ class GlobalSettingStation::Impl { */ [[nodiscard]] auto GetLogDir() const -> QString { return app_log_path_; } + /** + * @brief Get the Modules Dir object + * + * @return QString + */ + [[nodiscard]] auto GetModulesDir() const -> QString { + return GetAppDataPath() + "/mods"; + } + private: QString working_path_ = QDir::currentPath(); @@ -174,6 +184,10 @@ auto GlobalSettingStation::GetAppDataPath() const -> QString { return p_->GetLogDir(); } +[[nodiscard]] auto GlobalSettingStation::GetModulesDir() const -> QString { + return p_->GetModulesDir(); +} + auto GlobalSettingStation::GetLogFilesSize() const -> QString { return p_->GetLogFilesSize(); } diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h index 85ac57b4..c907bdb5 100644 --- a/src/core/function/GlobalSettingStation.h +++ b/src/core/function/GlobalSettingStation.h @@ -83,6 +83,13 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation [[nodiscard]] auto GetLogDir() const -> QString; /** + * @brief Get the Modules Dir object + * + * @return QString + */ + [[nodiscard]] auto GetModulesDir() const -> QString; + + /** * @brief Get the Log Files Size object * * @return QString diff --git a/src/core/module/ModuleInit.cpp b/src/core/module/ModuleInit.cpp index 8932c97c..0fddc16a 100644 --- a/src/core/module/ModuleInit.cpp +++ b/src/core/module/ModuleInit.cpp @@ -31,41 +31,69 @@ #include <QCoreApplication> #include <QDir> +#include "core/function/GlobalSettingStation.h" #include "core/module/ModuleManager.h" #include "core/thread/Task.h" #include "core/thread/TaskRunnerGetter.h" namespace GpgFrontend::Module { +void LoadModuleFromPath(const QString& mods_path) { + for (const auto& module_library_name : + QDir(mods_path).entryList(QStringList() << "*.so" + << "*.dll" + << "*.dylib", + QDir::Files)) { + ModuleManager::GetInstance().LoadModule(mods_path + "/" + + module_library_name); + } +} + +auto LoadIntegratedMods() -> bool { + auto exec_binary_path = QCoreApplication::applicationDirPath(); + auto mods_path = exec_binary_path + "/mods"; + if (!qEnvironmentVariable("APPIMAGE").isEmpty()) { + mods_path = qEnvironmentVariable("APPDIR") + "/usr/lib/mods"; + } + + GF_CORE_LOG_DEBUG("try loading integrated modules at path: {} ...", + mods_path); + if (!QDir(mods_path).exists()) { + GF_CORE_LOG_WARN( + "integrated module directory at path {} not found, abort...", + mods_path); + return false; + } + + LoadModuleFromPath(mods_path); + + GF_CORE_LOG_DEBUG("load integrated modules done."); + return true; +} + +auto LoadExternalMods() -> bool { + auto mods_path = + GpgFrontend::GlobalSettingStation::GetInstance().GetModulesDir(); + + GF_CORE_LOG_DEBUG("try loading external modules at path: {} ...", mods_path); + if (!QDir(mods_path).exists()) { + GF_CORE_LOG_WARN("external module directory at path {} not found, abort...", + mods_path); + return false; + } + + LoadModuleFromPath(mods_path); + + GF_CORE_LOG_DEBUG("load integrated modules done."); + return true; +} + void LoadGpgFrontendModules(ModuleInitArgs) { // must init at default thread before core Thread::TaskRunnerGetter::GetInstance().GetTaskRunner()->PostTask( new Thread::Task( [](const DataObjectPtr&) -> int { - auto exec_binary_path = QCoreApplication::applicationDirPath(); - auto mods_path = exec_binary_path + "/mods"; - if (!qEnvironmentVariable("APPIMAGE").isEmpty()) { - mods_path = qEnvironmentVariable("APPDIR") + "/usr/lib/mods"; - } - - GF_CORE_LOG_DEBUG("try loading modules at path: {} ...", mods_path); - if (!QDir(mods_path).exists()) { - GF_CORE_LOG_WARN( - "module directory at path {} not found, abort...", mods_path); - return -1; - } - - for (const auto& module_library_name : - QDir(mods_path).entryList(QStringList() << "*.so" - << "*.dll" - << "*.dylib", - QDir::Files)) { - ModuleManager::GetInstance().LoadModule(mods_path + "/" + - module_library_name); - } - - GF_CORE_LOG_DEBUG("load modules done."); - return 0; + return LoadIntegratedMods() && LoadExternalMods() ? 0 : -1; }, "modules_system_init_task")); } |