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

@ -6,5 +6,9 @@ target_link_libraries(${APP_LAUNCH_HELPER_BIN} PRIVATE
PkgConfig::SYSTEMD
)
target_include_directories(${APP_LAUNCH_HELPER_BIN} PRIVATE
${PROJECT_SOURCE_DIR}/src
)
include(GNUInstallDirs)
install(TARGETS ${APP_LAUNCH_HELPER_BIN} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/deepin/application-manager/)

View File

@ -15,6 +15,7 @@
#include <cstdlib>
#include <map>
#include <thread>
#include "constant.h"
enum class ExitCode { SystemdError = -3, InvalidInput = -2, InternalError = -1, Done = 0, Waiting = 1 };
@ -25,10 +26,6 @@ struct JobRemoveResult
ExitCode result{ExitCode::Waiting};
};
constexpr static auto SystemdService = "org.freedesktop.systemd1";
constexpr static auto SystemdObjectPath = "/org/freedesktop/systemd1";
constexpr static auto SystemdInterfaceName = "org.freedesktop.systemd1.Manager";
using msg_ptr = sd_bus_message *;
using bus_ptr = sd_bus *;

View File

@ -21,17 +21,19 @@ int main(int argc, char *argv[])
{
QCoreApplication app{argc, argv};
auto &bus = ApplicationManager1DBus::instance();
bus.init(DBusType::Session);
auto &AMBus = bus.globalBus();
bus.initGlobalServerBus(DBusType::Session);
bus.setDestBus("");
auto &AMBus = bus.globalServerBus();
registerComplexDbusType();
ApplicationManager1Service AMService{std::make_unique<CGroupsIdentifier>(), AMBus};
QList<DesktopFile> fileList{};
auto pathEnv = qgetenv("XDG_DATA_DIRS");
if (pathEnv.isEmpty()) {
qFatal() << "environment variable $XDG_DATA_DIRS is empty.";
QByteArray XDGDataDirs;
XDGDataDirs = qgetenv("XDG_DATA_DIRS");
if (XDGDataDirs.isEmpty()) {
XDGDataDirs.append("/usr/local/share/:/usr/share/");
}
auto desktopFileDirs = pathEnv.split(':');
auto desktopFileDirs = XDGDataDirs.split(':');
for (const auto &dir : desktopFileDirs) {
auto dirPath = QDir{QDir::cleanPath(dir) + "/applications"};

View File

@ -6,7 +6,7 @@
bool registerObjectToDBus(QObject *o, const QString &path, const QString &interface)
{
auto &con = ApplicationManager1DBus::instance().globalBus();
auto &con = ApplicationManager1DBus::instance().globalServerBus();
if (!con.registerObject(path, interface, o, QDBusConnection::RegisterOption::ExportAllContents)) {
qFatal() << "register object failed:" << path << interface << con.lastError();
} else {
@ -17,6 +17,7 @@ bool registerObjectToDBus(QObject *o, const QString &path, const QString &interf
void unregisterObjectFromDBus(const QString &path)
{
auto &con = ApplicationManager1DBus::instance().globalBus();
auto &con = ApplicationManager1DBus::instance().globalServerBus();
con.unregisterObject(path);
qInfo() << "unregister object:" << path;
}