feat: watch systemd unit new and remove to sync state

add default values to XDG_DATA_DIRS if it dosen't set

Signed-off-by: ComixHe <heyuming@deepin.org>
Signed-off-by: black-desk <me@black-desk.cn>
This commit is contained in:
ComixHe
2023-08-08 15:10:32 +08:00
committed by Comix
parent 4687265e65
commit 799100436c
13 changed files with 313 additions and 52 deletions

View File

@ -0,0 +1,50 @@
// 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 serviceName, QDBusObjectPath systemdUnitPath)
{
if (!serviceName.startsWith("app-")) {
return;
}
emit SystemdUnitNew(serviceName.sliced(4), systemdUnitPath); // remove "app-"
}
void SystemdSignalDispatcher::onUnitRemoved(QString serviceName, QDBusObjectPath systemdUnitPath)
{
if (!serviceName.startsWith("app-")) {
return;
}
emit SystemdUnitRemoved(serviceName.sliced(4), systemdUnitPath);
}