test: add identify test
fix some bugs found in testing Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
@ -90,41 +90,6 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptr<Identifie
|
||||
});
|
||||
}
|
||||
|
||||
QPair<QString, QString> ApplicationManager1Service::processUnitName(const QString &unitName) noexcept
|
||||
{
|
||||
QString instanceId;
|
||||
QString applicationId;
|
||||
|
||||
if (unitName.endsWith(".service")) {
|
||||
auto lastDotIndex = unitName.lastIndexOf('.');
|
||||
auto app = unitName.sliced(0, lastDotIndex - 1); // remove suffix
|
||||
|
||||
if (app.contains('@')) {
|
||||
auto atIndex = app.indexOf('@');
|
||||
instanceId = app.sliced(atIndex + 1);
|
||||
app.remove(atIndex, instanceId.length() + 1);
|
||||
}
|
||||
|
||||
applicationId = app.split('-').last(); // drop launcher if it exists.
|
||||
} else if (unitName.endsWith(".scope")) {
|
||||
auto lastDotIndex = unitName.lastIndexOf('.');
|
||||
auto app = unitName.sliced(0, lastDotIndex - 1);
|
||||
|
||||
auto components = app.split('-');
|
||||
instanceId = components.takeLast();
|
||||
applicationId = components.takeLast();
|
||||
} else {
|
||||
qDebug() << "it's not service or scope:" << unitName << "ignore.";
|
||||
return {};
|
||||
}
|
||||
|
||||
if (instanceId.isEmpty()) {
|
||||
instanceId = QUuid::createUuid().toString(QUuid::Id128);
|
||||
}
|
||||
|
||||
return qMakePair(unescapeApplicationId(applicationId), std::move(instanceId));
|
||||
}
|
||||
|
||||
QList<QDBusObjectPath> ApplicationManager1Service::list() const
|
||||
{
|
||||
return m_applicationList.keys();
|
||||
|
@ -62,8 +62,6 @@ private:
|
||||
std::unique_ptr<Identifier> m_identifier;
|
||||
QScopedPointer<JobManager1Service> m_jobManager{nullptr};
|
||||
QMap<QDBusObjectPath, QSharedPointer<ApplicationService>> m_applicationList;
|
||||
|
||||
static QPair<QString, QString> processUnitName(const QString &serviceName) noexcept;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -64,7 +64,7 @@ public Q_SLOTS:
|
||||
private:
|
||||
friend class ApplicationManager1Service;
|
||||
template <typename T>
|
||||
ApplicationService(T &&source, ApplicationManager1Service *parent)
|
||||
explicit ApplicationService(T &&source, ApplicationManager1Service *parent = nullptr)
|
||||
: m_parent(parent)
|
||||
, m_desktopSource(std::forward<T>(source))
|
||||
{
|
||||
@ -84,7 +84,9 @@ private:
|
||||
m_isPersistence = true;
|
||||
sourceFile.setFileName(m_desktopSource.m_file.filePath());
|
||||
if (!sourceFile.open(QFile::ExistingOnly | QFile::ReadOnly | QFile::Text)) {
|
||||
#ifndef DEBUG_MODE
|
||||
qCritical() << "desktop file can't open:" << m_desktopSource.m_file.filePath() << sourceFile.errorString();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
sourceStream.setDevice(&sourceFile);
|
||||
|
Reference in New Issue
Block a user