diff --git a/applets/dde-apps/amappitemmodel.cpp b/applets/dde-apps/amappitemmodel.cpp index 426ac9c13..38291a6d9 100644 --- a/applets/dde-apps/amappitemmodel.cpp +++ b/applets/dde-apps/amappitemmodel.cpp @@ -1,15 +1,15 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later #include "amappitemmodel.h" #include "amappitem.h" -#include "appgroupmanager.h" #include "appitemmodel.h" #include "objectmanager1interface.h" #include -#include +#include +#include Q_LOGGING_CATEGORY(appsLog, "org.deepin.dde.shell.dde-apps.amappitemmodel") @@ -17,7 +17,7 @@ namespace apps { AMAppItemModel::AMAppItemModel(QObject *parent) : AppItemModel(parent) - , m_manager(new ObjectManager("org.desktopspec.ApplicationManager1", "/org/desktopspec/ApplicationManager1", QDBusConnection::sessionBus())) + , m_manager(new ObjectManager("org.desktopspec.ApplicationManager1", "/org/desktopspec/ApplicationManager1", QDBusConnection::sessionBus(), this)) , m_ready(false) { qRegisterMetaType(); @@ -50,10 +50,17 @@ AMAppItemModel::AMAppItemModel(QObject *parent) removeRow(res.first().row()); }); - // load static desktop info from am - auto future = QtConcurrent::run([this]() { - auto apps = m_manager->GetManagedObjects().value(); - + // load static desktop info from am asynchronously + auto reply = m_manager->GetManagedObjects(); + auto *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, watcher]() { + watcher->deleteLater(); + QDBusPendingReply reply = *watcher; + if (reply.isError()) { + qCWarning(appsLog()) << "Failed to get managed objects:" << reply.error().message(); + return; + } + auto apps = reply.value(); for (auto app = apps.cbegin(); app != apps.cend(); app++) { auto path = app.key(); if (!path.path().isEmpty()) { @@ -61,7 +68,6 @@ AMAppItemModel::AMAppItemModel(QObject *parent) appendRow(c); } } - setProperty("ready", true); qCDebug(appsLog) << "AMAppItemModel is now ready with apps counts:" << rowCount(); }); diff --git a/applets/dde-apps/appgroupmanager.cpp b/applets/dde-apps/appgroupmanager.cpp index b5ec71b16..157fc1771 100644 --- a/applets/dde-apps/appgroupmanager.cpp +++ b/applets/dde-apps/appgroupmanager.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -240,6 +240,11 @@ QVariantList AppGroupManager::fromListOfStringList(const QList & li // On AM model changed, add newly installed apps to group (if any) and remove apps that are no longer exists. void AppGroupManager::onReferenceModelChanged() { + if (!m_referenceModel) { + qWarning() << "referenceModel has been destroyed, skip updating"; + return; + } + // Avoid remove all existing records when first time (AM model is not ready). if (m_referenceModel->rowCount() == 0) { qDebug() << "referenceModel not ready, wait for next time"; diff --git a/applets/dde-apps/appgroupmanager.h b/applets/dde-apps/appgroupmanager.h index a51745b06..a33e0977e 100644 --- a/applets/dde-apps/appgroupmanager.h +++ b/applets/dde-apps/appgroupmanager.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -82,7 +83,7 @@ class AppGroupManager : public QStandardItemModel private: bool m_appGroupInitialized; - AMAppItemModel * m_referenceModel; + QPointer m_referenceModel; QTimer* m_dumpTimer; Dtk::Core::DConfig *m_config; };