MuseScore/src/diagnostics/diagnosticsmodule.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

152 lines
5.6 KiB
C++
Raw Normal View History

2021-06-17 16:19:00 +02:00
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "diagnosticsmodule.h"
#include <QQmlEngine>
#include "modularity/ioc.h"
#include "global/iglobalconfiguration.h"
2021-06-17 16:19:00 +02:00
#include "ui/iinteractiveuriregister.h"
2021-06-17 16:52:32 +02:00
#include "ui/iuiactionsregister.h"
#include "internal/diagnosticsconfiguration.h"
2021-06-17 16:52:32 +02:00
#include "internal/diagnosticsactions.h"
#include "internal/diagnosticsactionscontroller.h"
2021-06-18 12:41:15 +02:00
#include "internal/diagnosticspathsregister.h"
2021-08-27 16:51:23 +02:00
#include "internal/engravingelementsprovider.h"
2021-06-18 12:41:15 +02:00
#include "internal/crashhandler/crashhandler.h"
2021-06-18 12:41:15 +02:00
#include "view/diagnosticspathsmodel.h"
2021-11-23 15:42:37 +01:00
#include "view/system/profilerviewmodel.h"
2021-06-17 16:19:00 +02:00
2021-08-23 18:25:12 +02:00
#include "view/keynav/diagnosticnavigationmodel.h"
#include "view/keynav/abstractkeynavdevitem.h"
#include "view/keynav/keynavdevsection.h"
#include "view/keynav/keynavdevsubsection.h"
#include "view/keynav/keynavdevcontrol.h"
#include "view/diagnosticaccessiblemodel.h"
2021-08-27 16:51:23 +02:00
#include "view/engraving/engravingelementsmodel.h"
#include "devtools/crashhandlerdevtoolsmodel.h"
#include "log.h"
#include "config.h"
2021-06-17 16:19:00 +02:00
using namespace mu::diagnostics;
2021-06-29 16:52:02 +02:00
using namespace mu::modularity;
2021-06-17 16:19:00 +02:00
static std::shared_ptr<DiagnosticsConfiguration> s_configuration = std::make_shared<DiagnosticsConfiguration>();
2021-06-17 16:52:32 +02:00
static std::shared_ptr<DiagnosticsActionsController> s_actionsController = std::make_shared<DiagnosticsActionsController>();
2021-06-17 16:19:00 +02:00
std::string DiagnosticsModule::moduleName() const
{
return "diagnostics";
}
void DiagnosticsModule::registerExports()
{
2021-06-18 12:41:15 +02:00
ioc()->registerExport<IDiagnosticsPathsRegister>(moduleName(), new DiagnosticsPathsRegister());
2021-08-27 16:51:23 +02:00
ioc()->registerExport<EngravingElementsProvider>(moduleName(), new EngravingElementsProvider());
2021-06-17 16:19:00 +02:00
}
void DiagnosticsModule::resolveImports()
{
2021-06-17 16:52:32 +02:00
auto ir = ioc()->resolve<ui::IInteractiveUriRegister>(moduleName());
2021-06-17 16:19:00 +02:00
if (ir) {
2021-08-23 18:25:12 +02:00
ir->registerQmlUri(Uri("musescore://diagnostics/system/paths"), "MuseScore/Diagnostics/DiagnosticPathsDialog.qml");
2021-11-23 15:42:37 +01:00
ir->registerQmlUri(Uri("musescore://diagnostics/system/profiler"), "MuseScore/Diagnostics/DiagnosticProfilerDialog.qml");
ir->registerQmlUri(Uri("musescore://diagnostics/navigation/tree"), "MuseScore/Diagnostics/DiagnosticNavigationDialog.qml");
2021-08-23 18:25:12 +02:00
ir->registerQmlUri(Uri("musescore://diagnostics/accessible/tree"), "MuseScore/Diagnostics/DiagnosticAccessibleDialog.qml");
2021-08-27 16:51:23 +02:00
ir->registerQmlUri(Uri("musescore://diagnostics/engraving/elements"), "MuseScore/Diagnostics/EngravingElementsDialog.qml");
2021-06-17 16:52:32 +02:00
}
auto ar = ioc()->resolve<ui::IUiActionsRegister>(moduleName());
if (ar) {
ar->reg(std::make_shared<DiagnosticsActions>());
2021-06-17 16:19:00 +02:00
}
}
void DiagnosticsModule::registerUiTypes()
{
2021-06-18 12:41:15 +02:00
qmlRegisterType<DiagnosticsPathsModel>("MuseScore.Diagnostics", 1, 0, "DiagnosticsPathsModel");
2021-11-23 15:42:37 +01:00
qmlRegisterType<ProfilerViewModel>("MuseScore.Diagnostics", 1, 0, "ProfilerViewModel");
2021-08-23 18:25:12 +02:00
qmlRegisterType<DiagnosticNavigationModel>("MuseScore.Diagnostics", 1, 0, "DiagnosticNavigationModel");
qmlRegisterUncreatableType<AbstractKeyNavDevItem>("MuseScore.Diagnostics", 1, 0, "AbstractKeyNavDevItem", "Cannot create a Abstract");
qmlRegisterUncreatableType<KeyNavDevSubSection>("MuseScore.Diagnostics", 1, 0, "KeyNavDevSubSection", "Cannot create");
qmlRegisterUncreatableType<KeyNavDevSection>("MuseScore.Diagnostics", 1, 0, "KeyNavDevSection", "Cannot create a KeyNavDevSection");
qmlRegisterUncreatableType<KeyNavDevControl>("MuseScore.Diagnostics", 1, 0, "KeyNavDevControl", "Cannot create a KeyNavDevControl");
qmlRegisterType<DiagnosticAccessibleModel>("MuseScore.Diagnostics", 1, 0, "DiagnosticAccessibleModel");
2021-08-27 16:51:23 +02:00
qmlRegisterType<EngravingElementsModel>("MuseScore.Diagnostics", 1, 0, "EngravingElementsModel");
qmlRegisterType<CrashHandlerDevToolsModel>("MuseScore.Diagnostics", 1, 0, "CrashHandlerDevToolsModel");
2021-06-17 16:19:00 +02:00
}
void DiagnosticsModule::onInit(const framework::IApplication::RunMode&)
{
s_configuration->init();
2021-06-17 16:52:32 +02:00
s_actionsController->init();
auto globalConf = modularity::ioc()->resolve<framework::IGlobalConfiguration>(moduleName());
IF_ASSERT_FAILED(globalConf) {
return;
}
#ifdef BUILD_CRASHPAD_CLIENT
static CrashHandler s_crashHandler;
#ifdef _MSC_VER
2022-05-23 12:34:38 +02:00
io::path_t handlerFile("crashpad_handler.exe");
#else
2022-05-23 12:34:38 +02:00
io::path_t handlerFile("crashpad_handler");
#endif // _MSC_VER
2022-05-23 12:34:38 +02:00
io::path_t handlerPath = globalConf->appBinPath() + "/" + handlerFile;
io::path_t dumpsDir = globalConf->userAppDataPath() + "/logs/dumps";
fileSystem()->makePath(dumpsDir);
std::string serverUrl(CRASH_REPORT_URL);
if (!s_configuration->isDumpUploadAllowed()) {
serverUrl.clear();
LOGD() << "not allowed dump upload";
} else {
LOGD() << "crash server url: " << serverUrl;
}
bool ok = s_crashHandler.start(handlerPath, dumpsDir, serverUrl);
if (!ok) {
LOGE() << "failed start crash handler";
} else {
LOGI() << "success start crash handler";
}
#else
LOGW() << "crash handling disabled";
#endif // BUILD_CRASHPAD_CLIENT
2021-06-17 16:19:00 +02:00
}