mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-09-19 13:30:02 +00:00
a11y: Use session bus to check Flatpak portal
The Flatpak portal (and so far all other portals) live in the session bus, not in the a11y bus. Use the session bus to get the Flatpak portal version. Avoid too many synchronous D-Bus calls on startup by using g_once_init_* helpers.
This commit is contained in:
parent
24841a8d5b
commit
1ffd23dbab
@ -594,14 +594,31 @@ on_event_listener_deregistered (GDBusConnection *connection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
check_flatpak_portal_version (GDBusConnection *connection,
|
check_flatpak_portal_version (unsigned int minimum_version)
|
||||||
unsigned int minimum_version)
|
|
||||||
{
|
{
|
||||||
GVariant *child;
|
static uint32_t flatpak_portal_version = 0;
|
||||||
GError *error = NULL;
|
static size_t initialized = 0;
|
||||||
|
|
||||||
GVariant *res =
|
if (g_once_init_enter (&initialized))
|
||||||
g_dbus_connection_call_sync (connection,
|
{
|
||||||
|
GDBusConnection *session_bus;
|
||||||
|
GError *error = NULL;
|
||||||
|
GVariant *child;
|
||||||
|
GVariant *res;
|
||||||
|
|
||||||
|
session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||||
|
|
||||||
|
if (error != NULL)
|
||||||
|
{
|
||||||
|
g_warning ("Unable to retrieve the session bus: %s",
|
||||||
|
error->message);
|
||||||
|
g_clear_error (&error);
|
||||||
|
g_once_init_leave (&initialized, 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
res =
|
||||||
|
g_dbus_connection_call_sync (session_bus,
|
||||||
"org.freedesktop.portal.Flatpak",
|
"org.freedesktop.portal.Flatpak",
|
||||||
"/org/freedesktop/portal/Flatpak",
|
"/org/freedesktop/portal/Flatpak",
|
||||||
"org.freedesktop.DBus.Properties",
|
"org.freedesktop.DBus.Properties",
|
||||||
@ -618,18 +635,22 @@ check_flatpak_portal_version (GDBusConnection *connection,
|
|||||||
g_warning ("Unable to retrieve the Flatpak portal version: %s",
|
g_warning ("Unable to retrieve the Flatpak portal version: %s",
|
||||||
error->message);
|
error->message);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
|
g_once_init_leave (&initialized, 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_variant_get (res, "(v)", &child);
|
g_variant_get (res, "(v)", &child);
|
||||||
g_variant_unref (res);
|
g_variant_unref (res);
|
||||||
|
|
||||||
guint32 version = g_variant_get_uint32 (child);
|
flatpak_portal_version = g_variant_get_uint32 (child);
|
||||||
g_variant_unref (child);
|
g_variant_unref (child);
|
||||||
|
|
||||||
GTK_DEBUG (A11Y, "Flatpak portal version: %u (required: %u)", version, minimum_version);
|
g_once_init_leave (&initialized, 1);
|
||||||
|
}
|
||||||
|
|
||||||
return version >= minimum_version;
|
GTK_DEBUG (A11Y, "Flatpak portal version: %u (required: %u)", flatpak_portal_version, minimum_version);
|
||||||
|
|
||||||
|
return flatpak_portal_version >= minimum_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -749,7 +770,7 @@ on_registration_reply (GObject *gobject,
|
|||||||
* check if the version of the Flatpak portal is recent enough.
|
* check if the version of the Flatpak portal is recent enough.
|
||||||
*/
|
*/
|
||||||
if (gdk_should_use_portal () &&
|
if (gdk_should_use_portal () &&
|
||||||
!check_flatpak_portal_version (self->connection, 7))
|
!check_flatpak_portal_version (7))
|
||||||
{
|
{
|
||||||
GTK_DEBUG (A11Y, "Sandboxed does not allow event listener registration");
|
GTK_DEBUG (A11Y, "Sandboxed does not allow event listener registration");
|
||||||
self->can_use_event_listeners = false;
|
self->can_use_event_listeners = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user