aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/module/ModuleInit.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-04-28 17:02:17 +0000
committersaturneric <[email protected]>2024-04-28 17:02:17 +0000
commit2af2fff270c32837f8cce133268d96fa285a7b3e (patch)
treefbd43d12645fc2497841933a9b126d3abe86d742 /src/core/module/ModuleInit.cpp
parentMerge branch 'dev/2.1.2/main' into develop (diff)
downloadGpgFrontend-2af2fff270c32837f8cce133268d96fa285a7b3e.tar.gz
GpgFrontend-2af2fff270c32837f8cce133268d96fa285a7b3e.zip
feat: load both integrated and external modules
Diffstat (limited to 'src/core/module/ModuleInit.cpp')
-rw-r--r--src/core/module/ModuleInit.cpp76
1 files changed, 52 insertions, 24 deletions
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"));
}