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 {};
|
||||
|
35
src/global.h
35
src/global.h
@ -254,13 +254,46 @@ inline QString unescapeFromObjectPath(const QString &str)
|
||||
for (qsizetype i = 0; i < str.size(); ++i) {
|
||||
if (str[i] == '_' and i + 2 < str.size()) {
|
||||
auto hexStr = str.sliced(i + 1, 2);
|
||||
ret.replace(hexStr, QChar::fromLatin1(hexStr.toUInt(nullptr, 16)));
|
||||
ret.replace(QString{"_%1"}.arg(hexStr), QChar::fromLatin1(hexStr.toUInt(nullptr, 16)));
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline QString escapeApplicationId(const QString &id)
|
||||
{
|
||||
if (id.isEmpty()) {
|
||||
return id;
|
||||
}
|
||||
|
||||
auto ret = id;
|
||||
QRegularExpression re{R"([^a-zA-Z0-9])"};
|
||||
auto matcher = re.globalMatch(ret);
|
||||
while (matcher.hasNext()) {
|
||||
auto replaceList = matcher.next().capturedTexts();
|
||||
replaceList.removeDuplicates();
|
||||
for (const auto &c : replaceList) {
|
||||
auto hexStr = QString::number(static_cast<uint>(c.front().toLatin1()), 16);
|
||||
ret.replace(c, QString{R"(\x%1)"}.arg(hexStr));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline QString unescapeApplicationId(const QString &id)
|
||||
{
|
||||
auto ret = id;
|
||||
for (qsizetype i = 0; i < id.size(); ++i) {
|
||||
if (id[i] == '\\' and i + 3 < id.size()) {
|
||||
auto hexStr = id.sliced(i + 2, 2);
|
||||
ret.replace(QString{R"(\x%1)"}.arg(hexStr), QChar::fromLatin1(hexStr.toUInt(nullptr, 16)));
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline QString getRelativePathFromAppId(const QString &id)
|
||||
{
|
||||
QString path;
|
||||
|
Reference in New Issue
Block a user