Skip to content

Commit

Permalink
notification: Deprecate bytes option for icons
Browse files Browse the repository at this point in the history
Since we now have the option to give a file-descriptor there is no need
for moving binary data across D-Bus. This also ensures backwards
compatibility by converting the icon property's `bytes` option to
the `file-descriptor` option.
  • Loading branch information
jsparber committed Oct 17, 2024
1 parent 2e8860a commit 1e65575
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
2 changes: 2 additions & 0 deletions data/org.freedesktop.impl.portal.Notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
The format of the @notification is the same as for
:ref:`org.freedesktop.portal.Notification.AddNotification`.
Since version 2, the icon property never uses the ``bytes`` option.
-->
<method name="AddNotification">
<annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
Expand Down
3 changes: 3 additions & 0 deletions data/org.freedesktop.portal.Notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
* ``bytes`` (``ay``)
Since version 2, this is deprecated and should not be used.
Please use the `themed` or `file-descriptor` option to set an icon.
A bytes icon containing a bytestring with the icon data in
png, jpeg or svg form.
Expand Down
27 changes: 25 additions & 2 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,28 @@ parse_serialized_icon (GVariantBuilder *builder,
sealed_icon = xdp_sealed_fd_new_from_bytes (icon_bytes, &local_error);

if (!sealed_icon)
g_warning ("Failed to read icon: %s", local_error->message);
{
g_warning ("Failed to read icon: %s", local_error->message);
}
else if (xdp_validate_icon (sealed_icon, XDP_ICON_TYPE_NOTIFICATION, NULL, NULL))
g_variant_builder_add (builder, "{sv}", "icon", icon);
{
/* Since version 2 we only use file-descriptor icon */
if (impl_version > 1)
{
g_autoptr(GVariant) fd_icon = NULL;

fd_icon = xdp_sealed_fd_to_handle (sealed_icon, fd_list, &local_error);

if (!fd_icon)
g_warning ("Failed to get create file-descriptor icon from bytes icon: %s", local_error->message);

g_variant_builder_add (builder, "{sv}", "icon", fd_icon);
}
else
{
g_variant_builder_add (builder, "{sv}", "icon", icon);
}
}
}
else if (strcmp (key, "file-descriptor") == 0)
{
Expand Down Expand Up @@ -1027,8 +1046,12 @@ notification_handle_add_notification (XdpDbusNotification *object,
{
Call *call = call_from_invocation (invocation);
g_autoptr(GTask) task = NULL;
g_autoptr(GUnixFDList) empty_fd_list = NULL;
CallData *call_data;

if (!fd_list)
fd_list = empty_fd_list = g_unix_fd_list_new ();

call_data = call_data_new (invocation,
call->app_info,
call->sender,
Expand Down
18 changes: 18 additions & 0 deletions src/xdp-sealed-fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,21 @@ xdp_sealed_fd_get_bytes (XdpSealedFd *sealed_fd,
mapped = g_mapped_file_new_from_fd (sealed_fd->fd, FALSE, error);
return g_mapped_file_get_bytes (mapped);
}

GVariant *
xdp_sealed_fd_to_handle (XdpSealedFd *sealed_fd,
GUnixFDList *fd_list,
GError **error)
{
int fd_out;

g_return_val_if_fail (XDP_IS_SEALED_FD (sealed_fd), NULL);
g_return_val_if_fail (G_IS_UNIX_FD_LIST (fd_list), NULL);

fd_out = g_unix_fd_list_append (fd_list, sealed_fd->fd, error);

if (fd_out == -1)
return NULL;

return g_variant_ref_sink (g_variant_new ("(sv)", "file-descriptor", g_variant_new_handle (fd_out)));
}
3 changes: 3 additions & 0 deletions src/xdp-sealed-fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ int xdp_sealed_fd_dup_fd (XdpSealedFd *sealed_fd);

GBytes *xdp_sealed_fd_get_bytes (XdpSealedFd *sealed_fd,
GError **error);
GVariant *xdp_sealed_fd_to_handle (XdpSealedFd *sealed_fd,
GUnixFDList *fd_list,
GError **error);
2 changes: 1 addition & 1 deletion tests/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ test_bytes_icon (void)
serialized_icon = g_icon_serialize (icon);

serialized_icon_s = g_variant_print (serialized_icon, TRUE);
test_icon (serialized_icon_s, NULL, FALSE);
test_icon (serialized_icon_s, "('file-descriptor', <handle 0>)", FALSE);
}

static void
Expand Down

0 comments on commit 1e65575

Please sign in to comment.