[frameworks/knotifications] src: Ensure we have notifyrc file for platform notification configuration
Volker Krause <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit f37499b6fd8ba36f86c75ac0e3180b7026abf0aa by Volker Krause.
Committed on 01/08/2026 at 09:00.
Pushed by vkrause into branch 'master'.
Ensure we have notifyrc file for platform notification configuration
Outside of Android even a Qt resource bundled one isn't good enough,
System Settings wont be able to see that.
M +19 -1 src/knotificationconfiguration.cpp
M +3 -0 src/knotificationconfiguration.h
https://invent.kde.org/frameworks/knotifications/-/commit/f37499b6fd8ba36f86c75ac0e3180b7026abf0aa
diff --git a/src/knotificationconfiguration.cpp b/src/knotificationconfiguration.cpp
index 2365c0f9..6134b5a0 100644
--- a/src/knotificationconfiguration.cpp
+++ b/src/knotificationconfiguration.cpp
@@ -19,6 +19,20 @@
using namespace Qt::Literals;
+[[nodiscard]] static bool hasNotifyRcFile(QStringView appName)
+{
+ if (!QStandardPaths::locate(QStandardPaths::GenericDataLocation, "knotifications6/"_L1 + appName + ".notifyrc"_L1).isEmpty()) {
+ return true;
+ }
+#ifdef Q_OS_ANDROID
+ // on platforms where the system doesn't read notifyrc files bundling them as Qt resources is good enough'
+ if (QFileInfo::exists(":/knotifications6/"_L1 + appName + ".notifyrc"_L1)) {
+ return true;
+ }
+#endif
+ return false;
+}
+
#ifndef Q_OS_ANDROID
struct {
bool initialized : 1 = false;
@@ -33,6 +47,10 @@ static void detectCapabilities()
}
s_capabilities.initialized = true;
+ if (!hasNotifyRcFile(QCoreApplication::applicationName())) {
+ return;
+ }
+
if (QFileInfo::exists(u"/.flatpak-info"_s)) {
// technically only for Plasma >= 6.7, but we have no way to detect that
s_capabilities.hasSystemSettingsUri = qgetenv("XDG_CURRENT_DESKTOP") == "KDE";
@@ -53,7 +71,7 @@ static void detectCapabilities()
bool KNotificationConfiguration::isAvailable()
{
#ifdef Q_OS_ANDROID
- return true;
+ return hasNotifyRcFile(QCoreApplication::applicationName());
#else
detectCapabilities();
return s_capabilities.hasSystemSettingsUri || s_capabilities.hasKcm;
diff --git a/src/knotificationconfiguration.h b/src/knotificationconfiguration.h
index 7412befb..fd2dd018 100644
--- a/src/knotificationconfiguration.h
+++ b/src/knotificationconfiguration.h
@@ -25,6 +25,9 @@ class KNotificationConfigurationPrivate;
* This is particularly relevant for sandboxed applications (Flatpak, APK, etc)
* where the host platform ultimately decides if/how notifications are shown.
*
+ * This requires an installed \c .notifyrc file matching the application name
+ * to work, a \c .notifyrc file bundled as Qt resource will only work on Android.
+ *
* \since 6.28
*/
class KNOTIFICATIONS_EXPORT KNotificationConfiguration