mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-28 10:07:13 +02:00
notification: Don't send file icons to the portal
The notification portal only accept themed icons and bytes icons, so convert file icons to bytes before sending notifications to the portal. This was pointed out in https://github.com/flatpak/xdg-desktop-portal/issues/317
This commit is contained in:
@@ -25,6 +25,9 @@
|
|||||||
#include "gapplication.h"
|
#include "gapplication.h"
|
||||||
#include "gnotification-private.h"
|
#include "gnotification-private.h"
|
||||||
#include "gportalsupport.h"
|
#include "gportalsupport.h"
|
||||||
|
#include "gfileicon.h"
|
||||||
|
#include "gfile.h"
|
||||||
|
#include "gbytesicon.h"
|
||||||
|
|
||||||
#define G_TYPE_PORTAL_NOTIFICATION_BACKEND (g_portal_notification_backend_get_type ())
|
#define G_TYPE_PORTAL_NOTIFICATION_BACKEND (g_portal_notification_backend_get_type ())
|
||||||
#define G_PORTAL_NOTIFICATION_BACKEND(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_PORTAL_NOTIFICATION_BACKEND, GPortalNotificationBackend))
|
#define G_PORTAL_NOTIFICATION_BACKEND(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_PORTAL_NOTIFICATION_BACKEND, GPortalNotificationBackend))
|
||||||
@@ -55,6 +58,29 @@ g_portal_notification_backend_send_notification (GNotificationBackend *backend,
|
|||||||
const gchar *id,
|
const gchar *id,
|
||||||
GNotification *notification)
|
GNotification *notification)
|
||||||
{
|
{
|
||||||
|
GIcon *icon;
|
||||||
|
|
||||||
|
icon = g_notification_get_icon (notification);
|
||||||
|
if (G_IS_FILE_ICON (icon))
|
||||||
|
{
|
||||||
|
GFile *file;
|
||||||
|
GBytes *bytes;
|
||||||
|
|
||||||
|
/* convert a file icon to a bytes icon before
|
||||||
|
* sending the notification, since the portal
|
||||||
|
* will accept the latter, but not the former.
|
||||||
|
*/
|
||||||
|
file = g_file_icon_get_file (G_FILE_ICON (icon));
|
||||||
|
bytes = g_file_load_bytes (file, NULL, NULL, NULL);
|
||||||
|
if (bytes)
|
||||||
|
{
|
||||||
|
icon = g_bytes_icon_new (bytes);
|
||||||
|
g_notification_set_icon (notification, icon);
|
||||||
|
g_object_unref (icon);
|
||||||
|
g_bytes_unref (bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_dbus_connection_call (backend->dbus_connection,
|
g_dbus_connection_call (backend->dbus_connection,
|
||||||
"org.freedesktop.portal.Desktop",
|
"org.freedesktop.portal.Desktop",
|
||||||
"/org/freedesktop/portal/desktop",
|
"/org/freedesktop/portal/desktop",
|
||||||
|
Reference in New Issue
Block a user