feat: load both integrated and external modules
This commit is contained in:
parent
0dbbc0e038
commit
2af2fff270
@ -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();
|
||||
}
|
||||
|
@ -82,6 +82,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
|
||||
*
|
||||
|
@ -31,30 +31,14 @@
|
||||
#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 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;
|
||||
}
|
||||
|
||||
void LoadModuleFromPath(const QString& mods_path) {
|
||||
for (const auto& module_library_name :
|
||||
QDir(mods_path).entryList(QStringList() << "*.so"
|
||||
<< "*.dll"
|
||||
@ -63,9 +47,53 @@ void LoadGpgFrontendModules(ModuleInitArgs) {
|
||||
ModuleManager::GetInstance().LoadModule(mods_path + "/" +
|
||||
module_library_name);
|
||||
}
|
||||
}
|
||||
|
||||
GF_CORE_LOG_DEBUG("load modules done.");
|
||||
return 0;
|
||||
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 {
|
||||
return LoadIntegratedMods() && LoadExternalMods() ? 0 : -1;
|
||||
},
|
||||
"modules_system_init_task"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user