mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-17 21:48:19 +00:00
Add INotifications
kernel interface
Add a proper kernel interface `INotifications` for the notifications component instead of using a C style interface. Add parameter for the application name when initializing notifications to avoid hardcoding the application name. The implementation for macOS is kept in Objective-C and a TODO is added, as the API we are currently using appears to be deprecated.
This commit is contained in:
parent
5aa4b58d4e
commit
013b8dffa5
|
@ -1888,6 +1888,7 @@ set_src(ENGINE_INTERFACE GLOB src/engine
|
||||||
keys.h
|
keys.h
|
||||||
map.h
|
map.h
|
||||||
message.h
|
message.h
|
||||||
|
notifications.h
|
||||||
rust.h
|
rust.h
|
||||||
server.h
|
server.h
|
||||||
serverbrowser.h
|
serverbrowser.h
|
||||||
|
|
|
@ -2683,6 +2683,7 @@ void CClient::InitInterfaces()
|
||||||
#endif
|
#endif
|
||||||
m_pDiscord = Kernel()->RequestInterface<IDiscord>();
|
m_pDiscord = Kernel()->RequestInterface<IDiscord>();
|
||||||
m_pSteam = Kernel()->RequestInterface<ISteam>();
|
m_pSteam = Kernel()->RequestInterface<ISteam>();
|
||||||
|
m_pNotifications = Kernel()->RequestInterface<INotifications>();
|
||||||
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
||||||
|
|
||||||
m_DemoEditor.Init(m_pGameClient->NetVersion(), &m_SnapshotDelta, m_pConsole, m_pStorage);
|
m_DemoEditor.Init(m_pGameClient->NetVersion(), &m_SnapshotDelta, m_pConsole, m_pStorage);
|
||||||
|
@ -3959,7 +3960,7 @@ void CClient::Notify(const char *pTitle, const char *pMessage)
|
||||||
if(m_pGraphics->WindowActive() || !g_Config.m_ClShowNotifications)
|
if(m_pGraphics->WindowActive() || !g_Config.m_ClShowNotifications)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NotificationsNotify(pTitle, pMessage);
|
Notifications()->Notify(pTitle, pMessage);
|
||||||
Graphics()->NotifyWindow();
|
Graphics()->NotifyWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4290,9 +4291,6 @@ int main(int argc, const char **argv)
|
||||||
if(!RandInitFailed)
|
if(!RandInitFailed)
|
||||||
CleanerFunctions.emplace([]() { secure_random_uninit(); });
|
CleanerFunctions.emplace([]() { secure_random_uninit(); });
|
||||||
|
|
||||||
NotificationsInit();
|
|
||||||
CleanerFunctions.emplace([]() { NotificationsUninit(); });
|
|
||||||
|
|
||||||
// Register SDL for cleanup before creating the kernel and client,
|
// Register SDL for cleanup before creating the kernel and client,
|
||||||
// so SDL is shutdown after kernel and client. Otherwise the client
|
// so SDL is shutdown after kernel and client. Otherwise the client
|
||||||
// may crash when shutting down after SDL is already shutdown.
|
// may crash when shutting down after SDL is already shutdown.
|
||||||
|
@ -4394,6 +4392,9 @@ int main(int argc, const char **argv)
|
||||||
ISteam *pSteam = CreateSteam();
|
ISteam *pSteam = CreateSteam();
|
||||||
pKernel->RegisterInterface(pSteam);
|
pKernel->RegisterInterface(pSteam);
|
||||||
|
|
||||||
|
INotifications *pNotifications = CreateNotifications();
|
||||||
|
pKernel->RegisterInterface(pNotifications);
|
||||||
|
|
||||||
pKernel->RegisterInterface(CreateEditor(), false);
|
pKernel->RegisterInterface(CreateEditor(), false);
|
||||||
pKernel->RegisterInterface(CreateFavorites().release());
|
pKernel->RegisterInterface(CreateFavorites().release());
|
||||||
pKernel->RegisterInterface(CreateGameClient());
|
pKernel->RegisterInterface(CreateGameClient());
|
||||||
|
@ -4401,6 +4402,7 @@ int main(int argc, const char **argv)
|
||||||
pEngine->Init();
|
pEngine->Init();
|
||||||
pConsole->Init();
|
pConsole->Init();
|
||||||
pConfigManager->Init();
|
pConfigManager->Init();
|
||||||
|
pNotifications->Init(GAME_NAME " Client");
|
||||||
|
|
||||||
// register all console commands
|
// register all console commands
|
||||||
pClient->RegisterCommands();
|
pClient->RegisterCommands();
|
||||||
|
|
|
@ -39,6 +39,7 @@ class IEngineSound;
|
||||||
class IFriends;
|
class IFriends;
|
||||||
class ILogger;
|
class ILogger;
|
||||||
class ISteam;
|
class ISteam;
|
||||||
|
class INotifications;
|
||||||
class IStorage;
|
class IStorage;
|
||||||
class IUpdater;
|
class IUpdater;
|
||||||
|
|
||||||
|
@ -71,6 +72,7 @@ class CClient : public IClient, public CDemoPlayer::IListener
|
||||||
IEngineMap *m_pMap = nullptr;
|
IEngineMap *m_pMap = nullptr;
|
||||||
IEngineSound *m_pSound = nullptr;
|
IEngineSound *m_pSound = nullptr;
|
||||||
ISteam *m_pSteam = nullptr;
|
ISteam *m_pSteam = nullptr;
|
||||||
|
INotifications *m_pNotifications = nullptr;
|
||||||
IStorage *m_pStorage = nullptr;
|
IStorage *m_pStorage = nullptr;
|
||||||
IEngineTextRender *m_pTextRender = nullptr;
|
IEngineTextRender *m_pTextRender = nullptr;
|
||||||
IUpdater *m_pUpdater = nullptr;
|
IUpdater *m_pUpdater = nullptr;
|
||||||
|
@ -260,6 +262,7 @@ public:
|
||||||
IEngineInput *Input() { return m_pInput; }
|
IEngineInput *Input() { return m_pInput; }
|
||||||
IEngineSound *Sound() { return m_pSound; }
|
IEngineSound *Sound() { return m_pSound; }
|
||||||
ISteam *Steam() { return m_pSteam; }
|
ISteam *Steam() { return m_pSteam; }
|
||||||
|
INotifications *Notifications() { return m_pNotifications; }
|
||||||
IStorage *Storage() { return m_pStorage; }
|
IStorage *Storage() { return m_pStorage; }
|
||||||
IEngineTextRender *TextRender() { return m_pTextRender; }
|
IEngineTextRender *TextRender() { return m_pTextRender; }
|
||||||
IUpdater *Updater() { return m_pUpdater; }
|
IUpdater *Updater() { return m_pUpdater; }
|
||||||
|
|
|
@ -4,35 +4,41 @@
|
||||||
|
|
||||||
#if defined(CONF_PLATFORM_MACOS)
|
#if defined(CONF_PLATFORM_MACOS)
|
||||||
// Code is in src/macos/notification.mm.
|
// Code is in src/macos/notification.mm.
|
||||||
|
void NotificationsNotifyMacOsInternal(const char *pTitle, const char *pMessage);
|
||||||
#elif defined(CONF_FAMILY_UNIX) && !defined(CONF_PLATFORM_ANDROID) && !defined(CONF_PLATFORM_HAIKU) && !defined(CONF_WEBASM)
|
#elif defined(CONF_FAMILY_UNIX) && !defined(CONF_PLATFORM_ANDROID) && !defined(CONF_PLATFORM_HAIKU) && !defined(CONF_WEBASM)
|
||||||
#include <libnotify/notify.h>
|
#include <libnotify/notify.h>
|
||||||
void NotificationsInit()
|
#define NOTIFICATIONS_USE_LIBNOTIFY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void CNotifications::Init(const char *pAppname)
|
||||||
{
|
{
|
||||||
notify_init("DDNet Client");
|
#if defined(NOTIFICATIONS_USE_LIBNOTIFY)
|
||||||
|
notify_init(pAppname);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
void NotificationsUninit()
|
|
||||||
|
void CNotifications::Shutdown()
|
||||||
{
|
{
|
||||||
|
#if defined(NOTIFICATIONS_USE_LIBNOTIFY)
|
||||||
notify_uninit();
|
notify_uninit();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
void NotificationsNotify(const char *pTitle, const char *pMessage)
|
|
||||||
|
void CNotifications::Notify(const char *pTitle, const char *pMessage)
|
||||||
{
|
{
|
||||||
|
#if defined(CONF_PLATFORM_MACOS)
|
||||||
|
NotificationsNotifyMacOsInternal(pTitle, pMessage);
|
||||||
|
#elif defined(NOTIFICATIONS_USE_LIBNOTIFY)
|
||||||
NotifyNotification *pNotif = notify_notification_new(pTitle, pMessage, "ddnet");
|
NotifyNotification *pNotif = notify_notification_new(pTitle, pMessage, "ddnet");
|
||||||
if(pNotif)
|
if(pNotif)
|
||||||
{
|
{
|
||||||
notify_notification_show(pNotif, NULL);
|
notify_notification_show(pNotif, NULL);
|
||||||
g_object_unref(G_OBJECT(pNotif));
|
g_object_unref(G_OBJECT(pNotif));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#else
|
|
||||||
void NotificationsInit()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void NotificationsUninit()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void NotificationsNotify(const char *pTitle, const char *pMessage)
|
|
||||||
{
|
|
||||||
(void)pTitle;
|
|
||||||
(void)pMessage;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
INotifications *CreateNotifications()
|
||||||
|
{
|
||||||
|
return new CNotifications();
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
#ifndef ENGINE_CLIENT_NOTIFICATIONS_H
|
#ifndef ENGINE_CLIENT_NOTIFICATIONS_H
|
||||||
#define ENGINE_CLIENT_NOTIFICATIONS_H
|
#define ENGINE_CLIENT_NOTIFICATIONS_H
|
||||||
void NotificationsInit();
|
|
||||||
void NotificationsUninit();
|
#include <engine/notifications.h>
|
||||||
void NotificationsNotify(const char *pTitle, const char *pMessage);
|
|
||||||
|
class CNotifications : public INotifications
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void Init(const char *pAppname) override;
|
||||||
|
void Shutdown() override;
|
||||||
|
void Notify(const char *pTitle, const char *pMessage) override;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // ENGINE_CLIENT_NOTIFICATIONS_H
|
#endif // ENGINE_CLIENT_NOTIFICATIONS_H
|
||||||
|
|
17
src/engine/notifications.h
Normal file
17
src/engine/notifications.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef ENGINE_NOTIFICATIONS_H
|
||||||
|
#define ENGINE_NOTIFICATIONS_H
|
||||||
|
|
||||||
|
#include "kernel.h"
|
||||||
|
|
||||||
|
class INotifications : public IInterface
|
||||||
|
{
|
||||||
|
MACRO_INTERFACE("notifications")
|
||||||
|
public:
|
||||||
|
virtual void Init(const char *pAppname) = 0;
|
||||||
|
virtual void Shutdown() override = 0;
|
||||||
|
virtual void Notify(const char *pTitle, const char *pMessage) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
INotifications *CreateNotifications();
|
||||||
|
|
||||||
|
#endif // ENGINE_NOTIFICATIONS_H
|
|
@ -1,16 +1,9 @@
|
||||||
#import <engine/client/notifications.h>
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import <Foundation/NSUserNotification.h>
|
#import <Foundation/NSUserNotification.h>
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
void NotificationsInit()
|
// TODO: NSUserNotification is deprecated. Use the User Notifications framework instead: https://developer.apple.com/documentation/usernotifications?language=objc
|
||||||
{
|
void NotificationsNotifyMacOsInternal(const char *pTitle, const char *pMessage)
|
||||||
}
|
|
||||||
void NotificationsUninit()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void NotificationsNotify(const char *pTitle, const char *pMessage)
|
|
||||||
{
|
{
|
||||||
NSString* pNsTitle = [NSString stringWithCString:pTitle encoding:NSUTF8StringEncoding];
|
NSString* pNsTitle = [NSString stringWithCString:pTitle encoding:NSUTF8StringEncoding];
|
||||||
NSString* pNsMsg = [NSString stringWithCString:pMessage encoding:NSUTF8StringEncoding];
|
NSString* pNsMsg = [NSString stringWithCString:pMessage encoding:NSUTF8StringEncoding];
|
||||||
|
|
Loading…
Reference in a new issue