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:
50
src/systemdsignaldispatcher.cpp
Normal file
50
src/systemdsignaldispatcher.cpp
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user