From e5caf21bcb3354cdd3837104892a1ac9eac9964b Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Sun, 10 Apr 2022 15:31:27 +0200 Subject: [PATCH] pickbutton: Add version check for XDG portal `PickColor()` API only got added in version 2, so check for that before trying to use it. --- libgimpwidgets/gimppickbutton-xdg.c | 40 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/libgimpwidgets/gimppickbutton-xdg.c b/libgimpwidgets/gimppickbutton-xdg.c index 3b3dcee33a..05a225593b 100644 --- a/libgimpwidgets/gimppickbutton-xdg.c +++ b/libgimpwidgets/gimppickbutton-xdg.c @@ -36,7 +36,9 @@ gboolean _gimp_pick_button_xdg_available (void) { - GDBusProxy *proxy = NULL; + gboolean ret = TRUE; + GDBusProxy *proxy = NULL; + GVariant *version = NULL; proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, @@ -46,24 +48,30 @@ _gimp_pick_button_xdg_available (void) "org.freedesktop.portal.Screenshot", NULL, NULL); - if (proxy) + if (proxy == NULL) { - GError *error = NULL; - - g_dbus_proxy_call_sync (proxy, "org.freedesktop.DBus.Peer.Ping", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); - if (! error) - return TRUE; - - g_clear_error (&error); - - g_object_unref (proxy); - proxy = NULL; + ret = FALSE; + goto out; } - return FALSE; + /* Finally, PickColor is only available starting V2 of the portal */ + version = g_dbus_proxy_get_cached_property (proxy, "version"); + if (version == NULL) + { + ret = FALSE; + goto out; + } + + if (g_variant_get_uint32 (version) < 2) + { + ret = FALSE; + goto out; + } + +out: + g_clear_pointer (&version, g_variant_unref); + g_clear_object (&proxy); + return ret; } static void