diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 61129141..47095634 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -345,13 +345,13 @@ if (BUILD_APPLICATION) ) add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/AppDir/usr/lib" + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/AppDir/usr/plugins" COMMENT "Complement to build the required architecture" ) add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/AppDir/usr/lib/mods" - COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mods" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/AppDir/usr/lib/mods" + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/AppDir/usr/plugins/mods" + COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mods" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/AppDir/usr/plugins/mods" COMMENT "Copying Mods into App Image" ) diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp index 1744ba72..b5a04d64 100644 --- a/src/core/module/GlobalModuleContext.cpp +++ b/src/core/module/GlobalModuleContext.cpp @@ -98,7 +98,7 @@ class GlobalModuleContext::Impl { return default_task_runner_; } - auto RegisterModule(const ModulePtr& module) -> bool { + auto RegisterModule(const ModulePtr& module, bool integrated_module) -> bool { GF_CORE_LOG_DEBUG("attempting to register module: {}", module->GetModuleIdentifier()); // Check if the module is null or already registered. @@ -120,6 +120,7 @@ class GlobalModuleContext::Impl { GpgFrontend::SecureCreateSharedObject(); register_info->module = module; register_info->channel = acquire_new_unique_channel(); + register_info->integrated = integrated_module; // move module to its task runner' thread register_info->module->setParent(nullptr); @@ -322,6 +323,11 @@ class GlobalModuleContext::Impl { return m.has_value() && m->get()->activate; } + auto IsIntegratedModule(ModuleIdentifier m_id) -> bool { + auto m = search_module_register_table(m_id); + return m.has_value() && m->get()->integrated; + } + auto ListAllRegisteredModuleID() -> QList { QList module_ids; for (const auto& module : module_register_table_) { @@ -343,6 +349,7 @@ class GlobalModuleContext::Impl { int channel; ModulePtr module; bool activate; + bool integrated; QList listening_event_ids; }; @@ -411,8 +418,9 @@ auto GlobalModuleContext::GetGlobalTaskRunner() return p_->GetGlobalTaskRunner(); } -auto GlobalModuleContext::RegisterModule(ModulePtr module) -> bool { - return p_->RegisterModule(module); +auto GlobalModuleContext::RegisterModule(ModulePtr module, + bool integrated_module) -> bool { + return p_->RegisterModule(module, integrated_module); } auto GlobalModuleContext::ActiveModule(ModuleIdentifier module_id) -> bool { @@ -449,6 +457,10 @@ auto GlobalModuleContext::IsModuleActivated(ModuleIdentifier m_id) -> bool { return p_->IsModuleActivated(m_id); } +auto GlobalModuleContext::IsIntegratedModule(ModuleIdentifier m_id) -> bool { + return p_->IsIntegratedModule(m_id); +} + auto GlobalModuleContext::ListAllRegisteredModuleID() -> QList { return p_->ListAllRegisteredModuleID(); diff --git a/src/core/module/GlobalModuleContext.h b/src/core/module/GlobalModuleContext.h index ae4300af..3177f984 100644 --- a/src/core/module/GlobalModuleContext.h +++ b/src/core/module/GlobalModuleContext.h @@ -70,7 +70,7 @@ class GPGFRONTEND_CORE_EXPORT GlobalModuleContext : public QObject { auto GetGlobalTaskRunner() -> std::optional; - auto RegisterModule(ModulePtr) -> bool; + auto RegisterModule(ModulePtr, bool) -> bool; auto ActiveModule(ModuleIdentifier) -> bool; @@ -86,6 +86,8 @@ class GPGFRONTEND_CORE_EXPORT GlobalModuleContext : public QObject { auto IsModuleActivated(ModuleIdentifier) -> bool; + auto IsIntegratedModule(ModuleIdentifier) -> bool; + auto ListAllRegisteredModuleID() -> QList; private: diff --git a/src/core/module/ModuleInit.cpp b/src/core/module/ModuleInit.cpp index 0fddc16a..8a7516a1 100644 --- a/src/core/module/ModuleInit.cpp +++ b/src/core/module/ModuleInit.cpp @@ -38,22 +38,34 @@ namespace GpgFrontend::Module { -void LoadModuleFromPath(const QString& mods_path) { +void LoadModuleFromPath(const QString& mods_path, bool integrated) { for (const auto& module_library_name : QDir(mods_path).entryList(QStringList() << "*.so" << "*.dll" << "*.dylib", QDir::Files)) { - ModuleManager::GetInstance().LoadModule(mods_path + "/" + - module_library_name); + ModuleManager::GetInstance().LoadModule( + mods_path + "/" + module_library_name, integrated); } } auto LoadIntegratedMods() -> bool { auto exec_binary_path = QCoreApplication::applicationDirPath(); + +#if defined(MACOS) && defined(RELEASE) + auto mods_path = exec_binary_path + "../PlugIns/mods"; +#else auto mods_path = exec_binary_path + "/mods"; +#endif + + // AppImage if (!qEnvironmentVariable("APPIMAGE").isEmpty()) { - mods_path = qEnvironmentVariable("APPDIR") + "/usr/lib/mods"; + mods_path = qEnvironmentVariable("APPDIR") + "/usr/plugins/mods"; + } + + // Flatpak + if (!qEnvironmentVariable("container").isEmpty()) { + mods_path = "/app/lib/mods"; } GF_CORE_LOG_DEBUG("try loading integrated modules at path: {} ...", @@ -65,7 +77,7 @@ auto LoadIntegratedMods() -> bool { return false; } - LoadModuleFromPath(mods_path); + LoadModuleFromPath(mods_path, true); GF_CORE_LOG_DEBUG("load integrated modules done."); return true; @@ -82,7 +94,7 @@ auto LoadExternalMods() -> bool { return false; } - LoadModuleFromPath(mods_path); + LoadModuleFromPath(mods_path, false); GF_CORE_LOG_DEBUG("load integrated modules done."); return true; diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index e00c8c8c..7094b801 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -53,7 +53,8 @@ class ModuleManager::Impl { ~Impl() = default; - auto LoadAndRegisterModule(const QString& module_library_path) -> void { + auto LoadAndRegisterModule(const QString& module_library_path, + bool integrated_module) -> void { Thread::TaskRunnerGetter::GetInstance() .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Default) ->PostTask(new Thread::Task( @@ -77,21 +78,39 @@ class ModuleManager::Impl { } module->SetGPC(gmc_.get()); - if (!gmc_->RegisterModule(module)) return -1; + if (!gmc_->RegisterModule(module, integrated_module)) return -1; - SettingsObject so( - QString("module.%1.so").arg(module->GetModuleIdentifier())); + const auto module_id = module->GetModuleIdentifier(); + const auto module_hash = module->GetModuleHash(); + + SettingsObject so(QString("module.%1.so").arg(module_id)); ModuleSO module_so(so); // if user has set auto active enable - if (module_so.module_id == module->GetModuleIdentifier() && - module_so.module_hash == module->GetModuleHash() && - module_so.auto_activate) { - if (gmc_->ActiveModule(module->GetModuleIdentifier())) { + if ((module_so.module_id == module_id && + module_so.module_hash == module_hash && + module_so.auto_activate) || + // integrated modules activate by default + ((module_so.module_id.isEmpty() || + module_so.module_hash.isEmpty()) && + integrated_module)) { + if (!gmc_->ActiveModule(module_id)) { return -1; } } + // reset module settings after change + if ((module_so.module_id.isEmpty() || + module_so.module_id != module_id) || + (module_so.module_hash.isEmpty() || + module_so.module_hash != module_hash)) { + module_so.module_id = module_id; + module_so.module_hash = module_hash; + module_so.auto_activate = integrated_module; + + so.Store(module_so.ToJson()); + } + return 0; }, __func__, nullptr)); @@ -111,7 +130,7 @@ class ModuleManager::Impl { ->PostTask(new Thread::Task( [=](GpgFrontend::DataObjectPtr) -> int { module->SetGPC(gmc_.get()); - return gmc_->RegisterModule(module) ? 0 : -1; + return gmc_->RegisterModule(module, false) ? 0 : -1; }, __func__, nullptr)); } @@ -196,6 +215,10 @@ class ModuleManager::Impl { return gmc_->IsModuleActivated(id); } + auto IsIntegratedModule(ModuleIdentifier id) -> bool { + return gmc_->IsIntegratedModule(id); + } + auto GRT() -> GlobalRegisterTable* { return grt_.get(); } private: @@ -231,8 +254,9 @@ ModuleManager::ModuleManager(int channel) ModuleManager::~ModuleManager() = default; -void ModuleManager::LoadModule(QString module_library_path) { - return p_->LoadAndRegisterModule(module_library_path); +void ModuleManager::LoadModule(QString module_library_path, + bool integrated_module) { + return p_->LoadAndRegisterModule(module_library_path, integrated_module); } auto ModuleManager::SearchModule(ModuleIdentifier module_id) -> ModulePtr { @@ -298,6 +322,10 @@ auto ModuleManager::IsModuleActivated(ModuleIdentifier id) -> bool { return p_->IsModuleActivated(id); } +auto ModuleManager::IsIntegratedModule(ModuleIdentifier id) -> bool { + return p_->IsIntegratedModule(id); +} + auto ModuleManager::ListAllRegisteredModuleID() -> QList { return p_->ListAllRegisteredModuleID(); }; diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index fa8d2264..5d7c1bdd 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -66,7 +66,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager virtual ~ModuleManager() override; - auto LoadModule(QString) -> void; + auto LoadModule(QString, bool) -> void; auto SearchModule(ModuleIdentifier) -> ModulePtr; @@ -76,6 +76,8 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager auto IsModuleActivated(ModuleIdentifier) -> bool; + auto IsIntegratedModule(ModuleIdentifier) -> bool; + void ListenEvent(ModuleIdentifier, EventIdentifier); void TriggerEvent(EventRefrernce); diff --git a/src/ui/dialog/controller/ModuleControllerDialog.cpp b/src/ui/dialog/controller/ModuleControllerDialog.cpp index f7b335dd..e99e84a3 100644 --- a/src/ui/dialog/controller/ModuleControllerDialog.cpp +++ b/src/ui/dialog/controller/ModuleControllerDialog.cpp @@ -28,6 +28,7 @@ #include "ModuleControllerDialog.h" +#include "core/function/GlobalSettingStation.h" #include "core/model/SettingsObject.h" #include "core/struct/settings_object/ModuleSO.h" #include "ui_ModuleControllerDialog.h" @@ -43,6 +44,7 @@ ModuleControllerDialog::ModuleControllerDialog(QWidget* parent) ui_(std::make_shared()), module_manager_(&Module::ModuleManager::GetInstance()) { ui_->setupUi(this); + ui_->actionsGroupBox->hide(); connect(ui_->moduleListView, &ModuleListView::SignalSelectModule, this, &ModuleControllerDialog::slot_load_module_details); @@ -77,6 +79,11 @@ ModuleControllerDialog::ModuleControllerDialog(QWidget* parent) QInputDialog::getText(this, "Please provide an Event ID", "Event ID"); Module::TriggerEvent(event_id); }); + + connect(ui_->showModsDirButton, &QPushButton::clicked, this, [=]() { + QDesktopServices::openUrl(QUrl::fromLocalFile( + GlobalSettingStation::GetInstance().GetModulesDir())); + }); } void ModuleControllerDialog::slot_load_module_details( @@ -86,6 +93,13 @@ void ModuleControllerDialog::slot_load_module_details( SettingsObject so(QString("module.%1.so").arg(module_id)); ModuleSO module_so(so); + if (module_id.isEmpty() || module == nullptr) { + ui_->actionsGroupBox->hide(); + return; + } + + ui_->actionsGroupBox->show(); + if (module_so.module_id != module_id || module_so.module_hash != module->GetModuleHash()) { module_so.module_id = module_id; diff --git a/src/ui/widgets/ModuleListView.cpp b/src/ui/widgets/ModuleListView.cpp index 6a386813..ced602fb 100644 --- a/src/ui/widgets/ModuleListView.cpp +++ b/src/ui/widgets/ModuleListView.cpp @@ -56,8 +56,12 @@ void ModuleListView::load_module_informations() { model_->clear(); for (const auto &module_id : module_ids) { auto module = module_manager.SearchModule(module_id); + auto integrated_module = module_manager.IsIntegratedModule(module_id); auto meta_data = module->GetModuleMetaData(); - auto *item = new QStandardItem(meta_data.value("Name", module_id)); + + auto *item = new QStandardItem((integrated_module ? "*" : "") + + meta_data.value("Name", module_id)); + item->setData(module_id, Qt::UserRole + 1); model_->appendRow(item); } diff --git a/ui/ModuleControllerDialog.ui b/ui/ModuleControllerDialog.ui index 92f70c15..a12ec6e2 100644 --- a/ui/ModuleControllerDialog.ui +++ b/ui/ModuleControllerDialog.ui @@ -62,6 +62,13 @@ + + + + Show Mods Directory + + + @@ -91,17 +98,36 @@ - - - Activate + + + Qt::Horizontal - - - Auto Activate + + + Actions + + + + + true + + + Activate + + + + + + + Auto Activate + + + +