| 1 | #include "notifications.h" |
|---|---|
| 2 | |
| 3 | #include <base/detect.h> |
| 4 | |
| 5 | #if defined(CONF_PLATFORM_MACOS) |
| 6 | // Code is in src/macos/notification.mm. |
| 7 | void NotificationsNotifyMacOsInternal(const char *pTitle, const char *pMessage); |
| 8 | #elif defined(CONF_FAMILY_UNIX) && !defined(CONF_PLATFORM_ANDROID) && !defined(CONF_PLATFORM_HAIKU) && !defined(CONF_PLATFORM_EMSCRIPTEN) |
| 9 | #include <libnotify/notify.h> |
| 10 | #define NOTIFICATIONS_USE_LIBNOTIFY |
| 11 | #endif |
| 12 | |
| 13 | void CNotifications::Init(const char *pAppname) |
| 14 | { |
| 15 | #if defined(NOTIFICATIONS_USE_LIBNOTIFY) |
| 16 | notify_init(app_name: pAppname); |
| 17 | #endif |
| 18 | } |
| 19 | |
| 20 | void CNotifications::Shutdown() |
| 21 | { |
| 22 | #if defined(NOTIFICATIONS_USE_LIBNOTIFY) |
| 23 | notify_uninit(); |
| 24 | #endif |
| 25 | } |
| 26 | |
| 27 | void CNotifications::Notify(const char *pTitle, const char *pMessage) |
| 28 | { |
| 29 | #if defined(CONF_PLATFORM_MACOS) |
| 30 | NotificationsNotifyMacOsInternal(pTitle, pMessage); |
| 31 | #elif defined(NOTIFICATIONS_USE_LIBNOTIFY) |
| 32 | NotifyNotification *pNotif = notify_notification_new(summary: pTitle, body: pMessage, icon: "ddnet"); |
| 33 | if(pNotif) |
| 34 | { |
| 35 | notify_notification_show(notification: pNotif, NULL); |
| 36 | g_object_unref(G_OBJECT(pNotif)); |
| 37 | } |
| 38 | #endif |
| 39 | } |
| 40 | |
| 41 | INotifications *CreateNotifications() |
| 42 | { |
| 43 | return new CNotifications(); |
| 44 | } |
| 45 |