Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 33 additions & 26 deletions src/ddeintegration/appmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,37 +155,22 @@ AppMgr::AppMgr(QObject *parent)
watchingAppItemRemoved(key);
});

DConfig *config = DConfig::create("org.deepin.dde.application-manager", "org.deepin.dde.am", "", this);
if (!config->isValid()) {
qCWarning(logDdeIntegration) << "DConfig is invalid when getting launched times.";
} else {
static const QString AppsLaunchedTimes(u8"appsLaunchedTimes");
const auto &value = config->value(AppsLaunchedTimes).toMap();
updateAppsLaunchedTimes(value);
QObject::connect(config, &DConfig::valueChanged, this, [this, config](const QString &key) {
if (key != AppsLaunchedTimes) {
qCDebug(logDdeIntegration) << "Ignoring non-appsLaunchedTimes key:" << key;
return;
}

qCInfo(logDdeIntegration) << "appsLaunchedTimes of DConfig changed, updating";
const auto &value = config->value(AppsLaunchedTimes).toMap();
updateAppsLaunchedTimes(value);
});
}

if (isValid()) {
qCInfo(logDdeIntegration) << "AppManager1 service already ready, fetching app items right away";
fetchAppItems();
}

m_serviceWatcher = new QDBusServiceWatcher(QStringLiteral("org.desktopspec.ApplicationManager1"),
loadAppsLaunchedTimes();
} else {
auto serviceWatcher = new QDBusServiceWatcher(QStringLiteral("org.desktopspec.ApplicationManager1"),
QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForRegistration,
this);
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this]() {
qCInfo(logDdeIntegration) << "AppManager1 service registered on bus, fetching app items";
fetchAppItems();
});
connect(serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this, serviceWatcher]() {
qCInfo(logDdeIntegration) << "AppManager1 service registered on bus, fetching app items";
fetchAppItems();
loadAppsLaunchedTimes();
serviceWatcher->disconnect();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是可以直接deleteLater它呀,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有道理...合早了 😂

});
}
}

AppMgr::~AppMgr()
Expand Down Expand Up @@ -483,6 +468,28 @@ void AppMgr::updateAppsLaunchedTimes(const QVariantMap &appsLaunchedTimes)
}
}

void AppMgr::loadAppsLaunchedTimes()
{
DConfig *config = DConfig::create("org.deepin.dde.application-manager", "org.deepin.dde.am", "", this);
if (!config->isValid()) {
qCWarning(logDdeIntegration) << "DConfig is invalid when getting launched times.";
} else {
static const QString AppsLaunchedTimes(u8"appsLaunchedTimes");
const auto &value = config->value(AppsLaunchedTimes).toMap();
updateAppsLaunchedTimes(value);
QObject::connect(config, &DConfig::valueChanged, this, [this, config](const QString &key) {
if (key != AppsLaunchedTimes) {
qCDebug(logDdeIntegration) << "Ignoring non-appsLaunchedTimes key:" << key;
return;
}

qCInfo(logDdeIntegration) << "appsLaunchedTimes of DConfig changed, updating";
const auto &value = config->value(AppsLaunchedTimes).toMap();
updateAppsLaunchedTimes(value);
});
}
}

void AppMgr::fetchAppItems()
{
qCDebug(logDdeIntegration) << "Begin to fetch apps.";
Expand Down
2 changes: 1 addition & 1 deletion src/ddeintegration/appmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private slots:

private:
void fetchAppItems();
void loadAppsLaunchedTimes();
void watchingAppItemAdded(const QString &key, AppMgr::AppItem *appItem);
void watchingAppItemRemoved(const QString &key);
void watchingAppItemPropertyChanged(const QString &key, AppMgr::AppItem *appItem);
Expand All @@ -72,7 +73,6 @@ private slots:

private:
__AppManager1ApplicationObjectManager *m_objectManager;
QDBusServiceWatcher *m_serviceWatcher = nullptr;
QMap<QString, AppMgr::AppItem *> m_appItems;
QMap<QString, AppMgr::AppItem *> m_pendingAppItems;
QTimer *m_checkTimer;
Expand Down
Loading