mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
NotificationServer: Add a system service for desktop notifications
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.
This commit is contained in:
parent
a6e69bda71
commit
9f54ea9bcd
16 changed files with 486 additions and 1 deletions
48
Libraries/LibGUI/Notification.cpp
Normal file
48
Libraries/LibGUI/Notification.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue