@@ -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 ()
@@ -483,6 +467,28 @@ void AppMgr::updateAppsLaunchedTimes(const QVariantMap &appsLaunchedTimes)
483467 }
484468}
485469
470+ void AppMgr::loadAppsLaunchedTimes ()
471+ {
472+ DConfig *config = DConfig::create (" org.deepin.dde.application-manager" , " org.deepin.dde.am" , " " , this );
473+ if (!config->isValid ()) {
474+ qCWarning (logDdeIntegration) << " DConfig is invalid when getting launched times." ;
475+ } else {
476+ static const QString AppsLaunchedTimes (u8" appsLaunchedTimes" );
477+ const auto &value = config->value (AppsLaunchedTimes).toMap ();
478+ updateAppsLaunchedTimes (value);
479+ QObject::connect (config, &DConfig::valueChanged, this , [this , config](const QString &key) {
480+ if (key != AppsLaunchedTimes) {
481+ qCDebug (logDdeIntegration) << " Ignoring non-appsLaunchedTimes key:" << key;
482+ return ;
483+ }
484+
485+ qCInfo (logDdeIntegration) << " appsLaunchedTimes of DConfig changed, updating" ;
486+ const auto &value = config->value (AppsLaunchedTimes).toMap ();
487+ updateAppsLaunchedTimes (value);
488+ });
489+ }
490+ }
491+
486492void AppMgr::fetchAppItems ()
487493{
488494 qCDebug (logDdeIntegration) << " Begin to fetch apps." ;
0 commit comments