mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:47:46 +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
|
@ -40,6 +40,7 @@ OBJS = \
|
|||
Model.o \
|
||||
ModelIndex.o \
|
||||
ModelSelection.o \
|
||||
Notification.o \
|
||||
Painter.o \
|
||||
ProgressBar.o \
|
||||
RadioButton.o \
|
||||
|
@ -71,6 +72,8 @@ LIBRARY = libgui.a
|
|||
|
||||
Application.cpp: ../../Servers/WindowServer/WindowServerEndpoint.h
|
||||
|
||||
Notification.cpp: ../../Servers/NotificationServer/NotificationServerEndpoint.h
|
||||
|
||||
../../Servers/WindowServer/WindowServerEndpoint.h:
|
||||
@flock $(dir $(@)) $(MAKE) -C $(dir $(@))
|
||||
|
||||
|
|
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));
|
||||
}
|
||||
|
||||
}
|
28
Libraries/LibGUI/Notification.h
Normal file
28
Libraries/LibGUI/Notification.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibCore/Object.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class Notification : public Core::Object {
|
||||
C_OBJECT(Notification);
|
||||
|
||||
public:
|
||||
virtual ~Notification() override;
|
||||
|
||||
const String& text() const { return m_text; }
|
||||
void set_text(const String& text) { m_text = text; }
|
||||
|
||||
const String& title() const { return m_title; }
|
||||
void set_title(const String& title) { m_title = title; }
|
||||
|
||||
void show();
|
||||
|
||||
private:
|
||||
Notification();
|
||||
|
||||
String m_title;
|
||||
String m_text;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue