From 36ef9be395b07b8224cd95c3f9b0c821ce4b1e5e Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Fri, 10 May 2024 21:01:34 +0100 Subject: [PATCH] portal-impl: Use fallback portals for Settings as well Since 1.18.2, we have a hardcoded fallback to xdg-desktop-portal-gtk as a last resort if no other portal is defined by a configuration file. This fallback mechanism, however, isn't implemented for the org.freedesktop.impl.portal.Settings interface. The consequence is that everything seems to work just fine, but user preferences like color scheme are ignored in applications that use the portal API to retrieve them (not just flatpak apps, also libadwaita apps). That comes as a surprise to users; and since the portal stuff otherwise works fine, it's not entirely straightforward to figure out that configuring portal.conf would fix it. I believe that if find_portal_implementation implements fallbacks, so should find_all_portal_implementations, for consistency and to avoid surprises. The fallback logic this commit implements closely resembles the logic in find_portal_implementation: we don't look for fallbacks if there is a portal configured in portals.conf (or if portals.conf explicitly says there should be none), and we only use the x-d-p-gtk as a last resort if we haven't found any impl(s) using the legacy UseIn key. (The above should be a self-contained description but there's some additional thoughts at https://github.com/flatpak/xdg-desktop-portal/pull/1199#issuecomment-2093902804) Fixes: d18c563b6a34 ("portal-impl: Hard-code x-d-p-gtk as a last-resort fallback") Related: https://github.com/flatpak/xdg-desktop-portal/issues/1102 --- src/portal-impl.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/portal-impl.c b/src/portal-impl.c index bf3f2b690..0c03c3acc 100644 --- a/src/portal-impl.c +++ b/src/portal-impl.c @@ -719,7 +719,10 @@ find_portal_implementation (const char *interface) GPtrArray * find_all_portal_implementations (const char *interface) { + const char **desktops; GPtrArray *impls; + GList *l; + int i; impls = g_ptr_array_new (); @@ -741,5 +744,56 @@ find_all_portal_implementations (const char *interface) } } + if (impls->len > 0) + return impls; + + desktops = get_current_lowercase_desktops (); + + /* Fallback to the old UseIn key */ + for (i = 0; desktops[i] != NULL; i++) + { + for (l = implementations; l != NULL; l = l->next) + { + PortalImplementation *impl = l->data; + + if (!portal_impl_supports_iface (impl, interface)) + continue; + + if (impl->use_in != NULL && g_strv_case_contains ((const char **)impl->use_in, desktops[i])) + { + g_warning ("Choosing %s.portal for %s via the deprecated UseIn key", + impl->source, interface); + warn_please_use_portals_conf (); + g_debug ("Using %s.portal for %s in %s (fallback)", impl->source, interface, desktops[i]); + g_ptr_array_add (impls, impl); + } + } + } + + if (impls->len > 0) + return impls; + + /* As a last resort, if nothing was selected for this desktop by + * ${desktop}-portals.conf or portals.conf, and no portal volunteered + * itself as suitable for this desktop via the legacy UseIn mechanism, + * try to fall back to x-d-p-gtk, which has historically been the portal + * UI backend used by desktop environments with no backend of their own. + * If it isn't installed, that is not an error: we just don't use it. */ + for (l = implementations; l != NULL; l = l->next) + { + PortalImplementation *impl = l->data; + + if (!g_str_equal (impl->dbus_name, "org.freedesktop.impl.portal.desktop.gtk")) + continue; + + if (!portal_impl_supports_iface (impl, interface)) + continue; + + g_warning ("Choosing %s.portal for %s as a last-resort fallback", + impl->source, interface); + warn_please_use_portals_conf (); + g_ptr_array_add (impls, impl); + } + return impls; }