summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorNick Johnson <sylvyrfysh@gmail.com>2021-03-11 15:33:37 -0600
committerAndreas Kling <kling@serenityos.org>2021-03-22 12:46:16 +0100
commit147a2c4ca26e88c76557b59cb1e1dc6486d188fd (patch)
treeca247efc73b49c6cc279767b0df71adc9dbd5b20 /Userland/Libraries/LibGUI
parent0fd1e6f062de8dd3d06a06b144fa45306446cd38 (diff)
downloadserenity-147a2c4ca26e88c76557b59cb1e1dc6486d188fd.zip
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.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/Notification.cpp18
-rw-r--r--Userland/Libraries/LibGUI/Notification.h1
2 files changed, 18 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/Notification.cpp b/Userland/Libraries/LibGUI/Notification.cpp
index 13a4820d6b..b4ea45882f 100644
--- a/Userland/Libraries/LibGUI/Notification.cpp
+++ b/Userland/Libraries/LibGUI/Notification.cpp
@@ -40,12 +40,17 @@ public:
send_sync<Messages::NotificationServer::Greet>();
}
+ virtual void die() override { m_connected = false; }
+
+ bool is_connected() const { return m_connected; }
+
private:
NotificationServerConnection()
: IPC::ServerConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, "/tmp/portal/notify")
{
}
virtual void handle(const Messages::NotificationClient::Dummy&) override { }
+ bool m_connected { true };
};
Notification::Notification()
@@ -60,15 +65,26 @@ Notification::~Notification()
void Notification::show()
{
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();
m_connection->send_sync<Messages::NotificationServer::ShowNotification>(m_text, m_title, icon);
m_showing = true;
}
+
void Notification::close()
{
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_disposed = true;
+}
}
}
diff --git a/Userland/Libraries/LibGUI/Notification.h b/Userland/Libraries/LibGUI/Notification.h
index 44f1479b74..445b856411 100644
--- a/Userland/Libraries/LibGUI/Notification.h
+++ b/Userland/Libraries/LibGUI/Notification.h
@@ -60,6 +60,7 @@ private:
NonnullRefPtr<NotificationServerConnection> m_connection;
bool m_showing { false };
+ bool m_disposed { false };
};
}