example: add launch application example
fix some bug while testing the example Signed-off-by: ComixHe <heyuming@deepin.org> Signed-off-by: black-desk <me@black-desk.cn>
This commit is contained in:
@ -16,9 +16,9 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptr<Identifie
|
||||
qFatal() << connection.lastError();
|
||||
}
|
||||
|
||||
if (!registerObjectToDBus(new ApplicationManager1Adaptor{this},
|
||||
DDEApplicationManager1ObjectPath,
|
||||
getDBusInterface<ApplicationManager1Adaptor>())) {
|
||||
new ApplicationManager1Adaptor{this};
|
||||
|
||||
if (!registerObjectToDBus(this, DDEApplicationManager1ObjectPath, getDBusInterface<ApplicationManager1Adaptor>())) {
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ QPair<QString, QString> ApplicationManager1Service::processServiceName(const QSt
|
||||
instanceId = components.takeLast();
|
||||
applicationId = components.takeLast();
|
||||
} else {
|
||||
qDebug() << "it's not service or slice or scope.";
|
||||
qDebug() << "it's not service or scope:" << serviceName << "ignore.";
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ QPair<QString, QString> ApplicationManager1Service::processServiceName(const QSt
|
||||
instanceId = QUuid::createUuid().toString(QUuid::Id128);
|
||||
}
|
||||
|
||||
return qMakePair(std::move(applicationId), std::move(instanceId));
|
||||
return qMakePair(unescapeApplicationId(applicationId), std::move(instanceId));
|
||||
}
|
||||
|
||||
QList<QDBusObjectPath> ApplicationManager1Service::list() const
|
||||
|
@ -37,9 +37,9 @@ public:
|
||||
if (!application) {
|
||||
return false;
|
||||
}
|
||||
if (!registerObjectToDBus(new ApplicationAdaptor{application.data()},
|
||||
application->m_applicationPath.path(),
|
||||
getDBusInterface<ApplicationAdaptor>())) {
|
||||
auto *ptr = application.data();
|
||||
new ApplicationAdaptor{ptr};
|
||||
if (!registerObjectToDBus(ptr, application->m_applicationPath.path(), getDBusInterface<ApplicationAdaptor>())) {
|
||||
return false;
|
||||
}
|
||||
m_applicationList.insert(application->m_applicationPath, application);
|
||||
|
@ -145,7 +145,7 @@ QDBusObjectPath ApplicationService::Launch(QString action, QStringList fields, Q
|
||||
if (resourceFile.isEmpty()) {
|
||||
auto instanceRandomUUID = QUuid::createUuid().toString(QUuid::Id128);
|
||||
commands.push_front(QString{R"(--unitName=app-DDE-%1@%2.service)"}.arg(
|
||||
this->id(), instanceRandomUUID)); // launcher should use this instanceId
|
||||
escapeApplicationId(this->id()), instanceRandomUUID)); // launcher should use this instanceId
|
||||
QProcess process;
|
||||
process.start(m_launcher, commands);
|
||||
process.waitForFinished();
|
||||
@ -255,7 +255,7 @@ bool ApplicationService::addOneInstance(const QString &instanceId, const QString
|
||||
auto adaptor = new InstanceAdaptor(service);
|
||||
QString objectPath{DDEApplicationManager1InstanceObjectPath + instanceId};
|
||||
|
||||
if (registerObjectToDBus(adaptor, objectPath, getDBusInterface<InstanceAdaptor>())) {
|
||||
if (registerObjectToDBus(service, objectPath, getDBusInterface<InstanceAdaptor>())) {
|
||||
m_Instances.insert(QDBusObjectPath{objectPath}, QSharedPointer<InstanceService>{service});
|
||||
service->moveToThread(this->thread());
|
||||
adaptor->moveToThread(this->thread());
|
||||
|
@ -5,18 +5,14 @@
|
||||
#include "dbus/jobmanager1service.h"
|
||||
#include "dbus/jobmanager1adaptor.h"
|
||||
|
||||
LaunchTask::LaunchTask()
|
||||
{
|
||||
qRegisterMetaType<LaunchTask>();
|
||||
}
|
||||
|
||||
JobManager1Service::JobManager1Service(ApplicationManager1Service *parent)
|
||||
: m_parent(parent)
|
||||
{
|
||||
if (!registerObjectToDBus(
|
||||
new JobManager1Adaptor{this}, DDEApplicationManager1JobManagerObjectPath, getDBusInterface<JobManager1Adaptor>())) {
|
||||
new JobManager1Adaptor{this};
|
||||
if (!registerObjectToDBus(this, DDEApplicationManager1JobManagerObjectPath, getDBusInterface<JobManager1Adaptor>())) {
|
||||
std::terminate();
|
||||
}
|
||||
qRegisterMetaType<LaunchTask>();
|
||||
}
|
||||
|
||||
JobManager1Service::~JobManager1Service() = default;
|
||||
|
@ -22,7 +22,7 @@ class ApplicationManager1Service;
|
||||
|
||||
struct LaunchTask
|
||||
{
|
||||
LaunchTask();
|
||||
LaunchTask() = default;
|
||||
~LaunchTask() = default;
|
||||
LaunchTask(const LaunchTask &) = default;
|
||||
LaunchTask(LaunchTask &&) = default;
|
||||
@ -57,7 +57,10 @@ public:
|
||||
QVariantList{},
|
||||
QtConcurrent::ReduceOption::OrderedReduce);
|
||||
QSharedPointer<JobService> job{new JobService{future}};
|
||||
if (!registerObjectToDBus(new JobAdaptor(job.data()), objectPath, getDBusInterface<JobAdaptor>())) {
|
||||
|
||||
auto *ptr = job.data();
|
||||
new JobAdaptor(ptr);
|
||||
if (!registerObjectToDBus(ptr, objectPath, getDBusInterface<JobAdaptor>())) {
|
||||
qCritical() << "can't register job to dbus.";
|
||||
future.cancel();
|
||||
return {};
|
||||
|
Reference in New Issue
Block a user