diff --git a/gio/gportalnotificationbackend.c b/gio/gportalnotificationbackend.c index 819358f64..0c579adb1 100644 --- a/gio/gportalnotificationbackend.c +++ b/gio/gportalnotificationbackend.c @@ -799,6 +799,35 @@ serialize_display_hint (GNotification *notification) return g_variant_builder_end (&builder); } +static GVariant * +serialize_category (GNotification *notification) +{ + const char *category; + const char *supported_categories[] = { + G_NOTIFICATION_CATEGORY_IM_RECEIVED, + G_NOTIFICATION_CATEGORY_ALARM_RINGING, + G_NOTIFICATION_CATEGORY_CALL_INCOMING, + G_NOTIFICATION_CATEGORY_CALL_OUTGOING, + G_NOTIFICATION_CATEGORY_CALL_UNANSWERED, + G_NOTIFICATION_CATEGORY_WEATHER_WARNING_EXTREME, + G_NOTIFICATION_CATEGORY_CELLBROADCAST_DANGER_SEVERE, + G_NOTIFICATION_CATEGORY_CELLBROADCAST_AMBER_ALERT, + G_NOTIFICATION_CATEGORY_CELLBROADCAST_TEST, + G_NOTIFICATION_CATEGORY_OS_BATTERY_LOW, + G_NOTIFICATION_CATEGORY_BROWSER_WEB_NOTIFICATION, + NULL + }; + + category = g_notification_get_category (notification); + + /* The portal fails if we give categories that aren't supported that + * don't start with the x-vendor prefix prefix */ + if (category && (g_strv_contains (supported_categories, category) || g_str_has_prefix (category, "x-"))) + return g_variant_new_string (category); + + return NULL; +} + static void serialize_notification (const char *id, GNotification *notification, @@ -812,6 +841,7 @@ serialize_notification (const char *id, const gchar *markup_body; GIcon *icon; GVariant *display_hint = NULL; + GVariant *category; gchar *default_action = NULL; GVariant *default_action_target = NULL; GVariant *buttons = NULL; @@ -865,6 +895,9 @@ serialize_notification (const char *id, if ((display_hint = serialize_display_hint (notification))) g_variant_builder_add (data->builder, "{sv}", "display-hint", display_hint); + if ((category = serialize_category (notification))) + g_variant_builder_add (data->builder, "{sv}", "category", category); + if (g_notification_get_default_action (notification, &default_action, &default_action_target)) { g_variant_builder_add (data->builder, "{sv}", "default-action",