From c96e2601d0024452c9b380dacebb0984b001d454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Wed, 12 Oct 2022 01:09:24 +0200 Subject: [PATCH] feat: implement OS notifications on Linux using "notify-send" wrapper Related: status-im/status-desktop#2520 --- .../lib/src/Status/OSNotification.cpp | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/vendor/DOtherSide/lib/src/Status/OSNotification.cpp b/vendor/DOtherSide/lib/src/Status/OSNotification.cpp index d4b2689980..b2a83728e1 100644 --- a/vendor/DOtherSide/lib/src/Status/OSNotification.cpp +++ b/vendor/DOtherSide/lib/src/Status/OSNotification.cpp @@ -14,6 +14,12 @@ static const UINT NOTIFYICONID = 0; static std::pair HWND_INSTANCE_PAIR; #endif +#ifdef Q_OS_LINUX +#include +#include +#include +#endif + using namespace Status; OSNotification::OSNotification(QObject *parent) @@ -158,6 +164,20 @@ void OSNotification::showNotification(const QString& title, #elif defined Q_OS_MACOS showNotificationMacOs(title, message, identifier); +#elif defined Q_OS_LINUX + static QString notifyExe = QStandardPaths::findExecutable(QStringLiteral("notify-send")); + if (notifyExe.isEmpty()) { + qWarning() << "'notify-send' not found; OS notifications will not work"; + return; + } + + QStringList args; // spec https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html + args << QStringLiteral("-a") << QStringLiteral("nim-status"); // appname; w/o .desktop extension + args << QStringLiteral("-c") << QStringLiteral("im"); // category; generic "im" category + args << title; // summary + args << message; // body + + QProcess::execute(notifyExe, args); #endif } @@ -168,4 +188,4 @@ void OSNotification::showIconBadgeNotification(int notificationsCount) #elif defined Q_OS_MACOS showIconBadgeNotificationMacOs(notificationsCount); #endif -} \ No newline at end of file +}