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.
7void 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) && !defined(CONF_PLATFORM_IOS)
9#include <libnotify/notify.h>
10#define NOTIFICATIONS_USE_LIBNOTIFY
11#endif
12
13void CNotifications::Init(const char *pAppname)
14{
15#if defined(NOTIFICATIONS_USE_LIBNOTIFY)
16 notify_init(app_name: pAppname);
17#endif
18}
19
20void CNotifications::Shutdown()
21{
22#if defined(NOTIFICATIONS_USE_LIBNOTIFY)
23 notify_uninit();
24#endif
25}
26
27void 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 gchar *pEscaped = g_markup_escape_text(text: pMessage, length: -1);
33 NotifyNotification *pNotif = notify_notification_new(summary: pTitle, body: pEscaped, icon: "ddnet");
34 if(pNotif)
35 {
36 notify_notification_show(notification: pNotif, error: nullptr);
37 g_object_unref(G_OBJECT(pNotif));
38 }
39 g_free(pEscaped);
40#endif
41}
42
43INotifications *CreateNotifications()
44{
45 return new CNotifications();
46}
47