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_data_path_).exists()) QDir(app_data_path_).mkpath(".");
|
||||||
if (!QDir(app_log_path_).exists()) QDir(app_log_path_).mkpath(".");
|
if (!QDir(app_log_path_).exists()) QDir(app_log_path_).mkpath(".");
|
||||||
|
if (!QDir(GetModulesDir()).exists()) QDir(GetModulesDir()).mkpath(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto GetSettings() -> QSettings {
|
[[nodiscard]] auto GetSettings() -> QSettings {
|
||||||
@ -124,6 +125,15 @@ class GlobalSettingStation::Impl {
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] auto GetLogDir() const -> QString { return app_log_path_; }
|
[[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:
|
private:
|
||||||
QString working_path_ = QDir::currentPath();
|
QString working_path_ = QDir::currentPath();
|
||||||
|
|
||||||
@ -174,6 +184,10 @@ auto GlobalSettingStation::GetAppDataPath() const -> QString {
|
|||||||
return p_->GetLogDir();
|
return p_->GetLogDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto GlobalSettingStation::GetModulesDir() const -> QString {
|
||||||
|
return p_->GetModulesDir();
|
||||||
|
}
|
||||||
|
|
||||||
auto GlobalSettingStation::GetLogFilesSize() const -> QString {
|
auto GlobalSettingStation::GetLogFilesSize() const -> QString {
|
||||||
return p_->GetLogFilesSize();
|
return p_->GetLogFilesSize();
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,13 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] auto GetLogDir() const -> QString;
|
[[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
|
* @brief Get the Log Files Size object
|
||||||
*
|
*
|
||||||
|
@ -31,41 +31,69 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
#include "core/function/GlobalSettingStation.h"
|
||||||
#include "core/module/ModuleManager.h"
|
#include "core/module/ModuleManager.h"
|
||||||
#include "core/thread/Task.h"
|
#include "core/thread/Task.h"
|
||||||
#include "core/thread/TaskRunnerGetter.h"
|
#include "core/thread/TaskRunnerGetter.h"
|
||||||
|
|
||||||
namespace GpgFrontend::Module {
|
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) {
|
void LoadGpgFrontendModules(ModuleInitArgs) {
|
||||||
// must init at default thread before core
|
// must init at default thread before core
|
||||||
Thread::TaskRunnerGetter::GetInstance().GetTaskRunner()->PostTask(
|
Thread::TaskRunnerGetter::GetInstance().GetTaskRunner()->PostTask(
|
||||||
new Thread::Task(
|
new Thread::Task(
|
||||||
[](const DataObjectPtr&) -> int {
|
[](const DataObjectPtr&) -> int {
|
||||||
auto exec_binary_path = QCoreApplication::applicationDirPath();
|
return LoadIntegratedMods() && LoadExternalMods() ? 0 : -1;
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"modules_system_init_task"));
|
"modules_system_init_task"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user