dde-application-manager/src/systemdsignaldispatcher.cpp
ComixHe bc7fbfb3a1 feat: add property Launcher, Orphaned
refactor some method which are related with systemd unit

Signed-off-by: ComixHe <heyuming@deepin.org>
2023-09-14 17:41:16 +08:00

51 lines
1.4 KiB
C++

// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "systemdsignaldispatcher.h"
bool SystemdSignalDispatcher::connectToSignals() noexcept
{
auto &con = ApplicationManager1DBus::instance().globalDestBus();
if (!con.connect(SystemdService,
SystemdObjectPath,
SystemdInterfaceName,
"UnitNew",
this,
SLOT(onUnitNew(QString, QDBusObjectPath)))) {
qCritical() << "can't connect to UnitNew signal of systemd service.";
return false;
}
if (!con.connect(SystemdService,
SystemdObjectPath,
SystemdInterfaceName,
"UnitRemoved",
this,
SLOT(onUnitRemoved(QString, QDBusObjectPath)))) {
qCritical() << "can't connect to UnitRemoved signal of systemd service.";
return false;
}
return true;
}
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);
}