diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -324,6 +324,18 @@ QRect availableScreenRect() const; + /** + * By default a QtQuick applet is marked as ready when the source is loaded + * and the root component is initialised. + * + * Calling this method during initial component creation allows a user + * to defer this. + * + * @returns an opaque cookie that inhibits signalling that the UI is ready. + * When all inhibitors are released the UiReady constraint is set. + */ + Q_INVOKABLE QVariant createUiReadyInhibitor(); + static AppletInterface *qmlAttachedProperties(QObject *object) { return qobject_cast(AppletQuickItem::qmlAttachedProperties(object)); @@ -474,6 +486,7 @@ QVariantList m_args; Plasma::Types::BackgroundHints m_backgroundHints; bool m_hideOnDeactivate : 1; + int m_loadingRef = 0; //this is used to build an emacs style shortcut int m_oldKeyboardShortcut; QObject *m_dummyNativeInterface; diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -169,7 +169,9 @@ geometryChanged(QRectF(), QRectF(x(), y(), width(), height())); emit busyChanged(); - applet()->updateConstraints(Plasma::Types::UiReadyConstraint); + if (m_loadingRef == 0) { + applet()->updateConstraints(Plasma::Types::UiReadyConstraint); + } connect(applet(), &Plasma::Applet::activated, this, [ = ]() { @@ -851,5 +853,18 @@ return AppletQuickItem::eventFilter(watched, event); } +QVariant AppletInterface::createUiReadyInhibitor() +{ + m_loadingRef++; + auto cookie = QSharedPointer::create(this); + connect(cookie.data(), &QObject::destroyed, this, [this]() { + m_loadingRef--; + if (m_loadingRef == 0) { + applet()->updateConstraints(Plasma::Types::UiReadyConstraint); + } + }); + return QVariant::fromValue(cookie); +} + #include "moc_appletinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.h b/src/scriptengines/qml/plasmoid/wallpaperinterface.h --- a/src/scriptengines/qml/plasmoid/wallpaperinterface.h +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.h @@ -84,6 +84,11 @@ Q_INVOKABLE QAction *action(QString name) const; + /** + * @see AppletInterface::createUiReadyInhibitor + */ + Q_INVOKABLE QVariant createUiReadyInhibitor(); + static WallpaperInterface *qmlAttachedProperties(QObject *object); Q_SIGNALS: diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp --- a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp @@ -259,6 +259,11 @@ } } +QVariant WallpaperInterface::createUiReadyInhibitor() +{ + return m_containmentInterface->createUiReadyInhibitor(); +} + WallpaperInterface * WallpaperInterface::qmlAttachedProperties(QObject* object) { //at the moment of the attached object creation, the root item is the only one that hasn't a parent