diff --git a/src/dbus/applicationmanager1service.cpp b/src/dbus/applicationmanager1service.cpp index 5951ae4..7c1bb83 100644 --- a/src/dbus/applicationmanager1service.cpp +++ b/src/dbus/applicationmanager1service.cpp @@ -187,10 +187,6 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce void ApplicationManager1Service::addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath) { - if (!isApplication(systemdUnitPath)) { - return; - } - auto info = processUnitName(unitName); auto appId = std::move(info.applicationID); auto launcher = std::move(info.Launcher); @@ -199,6 +195,9 @@ void ApplicationManager1Service::addInstanceToApplication(const QString &unitNam if (appId.isEmpty()) { return; } + if (instanceId.isEmpty()) { + instanceId = QUuid::createUuid().toString(QUuid::Id128); + } auto appIt = std::find_if(m_applicationList.cbegin(), m_applicationList.cend(), @@ -220,10 +219,6 @@ void ApplicationManager1Service::addInstanceToApplication(const QString &unitNam void ApplicationManager1Service::removeInstanceFromApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath) { - if (!isApplication(systemdUnitPath)) { - return; - } - auto info = processUnitName(unitName); auto appId = std::move(info.applicationID); auto launcher = std::move(info.Launcher); @@ -316,9 +311,6 @@ void ApplicationManager1Service::scanInstances() noexcept QList units; v.value() >> units; for (const auto &unit : units) { - if (!isApplication(unit.objectPath)) { - continue; - } if (unit.subState == "running") { this->addInstanceToApplication(unit.name, unit.objectPath); } @@ -567,10 +559,16 @@ QString ApplicationManager1Service::Identify(const QDBusUnixFileDescriptor &pidf return {}; } - auto instancePath = (*app)->findInstance(ret.InstanceId); - - if (auto path = instancePath.path(); path.isEmpty()) { - sendErrorReply(QDBusError::Failed, "can't find instance:" % path); + QDBusObjectPath instancePath; + const auto &instances = (*app)->instances(); + if (ret.InstanceId.isEmpty() && instances.size() == 1) { + // Maybe a dbus systemd service + instancePath = instances.constFirst(); + } else { + instancePath = (*app)->findInstance(ret.InstanceId); + } + if (instancePath.path().isEmpty()) { + sendErrorReply(QDBusError::Failed, "can't find instance:" % ret.InstanceId); return {}; } diff --git a/src/global.h b/src/global.h index 0937041..0b86caa 100644 --- a/src/global.h +++ b/src/global.h @@ -481,11 +481,6 @@ inline QString getCurrentDesktop() return desktops.first(); } -inline bool isApplication(const QDBusObjectPath &path) -{ - return path.path().split('/').last().startsWith("app"); -} - struct unitInfo { QString applicationID; @@ -503,8 +498,10 @@ inline unitInfo processUnitName(const QString &unitName) decltype(auto) appPrefix = u8"app-"; if (!unitName.startsWith(appPrefix)) { - qDebug() << "this unit " << unitName << "isn't an app unit."; - return {}; + // If not started by application manager, just remove suffix and take name as app id. + auto lastDotIndex = unitName.lastIndexOf('.'); + applicationId = unitName.sliced(0, lastDotIndex); + return {unescapeApplicationId(applicationId), std::move(launcher), std::move(instanceId)}; } auto unit = unitName.sliced(sizeof(appPrefix) - 1); @@ -540,10 +537,6 @@ inline unitInfo processUnitName(const QString &unitName) return {}; } - if (instanceId.isEmpty()) { - instanceId = QUuid::createUuid().toString(QUuid::Id128); - } - return {unescapeApplicationId(applicationId), std::move(launcher), std::move(instanceId)}; } diff --git a/src/systemdsignaldispatcher.cpp b/src/systemdsignaldispatcher.cpp index df729c8..d3c36d0 100644 --- a/src/systemdsignaldispatcher.cpp +++ b/src/systemdsignaldispatcher.cpp @@ -54,18 +54,10 @@ void SystemdSignalDispatcher::onPropertiesChanged(QString interface, QVariantMap void SystemdSignalDispatcher::onUnitNew(QString unitName, QDBusObjectPath systemdUnitPath) { - if (!unitName.startsWith("app-")) { - return; - } - emit SystemdUnitNew(unitName, systemdUnitPath); } void SystemdSignalDispatcher::onUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath) { - if (!unitName.startsWith("app-")) { - return; - } - emit SystemdUnitRemoved(unitName, systemdUnitPath); }