Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions framework/extensions/internal/legacy/extpluginrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
#include "../../api/v1/ipluginapiv1.h"
#include "../../extensionserrors.h"

#include "translation.h"

#include "log.h"

using namespace muse;
using namespace muse::extensions;
using namespace muse::extensions::legacy;
using namespace muse::extensions::apiv1;

//! Loads and runs the legacy plug-in described by `action`.
Ret ExtPluginRunner::run(const Action& action)
{
io::path_t qmlPath = action.path;
Expand All @@ -41,24 +44,40 @@ Ret ExtPluginRunner::run(const Action& action)
//! making it easier to maintain backward compatibility and stability.
QQmlComponent component = QQmlComponent(engine()->qmlEngineApiV1(), qmlPath.toQString());
if (!component.isReady()) {
const QString errorMessage = component.errorString().trimmed();
LOGE() << "Failed to load QML file: " << qmlPath;
LOGE() << component.errorString();
LOGE() << errorMessage;
showError(errorMessage);
return make_ret(Err::ExtLoadError);
}

QObject* obj = component.create();
if (!obj) {
LOGE() << "Failed to create QML Object: " << qmlPath;
const QString errorMessage = component.errorString().trimmed();
LOGE() << "Failed to create QML Object: " << qmlPath << ", error: " << errorMessage;
showError(errorMessage);
return make_ret(Err::ExtLoadError);
}

IPluginApiV1* plugin = dynamic_cast<IPluginApiV1*>(obj);
if (!plugin) {
LOGE() << "Qml Object not MuseScore plugin: " << qmlPath;
const QString errorMessage = muse::qtrc("extensions", "QML object is not a MuseScore plug-in: %1").arg(qmlPath.toQString());
LOGE() << errorMessage;
showError(errorMessage);
return make_ret(Err::ExtBadFormat);
}

plugin->runPlugin();

return muse::make_ok();
}

//! Displays `errorMessage` in a copyable error dialog.
void ExtPluginRunner::showError(const QString& errorMessage)
{
IInteractive::Text text(
muse::qtrc("extensions", "An error occurred in the plug-in: %1. Please contact the developer.").arg(errorMessage).toStdString(),
IInteractive::TextFormat::PlainText);
text.detailedText = errorMessage.toStdString();
interactive()->error(muse::trc("extensions", "Plug-in error"), text);
}
8 changes: 8 additions & 0 deletions framework/extensions/internal/legacy/extpluginrunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define MUSE_EXTENSIONS_EXTPLUGINRUNNER_H

#include "global/types/ret.h"
#include "interactive/iinteractive.h"

#include "../../extensionstypes.h"

Expand All @@ -35,12 +36,19 @@ namespace muse::extensions::legacy {
class ExtPluginRunner : public Contextable
{
ContextInject<IExtensionsUiEngine> engine = { this };
ContextInject<IInteractive> interactive = { this };

public:
//! Creates a runner in the given dependency-injection context.
ExtPluginRunner(const modularity::ContextPtr& iocCtx)
: Contextable(iocCtx) {}

//! Loads and runs the legacy plug-in described by `action`.
Ret run(const Action& action);

private:
//! Displays `errorMessage` in a copyable error dialog.
void showError(const QString& errorMessage);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Column {
anchors.fill: parent
anchors.margins: 1

contentWidth: contentItem.childrenRect.width
flickableDirection: Flickable.AutoFlickDirection
contentWidth: width
flickableDirection: Flickable.VerticalFlick

spacing: 0

Expand Down Expand Up @@ -91,8 +91,8 @@ Column {
background.color: model.index % 2 === 0 ? ui.theme.backgroundSecondaryColor : "transparent"
mouseArea.enabled: false

implicitWidth: label.implicitWidth + 2 * 30
width: Math.max(ListView.view.width, implicitWidth)
implicitHeight: Math.max(30, label.implicitHeight + 12)
width: ListView.view.width

StyledTextLabel {
id: label
Expand All @@ -104,6 +104,7 @@ Column {
horizontalAlignment: Text.AlignLeft

width: parent.width
wrapMode: Text.WrapAnywhere

textFormat: Qt.RichText
text: model.errorText
Expand Down