@@ -33,12 +33,12 @@ const QByteArray kScreenTransformFunctionUntypedSignature =
3333 " transformFrame(QVariant,QVariant)" );
3434const QByteArray kScreenTransformFunctionTypedSignature =
3535 QMetaObject::normalizedSignature (" transformFrame(QVariant,QDateTime)" );
36- const QByteArray kScreenInitFunctionUntypedSignature =
36+ const QByteArray kQmlComponentInitFunctionUntypedSignature =
3737 QMetaObject::normalizedSignature (
3838 " init(QVariant,QVariant)" );
39- const QByteArray kScreenInitFunctionTypedSignature =
39+ const QByteArray kQmlComponentFunctionTypedSignature =
4040 QMetaObject::normalizedSignature (" init(QString,bool)" );
41- const QByteArray kScreenShutdownFunctionSignature =
41+ const QByteArray kQmlComponentShutdownFunctionSignature =
4242 QMetaObject::normalizedSignature (" shutdown()" );
4343} // anonymous namespace
4444#endif
@@ -95,7 +95,6 @@ bool ControllerScriptEngineLegacy::callFunctionOnObjects(
9595
9696 const QJSValue global = m_pJSEngine->globalObject ();
9797
98- // TODO: ICI
9998 bool success = true ;
10099 for (const QString& prefixName : scriptFunctionPrefixes) {
101100 QJSValue prefix = global.property (prefixName);
@@ -155,7 +154,7 @@ bool ControllerScriptEngineLegacy::callShutdownFunction() {
155154 }
156155
157156 QMetaMethod shutdownFunction;
158- int methodIdx = metaObject->indexOfMethod (kScreenShutdownFunctionSignature );
157+ int methodIdx = metaObject->indexOfMethod (kQmlComponentShutdownFunctionSignature );
159158
160159 if (methodIdx == -1 || !metaObject->method (methodIdx).isValid ()) {
161160 qCDebug (m_logger) << " QML Scene for screen" << screenIdentifier
@@ -219,12 +218,12 @@ bool ControllerScriptEngineLegacy::callInitFunction() {
219218
220219 QMetaMethod initFunction;
221220 bool typed = false ;
222- int methodIdx = metaObject->indexOfMethod (kScreenInitFunctionUntypedSignature );
221+ int methodIdx = metaObject->indexOfMethod (kQmlComponentInitFunctionUntypedSignature );
223222
224223 if (methodIdx == -1 || !metaObject->method (methodIdx).isValid ()) {
225224 qCDebug (m_logger) << " QML Scene for screen" << screenIdentifier
226225 << " has no valid untyped init method." ;
227- methodIdx = metaObject->indexOfMethod (kScreenInitFunctionTypedSignature );
226+ methodIdx = metaObject->indexOfMethod (kQmlComponentFunctionTypedSignature );
228227 typed = true ;
229228 }
230229
@@ -459,6 +458,66 @@ bool ControllerScriptEngineLegacy::initialize() {
459458#ifdef MIXXX_USE_QML
460459 } else {
461460 if (script.identifier .isEmpty ()) {
461+ if (availableScreens.isEmpty ()) {
462+ QQmlComponent qmlComponent = QQmlComponent (
463+ std::dynamic_pointer_cast<QQmlEngine>(m_pJSEngine).get ());
464+
465+ QFile scene = QFile (script.file .absoluteFilePath ());
466+
467+ QDir dir (m_resourcePath + " /qml/" );
468+
469+ scene.open (QIODevice::ReadOnly);
470+ qmlComponent.setData (scene.readAll (),
471+ // Obfuscate the scene filename to make it appear in the QML folder.
472+ // This allows a smooth integration with QML components.
473+ QUrl::fromLocalFile (
474+ dir.absoluteFilePath (script.file .fileName ())));
475+ scene.close ();
476+
477+ while (qmlComponent.isLoading ()) {
478+ qCDebug (m_logger) << " Waiting for component "
479+ << script.file .absoluteFilePath ()
480+ << " to be ready: " << qmlComponent.progress ();
481+ QCoreApplication::processEvents (QEventLoop::WaitForMoreEvents, 500 );
482+ }
483+
484+ if (qmlComponent.isError ()) {
485+ const QList<QQmlError> errorList = qmlComponent.errors ();
486+ for (const QQmlError& error : errorList) {
487+ qCWarning (m_logger)
488+ << " Unable to load the QML scene:"
489+ << error.url () << " at line" << error.line ()
490+ << " , error: " << error;
491+ showQMLExceptionDialog (error, true );
492+ }
493+ }
494+
495+ VERIFY_OR_DEBUG_ASSERT (qmlComponent.isReady ()) {
496+ qCWarning (m_logger)
497+ << " QMLComponent isn't ready although "
498+ " synchronous load was requested." ;
499+ }
500+
501+ QObject* pRootObject = qmlComponent.createWithInitialProperties (
502+ QVariantMap{});
503+ if (qmlComponent.isError ()) {
504+ const QList<QQmlError> errorList = qmlComponent.errors ();
505+ for (const QQmlError& error : errorList) {
506+ qCWarning (m_logger) << error.url () << error.line () << error;
507+ }
508+ }
509+
510+ std::shared_ptr<QQuickItem> rootItem =
511+ std::shared_ptr<QQuickItem>(qobject_cast<QQuickItem*>(pRootObject));
512+ if (!rootItem) {
513+ qWarning (" Oopsie run: Not a QQuickItem" );
514+ delete pRootObject;
515+ }
516+
517+ watchFilePath (script.file .absoluteFilePath ());
518+
519+ m_rootItems.insert (" screenIdentifier" , rootItem);
520+ }
462521 while (!availableScreens.isEmpty ()) {
463522 QString screenIdentifier (availableScreens.firstKey ());
464523 if (!bindSceneToScreen (script,
0 commit comments