Skip to content

Commit

Permalink
notification: Ensure backwards compatibility with old backends
Browse files Browse the repository at this point in the history
We want to support old backends ensure we filter out properties that
were introduced in never versions.
In the case of the file-descriptor icon we can translate it to a bytes
icon to increase compatibility.
  • Loading branch information
jsparber committed Oct 16, 2024
1 parent 4b1a2e3 commit 2e8860a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ parse_button (GVariantBuilder *builder,
if (!target)
target = g_steal_pointer (&value);
}
else if (strcmp (key, "purpose") == 0)
else if (strcmp (key, "purpose") == 0 && impl_version > 1)
{
if (!check_button_purpose (value, error))
return FALSE;
Expand Down Expand Up @@ -662,7 +662,30 @@ parse_serialized_icon (GVariantBuilder *builder,
}

if (xdp_validate_icon (sealed_icon, XDP_ICON_TYPE_NOTIFICATION, NULL, NULL))
g_variant_builder_add (builder, "{sv}", "icon", icon);
{
/* Convert file descriptor icons to byte icons for backwards compatibility */
if (impl_version < 2)
{
g_autoptr(GBytes) bytes = NULL;
GVariant *bytes_icon;

bytes = xdp_sealed_fd_get_bytes (sealed_icon, &local_error);
if (!bytes)
{
g_warning ("Failed to get bytes from file-descriptor icon: %s", local_error->message);
return TRUE;
}

bytes_icon = g_variant_new ("(sv)", "bytes",
g_variant_new_from_bytes (G_VARIANT_TYPE_BYTESTRING, bytes, TRUE));

g_variant_builder_add (builder, "{sv}", "icon", bytes_icon);
}
else
{
g_variant_builder_add (builder, "{sv}", "icon", icon);
}
}
}
else
{
Expand Down Expand Up @@ -864,7 +887,7 @@ parse_notification (GVariantBuilder *builder,

g_variant_builder_add (builder, "{sv}", key, value);
}
else if (strcmp (key, "markup-body") == 0)
else if (strcmp (key, "markup-body") == 0 && impl_version > 1)
{
if (!parse_markup_body (builder, value, error))
return FALSE;
Expand All @@ -877,7 +900,7 @@ parse_notification (GVariantBuilder *builder,
return FALSE;
}
}
else if (strcmp (key, "sound") == 0)
else if (strcmp (key, "sound") == 0 && impl_version > 1)
{
if (!parse_serialized_sound (builder, value, fd_list, error))
{
Expand Down Expand Up @@ -906,12 +929,12 @@ parse_notification (GVariantBuilder *builder,
if (!parse_buttons (builder, value, error))
return FALSE;
}
else if (strcmp (key, "display-hint") == 0)
else if (strcmp (key, "display-hint") == 0 && impl_version > 1)
{
if (!parse_display_hint (builder, value, error))
return FALSE;
}
else if (strcmp (key, "category") == 0)
else if (strcmp (key, "category") == 0 && impl_version > 1)
{
if (!parse_category (builder, value, error))
return FALSE;
Expand Down
10 changes: 10 additions & 0 deletions src/xdp-sealed-fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,13 @@ xdp_sealed_fd_dup_fd (XdpSealedFd *sealed_fd)

return dup (sealed_fd->fd);
}

GBytes *
xdp_sealed_fd_get_bytes (XdpSealedFd *sealed_fd,
GError **error)
{
g_autoptr(GMappedFile) mapped = NULL;

mapped = g_mapped_file_new_from_fd (sealed_fd->fd, FALSE, error);
return g_mapped_file_get_bytes (mapped);
}
2 changes: 2 additions & 0 deletions src/xdp-sealed-fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ XdpSealedFd * xdp_sealed_fd_new_from_handle (GVariant *handle,
int xdp_sealed_fd_get_fd (XdpSealedFd *sealed_fd);
int xdp_sealed_fd_dup_fd (XdpSealedFd *sealed_fd);

GBytes *xdp_sealed_fd_get_bytes (XdpSealedFd *sealed_fd,
GError **error);

0 comments on commit 2e8860a

Please sign in to comment.