refactor: dumpDBusObject
Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
e827f404ac
commit
e14d7b9540
@ -69,30 +69,31 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
|
||||
auto &dispatcher = SystemdSignalDispatcher::instance();
|
||||
|
||||
connect(&dispatcher, &SystemdSignalDispatcher::SystemdUnitNew, this, &ApplicationManager1Service::addInstanceToApplication);
|
||||
connect(&dispatcher, &SystemdSignalDispatcher::SystemdJobNew, this, [this](QString unitName, QDBusObjectPath systemdUnitPath){
|
||||
auto info = processUnitName(unitName);
|
||||
auto appId = std::move(info.applicationID);
|
||||
connect(
|
||||
&dispatcher, &SystemdSignalDispatcher::SystemdJobNew, this, [this](QString unitName, QDBusObjectPath systemdUnitPath) {
|
||||
auto info = processUnitName(unitName);
|
||||
auto appId = std::move(info.applicationID);
|
||||
|
||||
if (appId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (appId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto app = m_applicationList.value(appId);
|
||||
auto app = m_applicationList.value(appId);
|
||||
|
||||
if (!app) {
|
||||
return;
|
||||
}
|
||||
if (!app) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 服务在 AM 之后启动那么 instance size 是 0, newJob 时尝试添加一次
|
||||
// 比如 dde-file-manager.service 如果启动的比 AM 晚,那么在 scanInstances 时不会 addInstanceToApplication
|
||||
if (app->instances().size() > 0) {
|
||||
return;
|
||||
}
|
||||
// 服务在 AM 之后启动那么 instance size 是 0, newJob 时尝试添加一次
|
||||
// 比如 dde-file-manager.service 如果启动的比 AM 晚,那么在 scanInstances 时不会 addInstanceToApplication
|
||||
if (app->instances().size() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "add Instance " << unitName << "on JobNew, " << app->instances().size();
|
||||
qDebug() << "add Instance " << unitName << "on JobNew, " << app->instances().size();
|
||||
|
||||
addInstanceToApplication(unitName, systemdUnitPath);
|
||||
});
|
||||
addInstanceToApplication(unitName, systemdUnitPath);
|
||||
});
|
||||
|
||||
connect(&dispatcher,
|
||||
&SystemdSignalDispatcher::SystemdUnitRemoved,
|
||||
@ -702,9 +703,10 @@ QHash<QDBusObjectPath, QSharedPointer<ApplicationService>>
|
||||
ApplicationManager1Service::findApplicationsByIds(const QStringList &appIds) const noexcept
|
||||
{
|
||||
QHash<QDBusObjectPath, QSharedPointer<ApplicationService>> ret;
|
||||
for (const auto appId : appIds) {
|
||||
if (auto app = m_applicationList.value(appId); app)
|
||||
for (const auto &appId : appIds) {
|
||||
if (auto app = m_applicationList.value(appId); app) {
|
||||
ret.insert(QDBusObjectPath{getObjectPathFromAppId(appId)}, app);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -120,7 +120,7 @@ public:
|
||||
void removeAllInstance() noexcept;
|
||||
[[nodiscard]] const QDBusObjectPath &applicationPath() const noexcept { return m_applicationPath; }
|
||||
[[nodiscard]] DesktopFile &desktopFileSource() noexcept { return m_desktopSource; }
|
||||
[[nodiscard]] const QMap<QDBusObjectPath, QSharedPointer<InstanceService>> &applicationInstances() const noexcept
|
||||
[[nodiscard]] const QHash<QDBusObjectPath, QSharedPointer<InstanceService>> &applicationInstances() const noexcept
|
||||
{
|
||||
return m_Instances;
|
||||
}
|
||||
@ -181,7 +181,7 @@ private:
|
||||
QString m_launcher{getApplicationLauncherBinary()};
|
||||
DesktopFile m_desktopSource;
|
||||
QSharedPointer<DesktopEntry> m_entry{nullptr};
|
||||
QMap<QDBusObjectPath, QSharedPointer<InstanceService>> m_Instances;
|
||||
QHash<QDBusObjectPath, QSharedPointer<InstanceService>> m_Instances;
|
||||
void updateAfterLaunch(bool isLaunch) noexcept;
|
||||
static bool shouldBeShown(const std::unique_ptr<DesktopEntry> &entry) noexcept;
|
||||
[[nodiscard]] bool autostartCheck(const QString &filePath) const noexcept;
|
||||
|
34
src/global.h
34
src/global.h
@ -540,29 +540,21 @@ inline unitInfo processUnitName(const QString &unitName)
|
||||
return {unescapeApplicationId(applicationId), std::move(launcher), std::move(instanceId)};
|
||||
}
|
||||
|
||||
template <template<typename, typename> class Container, typename QDBusObjectPath, typename T>
|
||||
ObjectMap dumpDBusObject(const Container<QDBusObjectPath, QSharedPointer<T>> &map)
|
||||
template <typename Key, typename Value>
|
||||
ObjectMap dumpDBusObject(const QHash<Key, QSharedPointer<Value>> &map)
|
||||
{
|
||||
static_assert(std::is_base_of_v<QObject, Value>, "dumpDBusObject only support which derived by QObject class");
|
||||
ObjectMap objs;
|
||||
|
||||
for (auto it = map.constKeyValueBegin(); it != map.constKeyValueEnd(); ++it) {
|
||||
const auto &[key, value] = *it;
|
||||
for (const auto &[key, value] : map.asKeyValueRange()) {
|
||||
auto interAndProps = getChildInterfacesAndPropertiesFromObject(value.data());
|
||||
objs.insert(key, interAndProps);
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ObjectMap dumpDBusObject(const QHash<QString, QSharedPointer<T>> &map)
|
||||
{
|
||||
ObjectMap objs;
|
||||
|
||||
for (auto it = map.constKeyValueBegin(); it != map.constKeyValueEnd(); ++it) {
|
||||
const auto &[key, value] = *it;
|
||||
auto interAndProps = getChildInterfacesAndPropertiesFromObject(value.data());
|
||||
objs.insert(QDBusObjectPath{getObjectPathFromAppId(key)}, interAndProps);
|
||||
if constexpr (std::is_same_v<Key, QString>) {
|
||||
objs.insert(QDBusObjectPath{getObjectPathFromAppId(key)}, interAndProps);
|
||||
} else if constexpr (std::is_same_v<Key, QDBusObjectPath>) {
|
||||
objs.insert(key, interAndProps);
|
||||
} else {
|
||||
static_assert(false, "dumpDBusObject only support QString/QDBusObject as key type");
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
@ -665,6 +657,8 @@ inline int pidfd_open(pid_t pid, uint flags)
|
||||
return syscall(SYS_pidfd_open, pid, flags);
|
||||
}
|
||||
|
||||
#define safe_sendErrorReply if (calledFromDBus()) sendErrorReply
|
||||
#define safe_sendErrorReply \
|
||||
if (calledFromDBus()) \
|
||||
sendErrorReply
|
||||
|
||||
#endif
|
||||
|
@ -31,12 +31,13 @@ public:
|
||||
std::shared_ptr<ApplicationManager1Storage> tmp{nullptr};
|
||||
m_am = new ApplicationManager1Service{std::make_unique<CGroupsIdentifier>(), tmp};
|
||||
auto ptr = std::make_unique<QFile>(QString{"/usr/share/applications/test-Application.desktop"});
|
||||
DesktopFile file{std::move(ptr), "test-Application", 0, 0};
|
||||
const auto *appID = "test-Application";
|
||||
DesktopFile file{std::move(ptr), appID, 0, 0};
|
||||
QSharedPointer<ApplicationService> app = QSharedPointer<ApplicationService>::create(std::move(file), nullptr, tmp);
|
||||
QSharedPointer<InstanceService> instance = QSharedPointer<InstanceService>::create(
|
||||
InstancePath.path().split('/').last(), ApplicationPath.path(), QString{"/"}, QString{"DDE"});
|
||||
app->m_Instances.insert(InstancePath, instance);
|
||||
m_am->m_applicationList.insert(ApplicationPath, app);
|
||||
m_am->m_applicationList.insert(appID, app);
|
||||
new InstanceAdaptor{instance.data()};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user