1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:17:35 +00:00

Notification: Prevent showing a closed window

If a notification was closed, the connection will now be dead. To
prevent inconsistencies between when a user closes a notification and
when an application closes an applicated, check if the notification has
been closed before allowing any action.
This commit is contained in:
Nick Johnson 2021-03-11 15:33:37 -06:00 committed by Andreas Kling
parent 0fd1e6f062
commit 147a2c4ca2
2 changed files with 18 additions and 1 deletions

View file

@ -40,12 +40,17 @@ public:
send_sync<Messages::NotificationServer::Greet>(); send_sync<Messages::NotificationServer::Greet>();
} }
virtual void die() override { m_connected = false; }
bool is_connected() const { return m_connected; }
private: private:
NotificationServerConnection() NotificationServerConnection()
: IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, "/tmp/portal/notify") : IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, "/tmp/portal/notify")
{ {
} }
virtual void handle(const Messages::NotificationClient::Dummy&) override { } virtual void handle(const Messages::NotificationClient::Dummy&) override { }
bool m_connected { true };
}; };
Notification::Notification() Notification::Notification()
@ -60,15 +65,26 @@ Notification::~Notification()
void Notification::show() void Notification::show()
{ {
VERIFY(!m_showing); VERIFY(!m_showing);
VERIFY(!m_disposed);
if (!m_connection->is_connected()) {
// This would imply that the NotificationServer crashed before we could send it any data.
VERIFY_NOT_REACHED();
}
auto icon = m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap(); auto icon = m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap();
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_showing = true; m_showing = true;
} }
void Notification::close() void Notification::close()
{ {
VERIFY(m_showing); VERIFY(m_showing);
m_connection->send_sync<Messages::NotificationServer::CloseNotification>(); if (m_connection->is_connected()) {
m_connection->send_sync<Messages::NotificationServer::CloseNotification>();
}
m_showing = false; m_showing = false;
m_disposed = true;
}
} }
} }

View file

@ -60,6 +60,7 @@ private:
NonnullRefPtr<NotificationServerConnection> m_connection; NonnullRefPtr<NotificationServerConnection> m_connection;
bool m_showing { false }; bool m_showing { false };
bool m_disposed { false };
}; };
} }