diff options
author | Bernd Weimer <bernd.weimer@pelagicore.com> | 2020-01-21 08:37:25 +0100 |
---|---|---|
committer | Bernd Weimer <bernd.weimer@pelagicore.com> | 2020-01-24 17:18:23 +0100 |
commit | df78fb1c31b2fcd1437c8f98de53c28514f83e54 (patch) | |
tree | 4c0672ea79161c92f25c56f5d890695ab202bfa6 | |
parent | 29c8cec06482fab8816eae2efcff738f498be371 (diff) |
Fix IPC extensions for quick-launched applications
IPC extensions did not work in an application, when it was started in
a quick-launched runtime, because the extension interfaces were not
registered.
Besides, a crash is avoided, should an ApplicationInterfaceExtension
type be used in quicklaunchQml code (although the interface will not
work).
Change-Id: Ie6a86d72fd41b401ce8754d0b6f4379749b56ea7
Reviewed-by: Robert Griebl <robert.griebl@qt.io>
-rw-r--r-- | src/manager-lib/applicationipcmanager.cpp | 39 | ||||
-rw-r--r-- | src/manager-lib/applicationipcmanager.h | 1 | ||||
-rw-r--r-- | src/manager-lib/nativeruntime.cpp | 3 | ||||
-rw-r--r-- | src/tools/launcher-qml/launcher-qml.cpp | 31 | ||||
-rw-r--r-- | tests/qml/quicklaunch/apps/tld.test.quicklaunch/app.qml | 5 | ||||
-rw-r--r-- | tests/qml/quicklaunch/tst_quicklaunch.qml | 16 |
6 files changed, 67 insertions, 28 deletions
diff --git a/src/manager-lib/applicationipcmanager.cpp b/src/manager-lib/applicationipcmanager.cpp index 2e0767f3..a309fdc0 100644 --- a/src/manager-lib/applicationipcmanager.cpp +++ b/src/manager-lib/applicationipcmanager.cpp @@ -293,21 +293,34 @@ void ApplicationIPCManager::attachToRuntime(AbstractRuntime *runtime) { #if defined(AM_MULTI_PROCESS) if (NativeRuntime *nativeRuntime = qobject_cast<NativeRuntime *>(runtime)) { - connect(nativeRuntime, &NativeRuntime::applicationConnectedToPeerDBus, this, - [this, nativeRuntime](const QDBusConnection &connection, Application *application) { - if (!application || !connection.isConnected()) - return; + if (!nativeRuntime->isQuickLauncher()) { + connect(nativeRuntime, &NativeRuntime::applicationConnectedToPeerDBus, this, + [this, nativeRuntime](const QDBusConnection &connection, Application *application) { + registerInterfaces(nativeRuntime, connection, application); + }); + } + } +#else + Q_UNUSED(runtime) +#endif +} - // register all known extension interfaces - for (ApplicationIPCInterface *iface : qAsConst(m_interfaces)) - registerInterfaceHelper(connection, iface, application, nativeRuntime); +void ApplicationIPCManager::registerInterfaces(AbstractRuntime *runtime, const QDBusConnection &connection, + Application *application) +{ +#if defined(AM_MULTI_PROCESS) + if (NativeRuntime *nativeRuntime = qobject_cast<NativeRuntime *>(runtime)) { + Q_ASSERT(application); + Q_ASSERT(connection.isConnected()); - // make sure that future extension interfaces get registered as well - connect(this, &ApplicationIPCManager::interfaceCreated, - this, [connection, nativeRuntime](ApplicationIPCInterface *iface) { - registerInterfaceHelper(connection, iface, nativeRuntime->application(), nativeRuntime); + // register all known extension interfaces + for (ApplicationIPCInterface *iface : qAsConst(m_interfaces)) + registerInterfaceHelper(connection, iface, application, nativeRuntime); - }); + // make sure that future extension interfaces get registered as well + connect(this, &ApplicationIPCManager::interfaceCreated, + this, [connection, nativeRuntime](ApplicationIPCInterface *iface) { + registerInterfaceHelper(connection, iface, nativeRuntime->application(), nativeRuntime); }); connect(nativeRuntime, &NativeRuntime::applicationDisconnectedFromPeerDBus, @@ -319,6 +332,8 @@ void ApplicationIPCManager::attachToRuntime(AbstractRuntime *runtime) } #else Q_UNUSED(runtime) + Q_UNUSED(application) + Q_UNUSED(connection) #endif } diff --git a/src/manager-lib/applicationipcmanager.h b/src/manager-lib/applicationipcmanager.h index 427a6fef..1c8827d8 100644 --- a/src/manager-lib/applicationipcmanager.h +++ b/src/manager-lib/applicationipcmanager.h @@ -77,6 +77,7 @@ public: QVector<ApplicationIPCInterface *> interfaces() const; void attachToRuntime(AbstractRuntime *runtime); + void registerInterfaces(AbstractRuntime *runtime, const QDBusConnection &connection, Application *application); signals: void interfaceCreated(ApplicationIPCInterface *iface); diff --git a/src/manager-lib/nativeruntime.cpp b/src/manager-lib/nativeruntime.cpp index 408efa3e..1ff1b065 100644 --- a/src/manager-lib/nativeruntime.cpp +++ b/src/manager-lib/nativeruntime.cpp @@ -172,6 +172,8 @@ bool NativeRuntime::attachApplicationToQuickLauncher(Application *app) // we have no D-Bus connection yet, so hope for the best ret = true; } else { + QDBusConnection connection(m_dbusConnectionName); + ApplicationIPCManager::instance()->registerInterfaces(this, connection, app); ret = startApplicationViaLauncher(); } @@ -588,6 +590,7 @@ AbstractRuntime *NativeRuntimeManager::create(AbstractContainer *container, Appl QScopedPointer<NativeRuntime> nrt(new NativeRuntime(container, app, this)); if (!nrt || !nrt->initialize()) return nullptr; + return nrt.take(); } diff --git a/src/tools/launcher-qml/launcher-qml.cpp b/src/tools/launcher-qml/launcher-qml.cpp index 77f1520a..ad40cdad 100644 --- a/src/tools/launcher-qml/launcher-qml.cpp +++ b/src/tools/launcher-qml/launcher-qml.cpp @@ -255,22 +255,6 @@ Controller::Controller(LauncherMain *a, bool quickLaunched, const QString &direc StartupTimer::instance()->checkpoint("after window registration"); - QString quicklaunchQml = m_configuration.value((qSL("quicklaunchQml"))).toString(); - if (!quicklaunchQml.isEmpty() && quickLaunched) { - if (QFileInfo(quicklaunchQml).isRelative()) - quicklaunchQml.prepend(a->baseDir()); - - QQmlComponent quicklaunchComp(&m_engine, quicklaunchQml); - if (!quicklaunchComp.isError()) { - QScopedPointer<QObject> quicklaunchInstance(quicklaunchComp.create()); - quicklaunchComp.completeCreate(); - } else { - const QList<QQmlError> errors = quicklaunchComp.errors(); - for (const QQmlError &error : errors) - qCCritical(LogQmlRuntime) << error; - } - } - if (directLoad.isEmpty()) { m_applicationInterface = new QmlApplicationInterface(a->p2pDBusName(), a->notificationDBusName(), this); connect(m_applicationInterface, &QmlApplicationInterface::startApplication, @@ -291,6 +275,21 @@ Controller::Controller(LauncherMain *a, bool quickLaunched, const QString &direc }, Qt::QueuedConnection); } + QString quicklaunchQml = m_configuration.value((qSL("quicklaunchQml"))).toString(); + if (!quicklaunchQml.isEmpty() && quickLaunched) { + if (QFileInfo(quicklaunchQml).isRelative()) + quicklaunchQml.prepend(a->baseDir()); + + QQmlComponent quicklaunchComp(&m_engine, quicklaunchQml); + if (!quicklaunchComp.isError()) { + QScopedPointer<QObject> quicklaunchInstance(quicklaunchComp.create()); + } else { + const QList<QQmlError> errors = quicklaunchComp.errors(); + for (const QQmlError &error : errors) + qCCritical(LogQmlRuntime) << error; + } + } + StartupTimer::instance()->checkpoint("after application interface initialization"); } diff --git a/tests/qml/quicklaunch/apps/tld.test.quicklaunch/app.qml b/tests/qml/quicklaunch/apps/tld.test.quicklaunch/app.qml index 1c203d4f..fbcf1fca 100644 --- a/tests/qml/quicklaunch/apps/tld.test.quicklaunch/app.qml +++ b/tests/qml/quicklaunch/apps/tld.test.quicklaunch/app.qml @@ -45,4 +45,9 @@ import QtApplicationManager.Application 2.0 ApplicationManagerWindow { width: 320 height: 240 + + ApplicationInterfaceExtension { + name: "quicklaunch.interface" + onReadyChanged: object.acknowledge(); + } } diff --git a/tests/qml/quicklaunch/tst_quicklaunch.qml b/tests/qml/quicklaunch/tst_quicklaunch.qml index b840e691..85e0165b 100644 --- a/tests/qml/quicklaunch/tst_quicklaunch.qml +++ b/tests/qml/quicklaunch/tst_quicklaunch.qml @@ -51,6 +51,8 @@ TestCase { when: windowShown name: "Quicklaunch" + property bool acknowledged: false + SignalSpy { id: windowAddedSpy target: WindowManager @@ -62,6 +64,12 @@ TestCase { signalName: "runStateChanged" } + ApplicationIPCInterface { + function acknowledge() { acknowledged = true; } + Component.onCompleted: ApplicationIPCManager.registerInterface(this, "quicklaunch.interface", {}); + } + + function test_quicklaunch() { var app = ApplicationManager.application("tld.test.quicklaunch"); runStateChangedSpy.target = app; @@ -71,14 +79,22 @@ TestCase { // sometimes caused some race where the app would not be started at all in the past: app.start(); windowAddedSpy.wait(3000); + tryCompare(testCase, "acknowledged", true); runStateChangedSpy.clear(); app.stop(true); runStateChangedSpy.wait(3000); // wait for ShuttingDown runStateChangedSpy.wait(3000); // wait for NotRunning + wait(1000); // Unfortunately there is no reliable means to determine, whether a quicklaunch process // is running, but after at least 2s now, there should be a process that can be attached to. + acknowledged = false; app.start(); windowAddedSpy.wait(3000); + tryCompare(testCase, "acknowledged", true); + runStateChangedSpy.clear(); + app.stop(true); + runStateChangedSpy.wait(3000); // wait for ShuttingDown + runStateChangedSpy.wait(3000); // wait for NotRunning } } |