feat: filter some application which shouldn't be shown

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe
2023-09-05 11:49:28 +08:00
committed by Comix
parent 4ff60db556
commit 897db2c85a
4 changed files with 143 additions and 6 deletions

View File

@ -4,6 +4,7 @@
#include "dbus/applicationservice.h"
#include "APPobjectmanager1adaptor.h"
#include "applicationchecker.h"
#include "applicationmanager1service.h"
#include "dbus/instanceadaptor.h"
#include "launchoptions.h"
@ -69,12 +70,9 @@ QSharedPointer<ApplicationService> ApplicationService::createApplicationService(
return nullptr;
}
if (auto val = entry->value(DesktopFileEntryKey, "Hidden"); val.has_value()) {
bool ok{false};
if (auto hidden = val.value().toBoolean(ok); ok and hidden) {
qWarning() << "invalid hidden value:" << *val.value().find(defaultKeyStr);
return nullptr;
}
if (!shouldBeShown(entry)) {
qDebug() << "application shouldn't be shown:" << app->desktopFileSource().sourcePath();
return nullptr;
}
app->m_entry.reset(entry.release());
@ -89,6 +87,23 @@ QSharedPointer<ApplicationService> ApplicationService::createApplicationService(
return app;
}
bool ApplicationService::shouldBeShown(const std::unique_ptr<DesktopEntry> &entry) noexcept
{
if (!ApplicationFilter::hiddenCheck(entry)) {
return true;
}
if (!ApplicationFilter::tryExecCheck(entry)) {
return true;
}
if (!ApplicationFilter::showInCheck(entry)) {
return true;
}
return false;
}
QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringList &fields, const QVariantMap &options)
{
QString execStr;

View File

@ -116,6 +116,7 @@ private:
const QString &valueKey,
EntryValueType type,
const QLocale &locale = getUserLocale()) const noexcept;
static bool shouldBeShown(const std::unique_ptr<DesktopEntry> &entry) noexcept;
};
#endif