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>
<interface name="org.desktopspec.ApplicationManager1">
<property type="ao" access="read" name="List" />
<method name="UpdateApplicationInfo">
<arg type="as" name="app_ids" direction="in" />
<method name="ReloadApplications">
<annotation
name="org.freedesktop.DBus.Description"
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
{
QList<DesktopFile> fileList{};
const auto &desktopFileDirs = getDesktopFileDirs();
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,
const DesktopFile &desktopFile) noexcept
{
// TODO: add propertyChanged
if (auto app = m_applicationList.find(destApp->applicationPath()); app == m_applicationList.cend()) {
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) {
DesktopErrorCode err{DesktopErrorCode::NotFound};
auto file = DesktopFile::searchDesktopFileById(appId, err);
auto destApp = std::find_if(m_applicationList.cbegin(),
const auto &desktopFileDirs = getDesktopFileDirs();
applyIteratively(QList<QDir>(desktopFileDirs.cbegin(), desktopFileDirs.cend()), [this](const QFileInfo &info) -> bool {
DesktopErrorCode err{DesktopErrorCode::NoError};
auto ret = DesktopFile::searchDesktopFileByPath(info.absoluteFilePath(), err);
if (!ret.has_value()) {
return false;
}
auto file = std::move(ret).value();
auto destApp =
std::find_if(m_applicationList.cbegin(),
m_applicationList.cend(),
[&appId](const QSharedPointer<ApplicationService> &app) { return appId == app->id(); });
[&file](const QSharedPointer<ApplicationService> &app) { return file.desktopId() == app->id(); });
if (err == DesktopErrorCode::NotFound) {
if (destApp != m_applicationList.cend()) {
removeOneApplication(destApp.key());
}
continue;
qWarning() << "failed to search File:" << err << "skip.";
return false;
}
if (destApp != m_applicationList.cend()) {
updateApplication(destApp.value(), file.value());
continue;
updateApplication(destApp.value(), file);
return false;
}
addApplication(std::move(file).value());
}
addApplication(std::move(file));
return false;
});
}
ObjectMap ApplicationManager1Service::GetManagedObjects() const

View File

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