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.
This commit is contained in:
Benedikt Heine 2018-07-06 20:03:43 +02:00
parent 837b4fe125
commit 974bcb776e
3 changed files with 17 additions and 0 deletions

View File

@ -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;

View File

@ -306,6 +306,7 @@ struct notification *notification_create(void)
n->progress = -1;
n->script_run = false;
n->dbus_valid = false;
n->fullscreen = FS_SHOW;

View File

@ -48,6 +48,7 @@ struct notification {
NotificationPrivate *priv;
int id;
char *dbus_client;
bool dbus_valid;
char *appname;
char *summary;