@@ -155,37 +155,21 @@ AppMgr::AppMgr(QObject *parent)
155155 watchingAppItemRemoved (key);
156156 });
157157
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-
177158 if (isValid ()) {
159+ qCInfo (logDdeIntegration) << " AppManager1 service already ready, fetching app items right away" ;
178160 fetchAppItems ();
179- }
180-
181- m_serviceWatcher = new QDBusServiceWatcher (QStringLiteral (" org.desktopspec.ApplicationManager1" ),
161+ loadAppsLaunchedTimes ();
162+ } else {
163+ auto serviceWatcher = new QDBusServiceWatcher (QStringLiteral (" org.desktopspec.ApplicationManager1" ),
182164 QDBusConnection::sessionBus (),
183165 QDBusServiceWatcher::WatchForRegistration,
184166 this );
185- connect (m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this , [this ]() {
186- qCInfo (logDdeIntegration) << " AppManager1 service registered on bus, fetching app items" ;
187- fetchAppItems ();
188- });
167+ connect (serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this , [this ]() {
168+ qCInfo (logDdeIntegration) << " AppManager1 service registered on bus, fetching app items" ;
169+ fetchAppItems ();
170+ loadAppsLaunchedTimes ();
171+ });
172+ }
189173}
190174
191175AppMgr::~AppMgr ()
@@ -466,21 +450,46 @@ void AppMgr::watchingAppItemPropertyChanged(const QString &key, AppMgr::AppItem
466450
467451void AppMgr::updateAppsLaunchedTimes (const QVariantMap &appsLaunchedTimes)
468452{
469- // need to update times for removed and updated.
453+ bool anyChanged = false ;
470454 const auto &appItems = m_appItems.values ();
471455 for (const auto item : std::as_const (appItems)) {
472456 auto iter = appsLaunchedTimes.find (item->appId );
473457 qint64 times = 0 ;
474458 if (iter != appsLaunchedTimes.cend ())
475459 times = iter->toLongLong ();
476460
477- // including reset and increase times.
478461 if (item->launchedTimes != times) {
479462 qCDebug (logDdeIntegration) << " LaunchedTimesChanged by DConfig, desktopId" << item->id << " from" << item->launchedTimes << " to" << times;
480463 item->launchedTimes = times;
481- Q_EMIT itemDataChanged (item-> id ) ;
464+ anyChanged = true ;
482465 }
483466 }
467+
468+ if (anyChanged) {
469+ Q_EMIT changed ();
470+ }
471+ }
472+
473+ void AppMgr::loadAppsLaunchedTimes ()
474+ {
475+ DConfig *config = DConfig::create (" org.deepin.dde.application-manager" , " org.deepin.dde.am" , " " , this );
476+ if (!config->isValid ()) {
477+ qCWarning (logDdeIntegration) << " DConfig is invalid when getting launched times." ;
478+ } else {
479+ static const QString AppsLaunchedTimes (u8" appsLaunchedTimes" );
480+ const auto &value = config->value (AppsLaunchedTimes).toMap ();
481+ updateAppsLaunchedTimes (value);
482+ QObject::connect (config, &DConfig::valueChanged, this , [this , config](const QString &key) {
483+ if (key != AppsLaunchedTimes) {
484+ qCDebug (logDdeIntegration) << " Ignoring non-appsLaunchedTimes key:" << key;
485+ return ;
486+ }
487+
488+ qCInfo (logDdeIntegration) << " appsLaunchedTimes of DConfig changed, updating" ;
489+ const auto &value = config->value (AppsLaunchedTimes).toMap ();
490+ updateAppsLaunchedTimes (value);
491+ });
492+ }
484493}
485494
486495void AppMgr::fetchAppItems ()
0 commit comments