ladybird/Libraries/LibGUI/Notification.cpp
Andreas Kling 96c7e2cd6d LibGUI: Make a new connection to NotificationServer each time
Since NotificationServer is a spawn-on-demand + die-when-not-used type
of service, we can't expect a singleton connection to it to remain open
and useful.

We solve this for now by making a new IPC connection for every new
notification sent. Maybe there's a better solution for this.
2020-03-26 20:10:03 +01:00

41 lines
1.1 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()
{
}
void Notification::show()
{
auto connection = NotificationServerConnection::construct();
connection->post_message(Messages::NotificationServer::ShowNotification(m_text, m_title));
}
}