refact: method UpdateApplicationInfo change to ReloadApplications

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe 2023-09-06 12:06:34 +08:00 committed by Comix
parent d198ecebc8
commit 4d6e399653
3 changed files with 26 additions and 16 deletions

View File

@ -2,8 +2,7 @@
<node> <node>
<interface name="org.desktopspec.ApplicationManager1"> <interface name="org.desktopspec.ApplicationManager1">
<property type="ao" access="read" name="List" /> <property type="ao" access="read" name="List" />
<method name="UpdateApplicationInfo"> <method name="ReloadApplications">
<arg type="as" name="app_ids" direction="in" />
<annotation <annotation
name="org.freedesktop.DBus.Description" name="org.freedesktop.DBus.Description"
value="This method is used to update the desktop file cache when needed. value="This method is used to update the desktop file cache when needed.

View File

@ -138,7 +138,6 @@ void ApplicationManager1Service::removeInstanceFromApplication(const QString &un
void ApplicationManager1Service::scanApplications() noexcept void ApplicationManager1Service::scanApplications() noexcept
{ {
QList<DesktopFile> fileList{};
const auto &desktopFileDirs = getDesktopFileDirs(); const auto &desktopFileDirs = getDesktopFileDirs();
applyIteratively(QList<QDir>(desktopFileDirs.cbegin(), desktopFileDirs.cend()), [this](const QFileInfo &info) -> bool { applyIteratively(QList<QDir>(desktopFileDirs.cbegin(), desktopFileDirs.cend()), [this](const QFileInfo &info) -> bool {
@ -307,6 +306,7 @@ QString ApplicationManager1Service::Identify(const QDBusUnixFileDescriptor &pidf
void ApplicationManager1Service::updateApplication(const QSharedPointer<ApplicationService> &destApp, void ApplicationManager1Service::updateApplication(const QSharedPointer<ApplicationService> &destApp,
const DesktopFile &desktopFile) noexcept const DesktopFile &desktopFile) noexcept
{ {
// TODO: add propertyChanged
if (auto app = m_applicationList.find(destApp->applicationPath()); app == m_applicationList.cend()) { if (auto app = m_applicationList.find(destApp->applicationPath()); app == m_applicationList.cend()) {
return; return;
} }
@ -329,29 +329,40 @@ void ApplicationManager1Service::updateApplication(const QSharedPointer<Applicat
} }
} }
void ApplicationManager1Service::UpdateApplicationInfo(const QStringList &appIdList) void ApplicationManager1Service::ReloadApplications()
{ {
for (const auto &appId : appIdList) { const auto &desktopFileDirs = getDesktopFileDirs();
DesktopErrorCode err{DesktopErrorCode::NotFound};
auto file = DesktopFile::searchDesktopFileById(appId, err); applyIteratively(QList<QDir>(desktopFileDirs.cbegin(), desktopFileDirs.cend()), [this](const QFileInfo &info) -> bool {
auto destApp = std::find_if(m_applicationList.cbegin(), DesktopErrorCode err{DesktopErrorCode::NoError};
m_applicationList.cend(), auto ret = DesktopFile::searchDesktopFileByPath(info.absoluteFilePath(), err);
[&appId](const QSharedPointer<ApplicationService> &app) { return appId == app->id(); }); if (!ret.has_value()) {
return false;
}
auto file = std::move(ret).value();
auto destApp =
std::find_if(m_applicationList.cbegin(),
m_applicationList.cend(),
[&file](const QSharedPointer<ApplicationService> &app) { return file.desktopId() == app->id(); });
if (err == DesktopErrorCode::NotFound) { if (err == DesktopErrorCode::NotFound) {
if (destApp != m_applicationList.cend()) { if (destApp != m_applicationList.cend()) {
removeOneApplication(destApp.key()); removeOneApplication(destApp.key());
} }
continue; qWarning() << "failed to search File:" << err << "skip.";
return false;
} }
if (destApp != m_applicationList.cend()) { if (destApp != m_applicationList.cend()) {
updateApplication(destApp.value(), file.value()); updateApplication(destApp.value(), file);
continue; return false;
} }
addApplication(std::move(file).value()); addApplication(std::move(file));
} return false;
});
} }
ObjectMap ApplicationManager1Service::GetManagedObjects() const ObjectMap ApplicationManager1Service::GetManagedObjects() const

View File

@ -42,7 +42,7 @@ public:
public Q_SLOTS: public Q_SLOTS:
QString Identify(const QDBusUnixFileDescriptor &pidfd, QDBusObjectPath &application, QDBusObjectPath &application_instance); QString Identify(const QDBusUnixFileDescriptor &pidfd, QDBusObjectPath &application, QDBusObjectPath &application_instance);
void UpdateApplicationInfo(const QStringList &appIdList); void ReloadApplications();
[[nodiscard]] ObjectMap GetManagedObjects() const; [[nodiscard]] ObjectMap GetManagedObjects() const;
Q_SIGNALS: Q_SIGNALS: