Notification.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <LibGUI/Notification.h>
  2. #include <LibIPC/ServerConnection.h>
  3. #include <NotificationServer/NotificationClientEndpoint.h>
  4. #include <NotificationServer/NotificationServerEndpoint.h>
  5. namespace GUI {
  6. class NotificationServerConnection : public IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>
  7. , public NotificationClientEndpoint {
  8. C_OBJECT(NotificationServerConnection)
  9. public:
  10. virtual void handshake() override
  11. {
  12. auto response = send_sync<Messages::NotificationServer::Greet>();
  13. set_my_client_id(response->client_id());
  14. }
  15. private:
  16. NotificationServerConnection()
  17. : IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, "/tmp/portal/notify")
  18. {
  19. }
  20. virtual void handle(const Messages::NotificationClient::Dummy&) override {}
  21. };
  22. Notification::Notification()
  23. {
  24. }
  25. Notification::~Notification()
  26. {
  27. }
  28. static NotificationServerConnection& notification_server_connection()
  29. {
  30. static NotificationServerConnection* connection;
  31. if (!connection)
  32. connection = &NotificationServerConnection::construct().leak_ref();
  33. return *connection;
  34. }
  35. void Notification::show()
  36. {
  37. notification_server_connection().post_message(Messages::NotificationServer::ShowNotification(m_text, m_title));
  38. }
  39. }