LCOV - code coverage report
Current view: top level - muse/framework/extensions - extensionsmodule.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 55 0
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2024 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #include "extensionsmodule.h"
      23              : 
      24              : #include "modularity/ioc.h"
      25              : 
      26              : #include "interactive/iinteractiveuriregister.h"
      27              : 
      28              : #include "internal/extensionsprovider.h"
      29              : #include "internal/extensionsconfiguration.h"
      30              : #include "internal/extensionsactioncontroller.h"
      31              : #include "internal/extensioninstaller.h"
      32              : #include "internal/extensionsuiengine.h"
      33              : #include "internal/extensionscommandsregister.h"
      34              : #include "internal/extensionscommandsstate.h"
      35              : #include "internal/extensionsregister.h"
      36              : 
      37              : #include "rcommand/icommandsregister.h"
      38              : #include "rcommand/icommandsstate.h"
      39              : 
      40              : #include "global/api/ifilesystemapirestriction.h"
      41              : #include "api/v1/extapiv1.h"
      42              : 
      43              : #include "muse_framework_config.h"
      44              : #ifdef MUSE_MODULE_DIAGNOSTICS
      45              : #include "diagnostics/idiagnosticspathsregister.h"
      46              : #endif
      47              : 
      48              : using namespace muse::extensions;
      49              : using namespace muse::modularity;
      50              : 
      51              : static const std::string mname("extensions");
      52              : 
      53            0 : std::string ExtensionsModule::moduleName() const
      54              : {
      55            0 :     return mname;
      56              : }
      57              : 
      58            0 : void ExtensionsModule::registerExports()
      59              : {
      60            0 :     m_configuration = std::make_shared<ExtensionsConfiguration>(globalCtx());
      61            0 :     m_extensionsRegister = std::make_shared<ExtensionsRegister>();
      62              : 
      63            0 :     globalIoc()->registerExport<IExtensionsConfiguration>(mname, m_configuration);
      64            0 :     globalIoc()->registerExport<IExtensionsRegister>(mname, m_extensionsRegister);
      65            0 : }
      66              : 
      67            0 : void ExtensionsModule::resolveImports()
      68              : {
      69            0 :     auto ir = globalIoc()->resolve<interactive::IInteractiveUriRegister>(mname);
      70            0 :     if (ir) {
      71            0 :         ir->registerQmlUri(Uri("muse://extensions/viewer"), "Muse.Extensions", "ExtensionViewerDialog");
      72            0 :         ir->registerQmlUri(Uri("muse://extensions/apidump"), "Muse.Extensions", "ExtensionsApiDumpDialog");
      73              :     }
      74              : 
      75            0 :     auto cr = globalIoc()->resolve<muse::rcommand::ICommandsRegister>(mname);
      76            0 :     if (cr) {
      77            0 :         auto ecr = std::make_shared<ExtensionsCommandsRegister>();
      78            0 :         ecr->init();
      79            0 :         cr->reg(ecr);
      80            0 :     }
      81            0 : }
      82              : 
      83            0 : void ExtensionsModule::registerApi()
      84              : {
      85            0 :     apiv1::ExtApiV1::registerQmlTypes();
      86              : 
      87              :     // added fs restrictions
      88            0 :     auto fsRestriction = globalIoc()->resolve<muse::api::IFileSystemApiRestriction>(moduleName());
      89            0 :     if (fsRestriction) {
      90            0 :         fsRestriction->addAllowedPathBase("extensions: userPath", m_configuration->userPath());
      91            0 :         fsRestriction->addAllowedPathBase("plugins (legacy): userPath", m_configuration->pluginsUserPath());
      92              :     }
      93            0 : }
      94              : 
      95            0 : void ExtensionsModule::onInit(const IApplication::RunMode&)
      96              : {
      97            0 :     m_configuration->init();
      98            0 :     m_extensionsRegister->reload();
      99              : 
     100              : #ifdef MUSE_MODULE_DIAGNOSTICS
     101            0 :     auto pr = globalIoc()->resolve<muse::diagnostics::IDiagnosticsPathsRegister>(mname);
     102            0 :     if (pr) {
     103            0 :         pr->reg("extensions: defaultPath", m_configuration->defaultPath());
     104            0 :         pr->reg("extensions: userPath", m_configuration->userPath());
     105            0 :         pr->reg("plugins (legacy): defaultPath", m_configuration->pluginsDefaultPath());
     106            0 :         pr->reg("plugins (legacy): userPath", m_configuration->pluginsUserPath());
     107              :     }
     108              : #endif
     109            0 : }
     110              : 
     111              : // Context
     112            0 : IContextSetup* ExtensionsModule::newContext(const muse::modularity::ContextPtr& ctx) const
     113              : {
     114            0 :     return new ExtensionsContext(ctx);
     115              : }
     116              : 
     117            0 : void ExtensionsContext::registerExports()
     118              : {
     119            0 :     m_actionController = std::make_shared<ExtensionsActionController>(iocContext());
     120            0 :     m_provider = std::make_shared<ExtensionsProvider>(iocContext());
     121              : 
     122            0 :     ioc()->registerExport<IExtensionsUiEngine>(mname, new ExtensionsUiEngine(iocContext()));
     123            0 :     ioc()->registerExport<IExtensionsProvider>(mname, m_provider);
     124            0 :     ioc()->registerExport<IExtensionInstaller>(mname, new ExtensionInstaller(iocContext()));
     125            0 : }
     126              : 
     127            0 : void ExtensionsContext::resolveImports()
     128              : {
     129            0 :     auto cs = ioc()->resolve<muse::rcommand::ICommandsState>(mname);
     130            0 :     if (cs) {
     131            0 :         cs->reg(std::make_shared<ExtensionsCommandsState>(iocContext()));
     132              :     }
     133            0 : }
     134              : 
     135            0 : void ExtensionsContext::onInit(const IApplication::RunMode&)
     136              : {
     137            0 :     m_actionController->init();
     138            0 :     m_provider->reloadExtensions();
     139            0 : }
        

Generated by: LCOV version 2.0-1