Skip to content

Commit f4feb31

Browse files
committed
fix: launchpad might be blank when starting a new treeland dde session
修复treeland dde会话下,启动器应用列表可能完全空白的问题。 Log:
1 parent bfbc4d2 commit f4feb31

3 files changed

Lines changed: 65 additions & 65 deletions

File tree

src/ddeintegration/appmgr.cpp

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,60 @@ AppMgr::AppMgr(QObject *parent)
132132
{
133133
m_checkTimer->setInterval(3000); // 3 second interval
134134
connect(m_checkTimer, &QTimer::timeout, this, &AppMgr::checkPendingAppItems);
135-
initObjectManager();
135+
136+
connect(m_objectManager, &AppManager1ApplicationObjectManager::InterfacesAdded, this,
137+
[this](const QDBusObjectPath &objPath, ObjectInterfaceMap interfacesAndProperties) {
138+
const QString key(objPath.path());
139+
qCDebug(logDdeIntegration) << "InterfacesAdded by AM, path:" << key;
140+
if (m_appItems.contains(objPath.path())) {
141+
qWarning() << "App already exists for the path:" << key;
142+
return;
143+
}
144+
m_checkCount = 0;
145+
if (auto appItem = parseDBus2AppItem(interfacesAndProperties)) {
146+
qCDebug(logDdeIntegration) << "App item added, desktopId" << appItem->id;
147+
watchingAppItemAdded(key, appItem);
148+
}
149+
});
150+
connect(m_objectManager, &AppManager1ApplicationObjectManager::InterfacesRemoved, this,
151+
[this](const QDBusObjectPath &objPath, const QStringList &interfaces) {
152+
Q_UNUSED(interfaces)
153+
const QString key(objPath.path());
154+
qCDebug(logDdeIntegration) << "InterfacesRemoved by AM, path:" << key;
155+
watchingAppItemRemoved(key);
156+
});
157+
158+
DConfig *config = DConfig::create("org.deepin.dde.application-manager", "org.deepin.dde.am", "", this);
159+
if (!config->isValid()) {
160+
qCWarning(logDdeIntegration) << "DConfig is invalid when getting launched times.";
161+
} else {
162+
static const QString AppsLaunchedTimes(u8"appsLaunchedTimes");
163+
const auto &value = config->value(AppsLaunchedTimes).toMap();
164+
updateAppsLaunchedTimes(value);
165+
QObject::connect(config, &DConfig::valueChanged, this, [this, config](const QString &key) {
166+
if (key != AppsLaunchedTimes) {
167+
qCDebug(logDdeIntegration) << "Ignoring non-appsLaunchedTimes key:" << key;
168+
return;
169+
}
170+
171+
qCInfo(logDdeIntegration) << "appsLaunchedTimes of DConfig changed, updating";
172+
const auto &value = config->value(AppsLaunchedTimes).toMap();
173+
updateAppsLaunchedTimes(value);
174+
});
175+
}
176+
177+
if (isValid()) {
178+
fetchAppItems();
179+
}
180+
181+
m_serviceWatcher = new QDBusServiceWatcher(QStringLiteral("org.desktopspec.ApplicationManager1"),
182+
QDBusConnection::sessionBus(),
183+
QDBusServiceWatcher::WatchForRegistration,
184+
this);
185+
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this]() {
186+
qCInfo(logDdeIntegration) << "AppManager1 service registered on bus, fetching app items";
187+
fetchAppItems();
188+
});
136189
}
137190

138191
AppMgr::~AppMgr()
@@ -430,58 +483,6 @@ void AppMgr::updateAppsLaunchedTimes(const QVariantMap &appsLaunchedTimes)
430483
}
431484
}
432485

433-
void AppMgr::initObjectManager()
434-
{
435-
if (!isValid()) {
436-
qCWarning(logDdeIntegration) << "Object manager is not valid, aborting initialization";
437-
return;
438-
}
439-
440-
connect(m_objectManager, &AppManager1ApplicationObjectManager::InterfacesAdded, this,
441-
[this](const QDBusObjectPath &objPath, ObjectInterfaceMap interfacesAndProperties) {
442-
const QString key(objPath.path());
443-
qCDebug(logDdeIntegration) << "InterfacesAdded by AM, path:" << key;
444-
if (m_appItems.contains(objPath.path())) {
445-
qWarning() << "App already exists for the path:" << key;
446-
return;
447-
}
448-
// Reset check count when new app is added
449-
m_checkCount = 0;
450-
if (auto appItem = parseDBus2AppItem(interfacesAndProperties)) {
451-
qCDebug(logDdeIntegration) << "App item added, desktopId" << appItem->id;
452-
watchingAppItemAdded(key, appItem);
453-
}
454-
});
455-
connect(m_objectManager, &AppManager1ApplicationObjectManager::InterfacesRemoved, this,
456-
[this](const QDBusObjectPath &objPath, const QStringList &interfaces) {
457-
Q_UNUSED(interfaces)
458-
const QString key(objPath.path());
459-
qCDebug(logDdeIntegration) << "InterfacesRemoved by AM, path:" << key;
460-
watchingAppItemRemoved(key);
461-
});
462-
463-
fetchAppItems();
464-
465-
DConfig *config = DConfig::create("org.deepin.dde.application-manager", "org.deepin.dde.am", "", this);
466-
if (!config->isValid()) {
467-
qCWarning(logDdeIntegration) << "DConfig is invalid when getting launched times.";
468-
} else {
469-
static const QString AppsLaunchedTimes(u8"appsLaunchedTimes");
470-
const auto &value = config->value(AppsLaunchedTimes).toMap();
471-
updateAppsLaunchedTimes(value);
472-
QObject::connect(config, &DConfig::valueChanged, this, [this, config](const QString &key) {
473-
if (key != AppsLaunchedTimes) {
474-
qCDebug(logDdeIntegration) << "Ignoring non-appsLaunchedTimes key:" << key;
475-
return;
476-
}
477-
478-
qCInfo(logDdeIntegration) << "appsLaunchedTimes of DConfig changed, updating";
479-
const auto &value = config->value(AppsLaunchedTimes).toMap();
480-
updateAppsLaunchedTimes(value);
481-
});
482-
}
483-
}
484-
485486
void AppMgr::fetchAppItems()
486487
{
487488
qCDebug(logDdeIntegration) << "Begin to fetch apps.";

src/ddeintegration/appmgr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <QPointer>
1010
#include <QTimer>
1111
#include <QFileInfo>
12+
#include <QDBusServiceWatcher>
1213
#include <dtkcore_global.h>
1314

1415
DCORE_BEGIN_NAMESPACE
@@ -62,7 +63,6 @@ private slots:
6263
void checkPendingAppItems();
6364

6465
private:
65-
void initObjectManager();
6666
void fetchAppItems();
6767
void watchingAppItemAdded(const QString &key, AppMgr::AppItem *appItem);
6868
void watchingAppItemRemoved(const QString &key);
@@ -72,6 +72,7 @@ private slots:
7272

7373
private:
7474
__AppManager1ApplicationObjectManager *m_objectManager;
75+
QDBusServiceWatcher *m_serviceWatcher = nullptr;
7576
QMap<QString, AppMgr::AppItem *> m_appItems;
7677
QMap<QString, AppMgr::AppItem *> m_pendingAppItems;
7778
QTimer *m_checkTimer;

src/models/appsmodel.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,15 @@ AppsModel::AppsModel(QObject *parent)
7373
m_tmUpdateCache->setInterval(1000);
7474
m_tmUpdateCache->setSingleShot(true);
7575

76-
if (AppMgr::instance()->isValid()) {
77-
connect(AppMgr::instance(), &AppMgr::changed, m_tmUpdateCache, qOverload<>(&QTimer::start));
78-
connect(AppMgr::instance(), &AppMgr::itemDataChanged, this, [this](const QString &id) {
79-
const auto appItem = this->itemFromDesktopId(id);
80-
if (!appItem) {
81-
qWarning() << "Not existing item in AppsModel for the desktopId" << id;
82-
return;
83-
}
84-
updateAppItemFromAM(appItem);
85-
});
86-
}
76+
connect(AppMgr::instance(), &AppMgr::changed, m_tmUpdateCache, qOverload<>(&QTimer::start));
77+
connect(AppMgr::instance(), &AppMgr::itemDataChanged, this, [this](const QString &id) {
78+
const auto appItem = this->itemFromDesktopId(id);
79+
if (!appItem) {
80+
qWarning() << "Not existing item in AppsModel for the desktopId" << id;
81+
return;
82+
}
83+
updateAppItemFromAM(appItem);
84+
});
8785

8886
m_fwIconCache = new DFileWatcherManager(this);
8987
const QStringList paths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);

0 commit comments

Comments
 (0)