summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/Notification.cpp
diff options
context:
space:
mode:
authorNick Johnson <sylvyrfysh@gmail.com>2021-03-12 11:53:51 -0600
committerAndreas Kling <kling@serenityos.org>2021-03-22 12:46:16 +0100
commitc7f00717c3224b24d4c567693bdfc876e0fc8b62 (patch)
tree0060f478040a088ab780f2a2a9c30f87ab8a2ec4 /Userland/Libraries/LibGUI/Notification.cpp
parente17752fc919411c5761ca424fc71ab1f50690d72 (diff)
downloadserenity-c7f00717c3224b24d4c567693bdfc876e0fc8b62.zip
Notification: Use RefPtr for connection
With this RefPtr, we can initialize the connection to the NotificationServer upon showing the notification. With this, we can prevent double shows and updates or closes before showing.
Diffstat (limited to 'Userland/Libraries/LibGUI/Notification.cpp')
-rw-r--r--Userland/Libraries/LibGUI/Notification.cpp54
1 files changed, 10 insertions, 44 deletions
diff --git a/Userland/Libraries/LibGUI/Notification.cpp b/Userland/Libraries/LibGUI/Notification.cpp
index d863309300..f38141044c 100644
--- a/Userland/Libraries/LibGUI/Notification.cpp
+++ b/Userland/Libraries/LibGUI/Notification.cpp
@@ -54,7 +54,6 @@ private:
};
Notification::Notification()
- : m_connection(NotificationServerConnection::construct())
{
}
@@ -64,73 +63,40 @@ 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();
- }
+ VERIFY(!m_connection);
auto icon = m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap();
+ m_connection = NotificationServerConnection::construct();
m_connection->send_sync<Messages::NotificationServer::ShowNotification>(m_text, m_title, icon);
- m_showing = true;
}
void Notification::close()
{
- VERIFY(m_showing);
- if (m_connection->is_connected()) {
- m_connection->send_sync<Messages::NotificationServer::CloseNotification>();
+ VERIFY(m_connection);
+ if (!m_connection->is_connected()) {
+ return;
}
-
- m_showing = false;
- m_disposed = true;
+ m_connection->send_sync<Messages::NotificationServer::CloseNotification>();
}
bool Notification::update()
{
- VERIFY(m_showing);
- VERIFY(!m_disposed);
+ VERIFY(m_connection);
if (!m_connection->is_connected()) {
- m_showing = false;
- m_disposed = true;
return false;
}
- bool is_checked = false;
-
if (m_text_dirty || m_title_dirty) {
- auto response = m_connection->send_sync<Messages::NotificationServer::UpdateNotificationText>(m_text, m_title);
+ m_connection->send_sync<Messages::NotificationServer::UpdateNotificationText>(m_text, m_title);
m_text_dirty = false;
m_title_dirty = false;
-
- is_checked = true;
- if (!response->still_showing()) {
- m_showing = false;
- m_disposed = true;
- return false;
- }
}
if (m_icon_dirty) {
- auto response = m_connection->send_sync<Messages::NotificationServer::UpdateNotificationIcon>(m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap());
+ m_connection->send_sync<Messages::NotificationServer::UpdateNotificationIcon>(m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap());
m_icon_dirty = false;
-
- is_checked = true;
- if (!response->still_showing()) {
- m_showing = false;
- m_disposed = true;
- return false;
- }
}
- if (!is_checked) {
- auto response = m_connection->send_sync<Messages::NotificationServer::IsShowing>();
- m_showing = response->still_showing();
- if (!m_showing) {
- m_disposed = true;
- }
- }
- return m_showing;
+ return true;
}
}