Skip to content

Commit 558ec35

Browse files
committed
fix: app hang a few seconds when launch app for the first time
修复启动器首次启动应用时,可能导致界面卡死几秒的问题. Log:
1 parent f4feb31 commit 558ec35

2 files changed

Lines changed: 34 additions & 27 deletions

File tree

src/ddeintegration/appmgr.cpp

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

191176
AppMgr::~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+
486493
void AppMgr::fetchAppItems()
487494
{
488495
qCDebug(logDdeIntegration) << "Begin to fetch apps.";

src/ddeintegration/appmgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private slots:
6464

6565
private:
6666
void fetchAppItems();
67+
void loadAppsLaunchedTimes();
6768
void watchingAppItemAdded(const QString &key, AppMgr::AppItem *appItem);
6869
void watchingAppItemRemoved(const QString &key);
6970
void watchingAppItemPropertyChanged(const QString &key, AppMgr::AppItem *appItem);
@@ -72,7 +73,6 @@ private slots:
7273

7374
private:
7475
__AppManager1ApplicationObjectManager *m_objectManager;
75-
QDBusServiceWatcher *m_serviceWatcher = nullptr;
7676
QMap<QString, AppMgr::AppItem *> m_appItems;
7777
QMap<QString, AppMgr::AppItem *> m_pendingAppItems;
7878
QTimer *m_checkTimer;

0 commit comments

Comments
 (0)