@@ -155,37 +155,22 @@ 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 , serviceWatcher]() {
168+ qCInfo (logDdeIntegration) << " AppManager1 service registered on bus, fetching app items" ;
169+ fetchAppItems ();
170+ loadAppsLaunchedTimes ();
171+ serviceWatcher->disconnect ();
172+ });
173+ }
189174}
190175
191176AppMgr::~AppMgr ()
@@ -483,6 +468,28 @@ void AppMgr::updateAppsLaunchedTimes(const QVariantMap &appsLaunchedTimes)
483468 }
484469}
485470
471+ void AppMgr::loadAppsLaunchedTimes ()
472+ {
473+ DConfig *config = DConfig::create (" org.deepin.dde.application-manager" , " org.deepin.dde.am" , " " , this );
474+ if (!config->isValid ()) {
475+ qCWarning (logDdeIntegration) << " DConfig is invalid when getting launched times." ;
476+ } else {
477+ static const QString AppsLaunchedTimes (u8" appsLaunchedTimes" );
478+ const auto &value = config->value (AppsLaunchedTimes).toMap ();
479+ updateAppsLaunchedTimes (value);
480+ QObject::connect (config, &DConfig::valueChanged, this , [this , config](const QString &key) {
481+ if (key != AppsLaunchedTimes) {
482+ qCDebug (logDdeIntegration) << " Ignoring non-appsLaunchedTimes key:" << key;
483+ return ;
484+ }
485+
486+ qCInfo (logDdeIntegration) << " appsLaunchedTimes of DConfig changed, updating" ;
487+ const auto &value = config->value (AppsLaunchedTimes).toMap ();
488+ updateAppsLaunchedTimes (value);
489+ });
490+ }
491+ }
492+
486493void AppMgr::fetchAppItems ()
487494{
488495 qCDebug (logDdeIntegration) << " Begin to fetch apps." ;
0 commit comments