2020-04-14 15:53:53 +00:00
|
|
|
#include "notifications.h"
|
|
|
|
|
|
|
|
#include <base/detect.h>
|
|
|
|
|
2021-02-12 12:40:29 +00:00
|
|
|
#if defined(CONF_PLATFORM_MACOS)
|
|
|
|
// Code is in src/macos/notification.mm.
|
2023-12-03 11:53:20 +00:00
|
|
|
void NotificationsNotifyMacOsInternal(const char *pTitle, const char *pMessage);
|
2022-03-25 08:26:37 +00:00
|
|
|
#elif defined(CONF_FAMILY_UNIX) && !defined(CONF_PLATFORM_ANDROID) && !defined(CONF_PLATFORM_HAIKU) && !defined(CONF_WEBASM)
|
2020-04-14 15:53:53 +00:00
|
|
|
#include <libnotify/notify.h>
|
2023-12-03 11:53:20 +00:00
|
|
|
#define NOTIFICATIONS_USE_LIBNOTIFY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void CNotifications::Init(const char *pAppname)
|
2020-04-14 15:53:53 +00:00
|
|
|
{
|
2023-12-03 11:53:20 +00:00
|
|
|
#if defined(NOTIFICATIONS_USE_LIBNOTIFY)
|
|
|
|
notify_init(pAppname);
|
|
|
|
#endif
|
2020-04-14 15:53:53 +00:00
|
|
|
}
|
2023-12-03 11:53:20 +00:00
|
|
|
|
|
|
|
void CNotifications::Shutdown()
|
2020-04-14 15:53:53 +00:00
|
|
|
{
|
2023-12-03 11:53:20 +00:00
|
|
|
#if defined(NOTIFICATIONS_USE_LIBNOTIFY)
|
2020-04-14 15:53:53 +00:00
|
|
|
notify_uninit();
|
2023-12-03 11:53:20 +00:00
|
|
|
#endif
|
2020-04-14 15:53:53 +00:00
|
|
|
}
|
2023-12-03 11:53:20 +00:00
|
|
|
|
|
|
|
void CNotifications::Notify(const char *pTitle, const char *pMessage)
|
2020-04-14 15:53:53 +00:00
|
|
|
{
|
2023-12-03 11:53:20 +00:00
|
|
|
#if defined(CONF_PLATFORM_MACOS)
|
|
|
|
NotificationsNotifyMacOsInternal(pTitle, pMessage);
|
|
|
|
#elif defined(NOTIFICATIONS_USE_LIBNOTIFY)
|
2020-09-30 20:40:19 +00:00
|
|
|
NotifyNotification *pNotif = notify_notification_new(pTitle, pMessage, "ddnet");
|
2023-10-08 12:01:02 +00:00
|
|
|
if(pNotif)
|
|
|
|
{
|
|
|
|
notify_notification_show(pNotif, NULL);
|
|
|
|
g_object_unref(G_OBJECT(pNotif));
|
|
|
|
}
|
2023-12-03 11:53:20 +00:00
|
|
|
#endif
|
2020-04-14 15:53:53 +00:00
|
|
|
}
|
2023-12-03 11:53:20 +00:00
|
|
|
|
|
|
|
INotifications *CreateNotifications()
|
2020-04-14 15:53:53 +00:00
|
|
|
{
|
2023-12-03 11:53:20 +00:00
|
|
|
return new CNotifications();
|
2020-04-14 15:53:53 +00:00
|
|
|
}
|