feat: implement OS notifications on Linux

using "notify-send" wrapper

Related: status-im/status-desktop#2520
This commit is contained in:
Lukáš Tinkl 2022-10-12 01:09:24 +02:00 committed by Michał
parent ec90b2107d
commit c96e2601d0
1 changed files with 21 additions and 1 deletions

View File

@ -14,6 +14,12 @@ static const UINT NOTIFYICONID = 0;
static std::pair<HWND, OSNotification *> HWND_INSTANCE_PAIR;
#endif
#ifdef Q_OS_LINUX
#include <QProcess>
#include <QStandardPaths>
#include <QDebug>
#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
}
}