diff options
author | Robert Griebl <robert.griebl@pelagicore.com> | 2018-06-21 15:35:18 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@pelagicore.com> | 2018-06-21 15:36:47 +0000 |
commit | 0dc94333e70bb4cbb7e6acbf6f79267a4ba8f29e (patch) | |
tree | ffcf09de545a578e0a0d297d9bb882ae3baf4ee3 | |
parent | 37ec2100342e3447552f0948aac11c155408254f (diff) | |
download | qtapplicationmanager-0dc94333e70bb4cbb7e6acbf6f79267a4ba8f29e.tar.gz |
Fix quick-launched apps not starting reliably
The logic around when to register extension interfaces and when to start apps
in a launcher was quite flawed. This commit also cleans up the existing state
booleans and renames them to be more descriptive.
Change-Id: If68e2cf012c7dfec4de0ddd396b19cd03e147693
Reviewed-by: Bernd Weimer <bernd.weimer@pelagicore.com>
-rw-r--r-- | src/manager-lib/nativeruntime.cpp | 55 | ||||
-rw-r--r-- | src/manager-lib/nativeruntime.h | 6 |
2 files changed, 33 insertions, 28 deletions
diff --git a/src/manager-lib/nativeruntime.cpp b/src/manager-lib/nativeruntime.cpp index bb22cacf..1d139f04 100644 --- a/src/manager-lib/nativeruntime.cpp +++ b/src/manager-lib/nativeruntime.cpp @@ -110,7 +110,7 @@ static qint64 getDBusPeerPid(const QDBusConnection &conn) NativeRuntime::NativeRuntime(AbstractContainer *container, const Application *app, NativeRuntimeManager *manager) : AbstractRuntime(container, app, manager) , m_isQuickLauncher(app == nullptr) - , m_needsLauncher(manager->identifier() != qL1S("native")) + , m_startedViaLauncher(manager->identifier() != qL1S("native")) { QString dbusAddress = QUuid::createUuid().toString().mid(1,36); m_applicationInterfaceServer = new QDBusServer(qSL("unix:path=/tmp/dbus-qtam-") + dbusAddress); @@ -164,7 +164,7 @@ bool NativeRuntime::isQuickLauncher() const bool NativeRuntime::attachApplicationToQuickLauncher(const Application *app) { - if (!app || !isQuickLauncher() || !m_needsLauncher) + if (!app || !isQuickLauncher() || !m_startedViaLauncher) return false; m_isQuickLauncher = false; @@ -178,8 +178,7 @@ bool NativeRuntime::attachApplicationToQuickLauncher(const Application *app) // we have no D-Bus connection yet, so hope for the best ret = true; } else { - onApplicationFinishedInitialization(); - ret = m_applicationInterfaceConnected; + ret = startApplicationViaLauncher(); } if (ret) @@ -190,7 +189,7 @@ bool NativeRuntime::attachApplicationToQuickLauncher(const Application *app) bool NativeRuntime::initialize() { - if (m_needsLauncher) { + if (m_startedViaLauncher) { static QVector<QString> possibleLocations; if (possibleLocations.isEmpty()) { // try the main binaries directory @@ -231,12 +230,12 @@ bool NativeRuntime::initialize() void NativeRuntime::shutdown(int exitCode, QProcess::ExitStatus status) { - if (!m_isQuickLauncher || m_applicationInterfaceConnected) { + if (!m_isQuickLauncher || m_connectedToRuntimeInterface) { qCDebug(LogSystem) << "NativeRuntime (id:" << (m_app ? m_app->id() : qSL("(none)")) << "pid:" << m_process->processId() << ") exited with code:" << exitCode << "status:" << status; } - m_applicationInterfaceConnected = m_launchWhenReady = m_dbusConnection = false; + m_connectedToRuntimeInterface = m_dbusConnection = false; // unregister all extension interfaces const auto interfaces = ApplicationIPCManager::instance()->interfaces(); @@ -301,7 +300,7 @@ bool NativeRuntime::start() { qSL("dbus"), dbusConfig } }; - if (!m_needsLauncher && !m_isQuickLauncher) + if (!m_startedViaLauncher && !m_isQuickLauncher) config.insert(qSL("systemProperties"), systemProperties()); if (!uiConfig.isEmpty()) config.insert(qSL("ui"), uiConfig); @@ -343,9 +342,7 @@ bool NativeRuntime::start() QStringList args; - if (m_needsLauncher) { - m_launchWhenReady = true; - } else { + if (!m_startedViaLauncher) { args.append(variantToStringList(m_app->runtimeParameters().value(qSL("arguments")))); if (!m_document.isNull()) @@ -381,8 +378,8 @@ void NativeRuntime::stop(bool forceKill) setState(Shutdown); emit aboutToStop(); - if (!m_applicationInterfaceConnected) { - //The launcher didn't connected to the RuntimeInterface yet, so we it won't get the quit signal + if (!m_connectedToRuntimeInterface) { + //The launcher didn't connected to the RuntimeInterface yet, so it won't get the quit signal m_process->terminate(); } else if (forceKill) { m_process->kill(); @@ -399,7 +396,7 @@ void NativeRuntime::stop(bool forceKill) void NativeRuntime::onProcessStarted() { - if (!m_needsLauncher && !application()->supportsApplicationInterface()) + if (!m_startedViaLauncher && !application()->supportsApplicationInterface()) setState(Active); } @@ -438,7 +435,7 @@ void NativeRuntime::onDBusPeerConnection(const QDBusConnection &connection) connect(m_applicationInterface, &NativeRuntimeApplicationInterface::applicationFinishedInitialization, this, &NativeRuntime::onApplicationFinishedInitialization); - if (m_needsLauncher && m_launchWhenReady && !m_applicationInterfaceConnected) { + if (m_startedViaLauncher) { m_runtimeInterface = new NativeRuntimeInterface(this); if (!conn.registerObject(qSL("/RuntimeInterface"), m_runtimeInterface, QDBusConnection::ExportScriptableContents)) qCWarning(LogSystem) << "ERROR: could not register the /RuntimeInterface object on the peer DBus."; @@ -457,21 +454,29 @@ void NativeRuntime::onDBusPeerConnection(const QDBusConnection &connection) void NativeRuntime::onApplicationFinishedInitialization() { - if (!m_applicationInterfaceConnected) { + m_connectedToRuntimeInterface = true; + + if (m_app) { registerExtensionInterfaces(); - if (m_needsLauncher && m_launchWhenReady && m_app && m_runtimeInterface) { + if (m_startedViaLauncher && m_runtimeInterface) + startApplicationViaLauncher(); + } +} - QString baseDir = m_container->mapHostPathToContainer(m_app->codeDir()); - QString pathInContainer = m_container->mapHostPathToContainer(m_app->absoluteCodeFilePath()); +bool NativeRuntime::startApplicationViaLauncher() +{ + if (!m_startedViaLauncher || !m_runtimeInterface || !m_app) + return false; - emit m_runtimeInterface->startApplication(baseDir, pathInContainer, m_document, m_mimeType, - convertFromJSVariant(QVariant(m_app->toVariantMap())).toMap(), - convertFromJSVariant(QVariant(systemProperties())).toMap()); - } - m_applicationInterfaceConnected = true; - } + QString baseDir = m_container->mapHostPathToContainer(m_app->codeDir()); + QString pathInContainer = m_container->mapHostPathToContainer(m_app->absoluteCodeFilePath()); + + emit m_runtimeInterface->startApplication(baseDir, pathInContainer, m_document, m_mimeType, + convertFromJSVariant(QVariant(m_app->toVariantMap())).toMap(), + convertFromJSVariant(QVariant(systemProperties())).toMap()); setState(Active); + return true; } void NativeRuntime::registerExtensionInterfaces() diff --git a/src/manager-lib/nativeruntime.h b/src/manager-lib/nativeruntime.h index c35e5df6..6438b830 100644 --- a/src/manager-lib/nativeruntime.h +++ b/src/manager-lib/nativeruntime.h @@ -117,14 +117,14 @@ private: void shutdown(int exitCode, QProcess::ExitStatus status); void registerExtensionInterfaces(); QDBusServer *applicationInterfaceServer() const; + bool startApplicationViaLauncher(); bool m_isQuickLauncher; - bool m_needsLauncher; + bool m_startedViaLauncher; QString m_document; QString m_mimeType; - bool m_launchWhenReady = false; - bool m_applicationInterfaceConnected = false; + bool m_connectedToRuntimeInterface = false; bool m_dbusConnection = false; QString m_dbusConnectionName; |