refact: restructure project
1. adjust project structure; 2. use config.h to locate app-launch-helper binary.
This commit is contained in:
@ -1,31 +1,21 @@
|
||||
add_subdirectory(dbus)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(BIN_NAME dde-application-manager)
|
||||
set(LIB_NAME ddeam)
|
||||
configure_file(config.h.in config.h)
|
||||
|
||||
file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
|
||||
set(LIB_NAME dde_am_static)
|
||||
|
||||
list(REMOVE_ITEM SRCS "${PROJECT_SOURCE_DIR}/src/utils.cpp")
|
||||
file(GLOB SRCS ${CMAKE_CURRENT_LIST_DIR}/*.cpp ${CMAKE_CURRENT_LIST_DIR}/*.h)
|
||||
|
||||
add_library(${LIB_NAME} ${SRCS})
|
||||
|
||||
target_include_directories(${LIB_NAME} PRIVATE
|
||||
${PROJECT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(${LIB_NAME} PUBLIC
|
||||
Threads::Threads
|
||||
${AdaptorLib}
|
||||
dde_am_dbus
|
||||
)
|
||||
|
||||
add_executable(${BIN_NAME} main.cpp utils.cpp)
|
||||
|
||||
target_link_libraries(${BIN_NAME} PRIVATE
|
||||
${LIB_NAME}
|
||||
)
|
||||
|
||||
target_include_directories(${BIN_NAME} PRIVATE
|
||||
${PROJECT_BINARY_DIR}
|
||||
)
|
||||
|
||||
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
11
src/config.h.in
Normal file
11
src/config.h.in
Normal file
@ -0,0 +1,11 @@
|
||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
constexpr auto ApplicationLaunchHelperBinary =
|
||||
u8"@CMAKE_INSTALL_FULL_LIBEXECDIR@/deepin/application-manager/@APP_LAUNCH_HELPER_BIN@";
|
||||
|
||||
#endif
|
31
src/dbus/CMakeLists.txt
Normal file
31
src/dbus/CMakeLists.txt
Normal file
@ -0,0 +1,31 @@
|
||||
add_library(dde_am_dbus OBJECT)
|
||||
|
||||
file(
|
||||
GLOB_RECURSE dde_am_dbus_SOURCE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.h
|
||||
)
|
||||
|
||||
qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.desktopspec.ApplicationManager1.xml dbus/applicationmanager1service.h ApplicationManager1Service)
|
||||
qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.desktopspec.ApplicationManager1.Application.xml dbus/applicationservice.h ApplicationService)
|
||||
qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.desktopspec.ApplicationManager1.Instance.xml dbus/instanceservice.h InstanceService)
|
||||
qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.desktopspec.JobManager1.xml dbus/jobmanager1service.h JobManager1Service)
|
||||
qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.desktopspec.JobManager1.Job.xml dbus/jobservice.h JobService)
|
||||
|
||||
|
||||
target_sources(dde_am_dbus PRIVATE
|
||||
${dde_am_dbus_SOURCE}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
dde_am_dbus PUBLIC
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::DBus
|
||||
Qt${QT_VERSION_MAJOR}::Concurrent
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
dde_am_dbus PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
${CMAKE_CURRENT_BINARY_DIR}/..
|
||||
)
|
@ -1,8 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
#include "applicationmanager1service.h"
|
||||
#include "applicationmanager1adaptor.h"
|
||||
#include "dbus/applicationmanager1service.h"
|
||||
#include "dbus/applicationmanager1adaptor.h"
|
||||
#include <QFile>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -12,9 +12,9 @@
|
||||
#include <QScopedPointer>
|
||||
#include <memory>
|
||||
#include <QMap>
|
||||
#include "jobmanager1service.h"
|
||||
#include "applicationservice.h"
|
||||
#include "applicationadaptor.h"
|
||||
#include "dbus/jobmanager1service.h"
|
||||
#include "dbus/applicationservice.h"
|
||||
#include "dbus/applicationadaptor.h"
|
||||
#include "identifier.h"
|
||||
|
||||
class ApplicationManager1Service final : public QObject
|
||||
|
@ -2,9 +2,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "applicationservice.h"
|
||||
#include "dbus/applicationservice.h"
|
||||
#include "applicationmanager1service.h"
|
||||
#include "instanceadaptor.h"
|
||||
#include "dbus/instanceadaptor.h"
|
||||
#include "pwd.h"
|
||||
#include <QUuid>
|
||||
#include <QStringList>
|
||||
@ -162,7 +162,7 @@ QDBusObjectPath ApplicationService::Launch(QString action, QStringList fields, Q
|
||||
auto instanceRandomUUID = QUuid::createUuid().toString(QUuid::Id128);
|
||||
tmp.push_front(QString{R"(--unitName=DDE-%1@%2.service)"}.arg(this->id(), instanceRandomUUID));
|
||||
QProcess process;
|
||||
process.start(ApplicationLauncherBinary, tmp);
|
||||
process.start(getApplicationLauncherBinary(), tmp);
|
||||
process.waitForFinished();
|
||||
auto exitCode = process.exitCode();
|
||||
if (exitCode != 0) {
|
||||
@ -318,6 +318,10 @@ LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringLis
|
||||
}
|
||||
case 'u': {
|
||||
execList.removeAt(location);
|
||||
if (fields.empty()) {
|
||||
task.command.append(execList);
|
||||
break;
|
||||
}
|
||||
if (fields.count() > 1) {
|
||||
qDebug() << R"(fields count is greater than one, %u will only take first element.)";
|
||||
}
|
||||
|
@ -14,11 +14,11 @@
|
||||
#include <QUuid>
|
||||
#include <QTextStream>
|
||||
#include <QFile>
|
||||
#include "instanceservice.h"
|
||||
#include "dbus/instanceservice.h"
|
||||
#include "global.h"
|
||||
#include "desktopentry.h"
|
||||
#include "desktopicons.h"
|
||||
#include "jobmanager1service.h"
|
||||
#include "dbus/jobmanager1service.h"
|
||||
|
||||
class ApplicationService : public QObject
|
||||
{
|
||||
@ -102,7 +102,7 @@ private:
|
||||
bool m_isPersistence;
|
||||
ApplicationManager1Service *m_parent{nullptr};
|
||||
QDBusObjectPath m_applicationPath;
|
||||
QString m_launcher{ApplicationLauncherBinary};
|
||||
QString m_launcher{getApplicationLauncherBinary()};
|
||||
union DesktopSource
|
||||
{
|
||||
template <typename T, std::enable_if_t<std::is_same_v<T, DesktopFile>, bool> = true>
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "instanceservice.h"
|
||||
#include "dbus/instanceservice.h"
|
||||
|
||||
InstanceService::InstanceService(QString instanceId, QString application, QString systemdUnitPath)
|
||||
: m_instanceId(std::move(instanceId))
|
||||
|
@ -2,8 +2,8 @@
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "jobmanager1service.h"
|
||||
#include "jobmanager1adaptor.h"
|
||||
#include "dbus/jobmanager1service.h"
|
||||
#include "dbus/jobmanager1adaptor.h"
|
||||
|
||||
LaunchTask::LaunchTask()
|
||||
{
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <QFuture>
|
||||
#include <QUuid>
|
||||
#include "global.h"
|
||||
#include "jobadaptor.h"
|
||||
#include "dbus/jobadaptor.h"
|
||||
|
||||
class ApplicationManager1Service;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "jobservice.h"
|
||||
#include "dbus/jobservice.h"
|
||||
|
||||
JobService::JobService(const QFuture<QVariantList> &job)
|
||||
: m_job(job)
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <unistd.h>
|
||||
#include <optional>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
using IconMap = QMap<QString, QMap<uint, QMap<QString, QDBusUnixFileDescriptor>>>;
|
||||
|
||||
constexpr auto DDEApplicationManager1ServiceName = u8"org.deepin.dde.ApplicationManager1";
|
||||
@ -29,8 +31,16 @@ constexpr auto DDEApplicationManager1JobManagerObjectPath = u8"/org/deepin/dde/A
|
||||
constexpr auto DDEApplicationManager1JobObjectPath = u8"/org/deepin/dde/ApplicationManager1/JobManager1/Job/";
|
||||
constexpr auto DesktopFileEntryKey = u8"Desktop Entry";
|
||||
constexpr auto DesktopFileActionKey = u8"Desktop Action ";
|
||||
constexpr auto ApplicationLauncherBinary =
|
||||
u8"/home/heyuming/workspace/dde-application-manager/build/plugin/appLauncher/am-launcher";
|
||||
inline QString getApplicationLauncherBinary()
|
||||
{
|
||||
auto value = qgetenv("DEEPIN_APPLICATION_MANAGER_APP_LAUNCH_HELPER_BIN");
|
||||
if (value.isEmpty()) {
|
||||
return ApplicationLaunchHelperBinary;
|
||||
} else {
|
||||
qWarning() << "Using app launch helper defined in environment variable DEEPIN_APPLICATION_MANAGER_APP_LAUNCH_HELPER_BIN.";
|
||||
return value;
|
||||
}
|
||||
}
|
||||
constexpr auto ApplicationManagerDBusName = u8"deepin_application_manager_bus";
|
||||
|
||||
enum class DBusType { Session = QDBusConnection::SessionBus, System = QDBusConnection::SystemBus, Custom };
|
59
src/main.cpp
59
src/main.cpp
@ -1,59 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "global.h"
|
||||
#include <QDBusConnection>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include "applicationmanager1service.h"
|
||||
#include "cgroupsidentifier.h"
|
||||
#include "global.h"
|
||||
|
||||
static void registerComplexDbusType()
|
||||
{
|
||||
qDBusRegisterMetaType<QMap<QString, QDBusUnixFileDescriptor>>();
|
||||
qDBusRegisterMetaType<QMap<uint, QMap<QString, QDBusUnixFileDescriptor>>>();
|
||||
qDBusRegisterMetaType<IconMap>();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app{argc, argv};
|
||||
auto &bus = ApplicationManager1DBus::instance();
|
||||
bus.init(DBusType::Session);
|
||||
auto &AMBus = bus.globalBus();
|
||||
|
||||
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.";
|
||||
}
|
||||
auto desktopFileDirs = pathEnv.split(':');
|
||||
|
||||
for (const auto &dir : desktopFileDirs) {
|
||||
auto dirPath = QDir{QDir::cleanPath(dir) + "/applications"};
|
||||
if (!dirPath.exists()) {
|
||||
continue;
|
||||
}
|
||||
QDirIterator it{dirPath.absolutePath(),
|
||||
{"*.desktop"},
|
||||
QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::Readable,
|
||||
QDirIterator::Subdirectories};
|
||||
while (it.hasNext()) {
|
||||
auto file = it.next();
|
||||
ParseError err;
|
||||
auto ret = DesktopFile::searchDesktopFile(file, err);
|
||||
if (!ret.has_value()) {
|
||||
continue;
|
||||
}
|
||||
if (!AMService.addApplication(std::move(ret).value())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "global.h"
|
||||
|
||||
bool registerObjectToDBus(QObject *o, const QString &path, const QString &interface)
|
||||
{
|
||||
auto &con = ApplicationManager1DBus::instance().globalBus();
|
||||
if (!con.registerObject(path, interface, o, QDBusConnection::RegisterOption::ExportAllContents)) {
|
||||
qFatal() << "register object failed:" << path << interface << con.lastError();
|
||||
} else {
|
||||
qInfo() << "register object:" << path << interface;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void unregisterObjectFromDBus(const QString &path)
|
||||
{
|
||||
auto &con = ApplicationManager1DBus::instance().globalBus();
|
||||
con.unregisterObject(path);
|
||||
}
|
Reference in New Issue
Block a user