@@ -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
138191AppMgr::~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-
485486void AppMgr::fetchAppItems ()
486487{
487488 qCDebug (logDdeIntegration) << " Begin to fetch apps." ;
0 commit comments