From 974bcb776ee6c5d2399a09befad3c133cea7891d Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Fri, 6 Jul 2018 20:03:43 +0200 Subject: [PATCH] Remember if the notification is living on a valid connection The notification spec says, that a notification gets invalidated when closed. So the client won't listen anymore to ActionInvoked signals and won't listen to NotificationClosed signals. Remembering the actual status of the notification helps the standard and makes the behavior clearer. --- src/dbus.c | 15 +++++++++++++++ src/notification.c | 1 + src/notification.h | 1 + 3 files changed, 17 insertions(+) diff --git a/src/dbus.c b/src/dbus.c index 603a510..c485a57 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -137,6 +137,7 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV n->actions = g_malloc0(sizeof(struct actions)); n->dbus_client = g_strdup(sender); + n->dbus_valid = true; { GVariantIter *iter = g_variant_iter_new(parameters); @@ -316,6 +317,12 @@ static void on_get_server_information(GDBusConnection *connection, void signal_notification_closed(struct notification *n, enum reason reason) { + if (!n->dbus_valid) { + LOG_W("Closing notification '%s' not supported. " + "Notification already closed.", n->summary); + return; + } + if (reason < REASON_MIN || REASON_MAX < reason) { LOG_W("Closing notification with reason '%d' not supported. " "Closing it with reason '%d'.", reason, REASON_UNDEF); @@ -337,6 +344,8 @@ void signal_notification_closed(struct notification *n, enum reason reason) body, &err); + n->dbus_valid = false; + if (err) { LOG_W("Unable to close notification: %s", err->message); g_error_free(err); @@ -346,6 +355,12 @@ void signal_notification_closed(struct notification *n, enum reason reason) void signal_action_invoked(const struct notification *n, const char *identifier) { + if (!n->dbus_valid) { + LOG_W("Invoking action '%s' not supported. " + "Notification already closed.", identifier); + return; + } + GVariant *body = g_variant_new("(us)", n->id, identifier); GError *err = NULL; diff --git a/src/notification.c b/src/notification.c index 906deab..c08fbe2 100644 --- a/src/notification.c +++ b/src/notification.c @@ -306,6 +306,7 @@ struct notification *notification_create(void) n->progress = -1; n->script_run = false; + n->dbus_valid = false; n->fullscreen = FS_SHOW; diff --git a/src/notification.h b/src/notification.h index 6f9731b..0764152 100644 --- a/src/notification.h +++ b/src/notification.h @@ -48,6 +48,7 @@ struct notification { NotificationPrivate *priv; int id; char *dbus_client; + bool dbus_valid; char *appname; char *summary;