mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
9f54ea9bcd
This patch adds NotificationServer, which runs as the "notify" user and provides an IPC API for desktop notifications. LibGUI gains the GUI::Notification class for showing notifications. NotificationServer is spawned on demand and will unspawn after dimissing all visible notifications. :^) Finally, this also comes with a small /bin/notify utility.
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include <LibGUI/Notification.h>
|
|
#include <LibIPC/ServerConnection.h>
|
|
#include <NotificationServer/NotificationClientEndpoint.h>
|
|
#include <NotificationServer/NotificationServerEndpoint.h>
|
|
|
|
namespace GUI {
|
|
|
|
class NotificationServerConnection : public IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>
|
|
, public NotificationClientEndpoint {
|
|
C_OBJECT(NotificationServerConnection)
|
|
public:
|
|
virtual void handshake() override
|
|
{
|
|
auto response = send_sync<Messages::NotificationServer::Greet>();
|
|
set_my_client_id(response->client_id());
|
|
}
|
|
|
|
private:
|
|
NotificationServerConnection()
|
|
: IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, "/tmp/portal/notify")
|
|
{
|
|
|
|
}
|
|
virtual void handle(const Messages::NotificationClient::Dummy&) override {}
|
|
};
|
|
|
|
Notification::Notification()
|
|
{
|
|
}
|
|
|
|
Notification::~Notification()
|
|
{
|
|
}
|
|
|
|
static NotificationServerConnection& notification_server_connection()
|
|
{
|
|
static NotificationServerConnection* connection;
|
|
if (!connection)
|
|
connection = &NotificationServerConnection::construct().leak_ref();
|
|
return *connection;
|
|
}
|
|
|
|
void Notification::show()
|
|
{
|
|
notification_server_connection().post_message(Messages::NotificationServer::ShowNotification(m_text, m_title));
|
|
}
|
|
|
|
}
|