From c3c5479f7390a0741ae15378ccbd8d03d3888e17 Mon Sep 17 00:00:00 2001
From: Capsia <cmsuser3754@zoho.eu>
Date: Sun, 17 Aug 2025 15:33:46 +0200
Subject: [PATCH 2/7] Respects NoDisplay=true in desktop files

Checks the 'NoDisplay=true' key in desktop files using Gio, and does not emit the 'appAdded' event if the app should be hidden.

Signed-off-by: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
---
 CMakeLists.txt                         |  2 +-
 plugins/Lomiri/Launcher/CMakeLists.txt |  2 ++
 plugins/Lomiri/Launcher/xdgwatcher.cpp | 17 ++++++++++++++++-
 plugins/Lomiri/Launcher/xdgwatcher.h   |  1 +
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 29e041c31..bb36dc690 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -91,7 +91,7 @@ find_package(Intl REQUIRED)
 
 pkg_check_modules(APPLICATION_API REQUIRED lomiri-shell-application=28)
 pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
-pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
+pkg_check_modules(GIO REQUIRED gio-2.0>=2.32 gio-unix-2.0)
 pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
 pkg_check_modules(LAUNCHER_API REQUIRED lomiri-shell-launcher=13)
 pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
diff --git a/plugins/Lomiri/Launcher/CMakeLists.txt b/plugins/Lomiri/Launcher/CMakeLists.txt
index 2170e511e..94b78e577 100644
--- a/plugins/Lomiri/Launcher/CMakeLists.txt
+++ b/plugins/Lomiri/Launcher/CMakeLists.txt
@@ -12,6 +12,7 @@ include_directories(
     SYSTEM
     ${GSETTINGS_QT_INCLUDE_DIRS}
     ${GLIB_INCLUDE_DIRS}
+    ${GIO_INCLUDE_DIRS}
     ${UAL_INCLUDE_DIRS}
     )
 
@@ -48,6 +49,7 @@ target_link_libraries(LomiriLauncher-qml
     lomiri-private
     ${GSETTINGS_QT_LDFLAGS}
     ${GLIB_LIBRARIES}
+    ${GIO_LIBRARIES}
     ${UAL_LIBRARIES}
     Qt5::DBus Qt5::Qml Qt5::Gui Qt5::Concurrent
     )
diff --git a/plugins/Lomiri/Launcher/xdgwatcher.cpp b/plugins/Lomiri/Launcher/xdgwatcher.cpp
index 7cc2fd4fb..a2a958c1d 100644
--- a/plugins/Lomiri/Launcher/xdgwatcher.cpp
+++ b/plugins/Lomiri/Launcher/xdgwatcher.cpp
@@ -23,6 +23,8 @@
 #include <QStandardPaths>
 #include <QTextStream>
 
+#include <gio/gdesktopappinfo.h>
+
 XdgWatcher::XdgWatcher(QObject* parent)
     : QObject(parent),
       m_watcher(new QFileSystemWatcher(this))
@@ -100,13 +102,26 @@ const QString XdgWatcher::getAppId(const QFileInfo fileInfo) const {
     return toStandardAppId(fileInfo);
 }
 
+// Returns true if the desktop file should be shown (check for NoDisplay)
+bool XdgWatcher::shouldShow(const QFileInfo &file) const {
+    GDesktopAppInfo *appinfo = g_desktop_app_info_new(file.fileName().toUtf8().constData());
+    if (appinfo) {
+        bool show = g_app_info_should_show(G_APP_INFO(appinfo));
+        g_object_unref(appinfo);
+        return show;
+    } else {
+        qWarning() << "XdgWatcher: appinfo is NULL for" << file.absoluteFilePath();
+        return true; // Show the app if we can't determine its visibility
+    }
+}
+
 // Watch for newly added apps
 void XdgWatcher::onDirectoryChanged(const QString &path) {
     const auto files = QDir(path).entryInfoList(QDir::Files);
     const auto watchedFiles = m_watcher->files();
     for (const auto &file: files) {
         const auto appPath = file.absoluteFilePath();
-        if (file.suffix() == "desktop" && !watchedFiles.contains(appPath)) {
+        if (file.suffix() == "desktop" && !watchedFiles.contains(appPath) && shouldShow(file)) {
             m_watcher->addPath(appPath);
 
             const auto appId = getAppId(file);
diff --git a/plugins/Lomiri/Launcher/xdgwatcher.h b/plugins/Lomiri/Launcher/xdgwatcher.h
index 4c579d6a2..8ce409fa8 100644
--- a/plugins/Lomiri/Launcher/xdgwatcher.h
+++ b/plugins/Lomiri/Launcher/xdgwatcher.h
@@ -40,6 +40,7 @@ private:
     const QString toStandardAppId(const QFileInfo fileInfo) const;
     const QString getAppId(const QFileInfo file) const;
     const QString stripAppIdVersion(const QString rawAppID) const;
+    bool shouldShow(const QFileInfo &file) const;
 
     QFileSystemWatcher* m_watcher;
     QHash<const QString, QString> m_registry;
-- 
2.47.2

