mirror of
https://github.com/RGBCube/serenity
synced 2025-07-22 22:27:39 +00:00
NotificationServer: Close connection on notification close
When the notification was closed, the connection was kept around. This caused the core event loop to take up nearly all CPU, so instead of checking the connection we clear it on close and add state variables to check state.
This commit is contained in:
parent
9d09594e44
commit
ddcef0452a
2 changed files with 33 additions and 12 deletions
|
@ -34,23 +34,28 @@ namespace GUI {
|
||||||
class NotificationServerConnection : public IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>
|
class NotificationServerConnection : public IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>
|
||||||
, public NotificationClientEndpoint {
|
, public NotificationClientEndpoint {
|
||||||
C_OBJECT(NotificationServerConnection)
|
C_OBJECT(NotificationServerConnection)
|
||||||
|
|
||||||
|
friend class Notification;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void handshake() override
|
virtual void handshake() override
|
||||||
{
|
{
|
||||||
send_sync<Messages::NotificationServer::Greet>();
|
send_sync<Messages::NotificationServer::Greet>();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void die() override { m_connected = false; }
|
virtual void die() override
|
||||||
|
{
|
||||||
bool is_connected() const { return m_connected; }
|
m_notification->connection_closed();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NotificationServerConnection()
|
explicit NotificationServerConnection(Notification* notification)
|
||||||
: IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, "/tmp/portal/notify")
|
: IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, "/tmp/portal/notify")
|
||||||
|
, m_notification(notification)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual void handle(const Messages::NotificationClient::Dummy&) override { }
|
virtual void handle(const Messages::NotificationClient::Dummy&) override { }
|
||||||
bool m_connected { true };
|
Notification* m_notification;
|
||||||
};
|
};
|
||||||
|
|
||||||
Notification::Notification()
|
Notification::Notification()
|
||||||
|
@ -63,25 +68,27 @@ Notification::~Notification()
|
||||||
|
|
||||||
void Notification::show()
|
void Notification::show()
|
||||||
{
|
{
|
||||||
VERIFY(!m_connection);
|
VERIFY(!m_shown && !m_destroyed);
|
||||||
auto icon = m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap();
|
auto icon = m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap();
|
||||||
m_connection = NotificationServerConnection::construct();
|
m_connection = NotificationServerConnection::construct(this);
|
||||||
m_connection->send_sync<Messages::NotificationServer::ShowNotification>(m_text, m_title, icon);
|
m_connection->send_sync<Messages::NotificationServer::ShowNotification>(m_text, m_title, icon);
|
||||||
|
m_shown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::close()
|
void Notification::close()
|
||||||
{
|
{
|
||||||
VERIFY(m_connection);
|
VERIFY(m_shown);
|
||||||
if (!m_connection->is_connected()) {
|
if (!m_destroyed) {
|
||||||
|
m_connection->send_sync<Messages::NotificationServer::CloseNotification>();
|
||||||
|
connection_closed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_connection->send_sync<Messages::NotificationServer::CloseNotification>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Notification::update()
|
bool Notification::update()
|
||||||
{
|
{
|
||||||
VERIFY(m_connection);
|
VERIFY(m_shown);
|
||||||
if (!m_connection->is_connected()) {
|
if (m_destroyed) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,4 +106,10 @@ bool Notification::update()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Notification::connection_closed()
|
||||||
|
{
|
||||||
|
m_connection.clear();
|
||||||
|
m_destroyed = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ class NotificationServerConnection;
|
||||||
class Notification : public Core::Object {
|
class Notification : public Core::Object {
|
||||||
C_OBJECT(Notification);
|
C_OBJECT(Notification);
|
||||||
|
|
||||||
|
friend class NotificationServerConnection;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Notification() override;
|
virtual ~Notification() override;
|
||||||
|
|
||||||
|
@ -64,9 +66,13 @@ public:
|
||||||
bool update();
|
bool update();
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
bool is_showing() const { return m_shown && !m_destroyed; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Notification();
|
Notification();
|
||||||
|
|
||||||
|
void connection_closed();
|
||||||
|
|
||||||
String m_title;
|
String m_title;
|
||||||
bool m_title_dirty;
|
bool m_title_dirty;
|
||||||
String m_text;
|
String m_text;
|
||||||
|
@ -74,6 +80,8 @@ private:
|
||||||
RefPtr<Gfx::Bitmap> m_icon;
|
RefPtr<Gfx::Bitmap> m_icon;
|
||||||
bool m_icon_dirty;
|
bool m_icon_dirty;
|
||||||
|
|
||||||
|
bool m_destroyed { false };
|
||||||
|
bool m_shown { false };
|
||||||
RefPtr<NotificationServerConnection> m_connection;
|
RefPtr<NotificationServerConnection> m_connection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue