feature(desktop/general): Showing number of all notifications on tray icon badge

Functionality added to OSNotification.
MacOS version.

Issue #4922
This commit is contained in:
Michal Iskierko 2022-04-01 17:54:39 +02:00 committed by Michał
parent 3487862d27
commit e666ccf1ad
5 changed files with 33 additions and 0 deletions

View File

@ -1004,6 +1004,7 @@ DOS_API void dos_event_delete(DosEvent* vptr);
DOS_API DosOSNotification* dos_osnotification_create(); DOS_API DosOSNotification* dos_osnotification_create();
DOS_API void dos_osnotification_show_notification(DosOSNotification* vptr, DOS_API void dos_osnotification_show_notification(DosOSNotification* vptr,
const char* title, const char* message, const char* identifier); const char* title, const char* message, const char* identifier);
DOS_API void dos_osnotification_show_badge_notification(DosOSNotification* vptr, int notificationsCount);
DOS_API void dos_osnotification_delete(DosOSNotification* vptr); DOS_API void dos_osnotification_delete(DosOSNotification* vptr);
#pragma endregion #pragma endregion

View File

@ -23,6 +23,8 @@ namespace Status
void showNotification(const QString& title, const QString& message, void showNotification(const QString& title, const QString& message,
const QString& identifier); const QString& identifier);
void showIconBadgeNotification(int notificationsCount);
signals: signals:
void notificationClicked(QString identifier); void notificationClicked(QString identifier);
@ -41,6 +43,7 @@ namespace Status
private: private:
void initNotificationMacOs(); void initNotificationMacOs();
void showNotificationMacOs(QString title, QString message, QString identifier); void showNotificationMacOs(QString title, QString message, QString identifier);
void showIconBadgeNotificationMacOs(int notificationsCount);
private: private:
NotificationHelper *m_notificationHelper; NotificationHelper *m_notificationHelper;

View File

@ -1435,6 +1435,13 @@ void dos_osnotification_show_notification(DosOSNotification* vptr,
notificationObj->showNotification(title, message, identifier); notificationObj->showNotification(title, message, identifier);
} }
void dos_osnotification_show_badge_notification(DosOSNotification* vptr, int notificationsCount)
{
auto notificationObj = static_cast<Status::OSNotification*>(vptr);
if(notificationObj)
notificationObj->showIconBadgeNotification(notificationsCount);
}
void dos_osnotification_delete(DosOSNotification* vptr) void dos_osnotification_delete(DosOSNotification* vptr)
{ {
auto qobject = static_cast<QObject*>(vptr); auto qobject = static_cast<QObject*>(vptr);

View File

@ -159,4 +159,13 @@ void OSNotification::showNotification(const QString& title,
#elif defined Q_OS_MACOS #elif defined Q_OS_MACOS
showNotificationMacOs(title, message, identifier); showNotificationMacOs(title, message, identifier);
#endif #endif
}
void OSNotification::showIconBadgeNotification(int notificationsCount)
{
#ifdef Q_OS_WIN
// TODO
#elif defined Q_OS_MACOS
showIconBadgeNotificationMacOs(notificationsCount);
#endif
} }

View File

@ -1,5 +1,7 @@
#include "DOtherSide/Status/OSNotification.h" #include "DOtherSide/Status/OSNotification.h"
#include <QString>
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
@ -55,6 +57,17 @@ void OSNotification::showNotificationMacOs(QString title, QString message,
[notification release]; [notification release];
} }
void OSNotification::showIconBadgeNotificationMacOs(int notificationsCount)
{
QString notificationsString; // empty string will clear the badge
if (notificationsCount > 0 && notificationsCount < 10) {
notificationsString = QString::number(notificationsCount);
} else if (notificationsCount >= 10) {
notificationsString = "9+";
}
[[NSApp dockTile] setBadgeLabel:notificationsString.toNSString()];
}
@implementation NotificationDelegate { @implementation NotificationDelegate {
OSNotification* instance; OSNotification* instance;
} }