From e6c009a37a149b8e57d6829e9c692aca36de88de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=8A=9F?= Date: Thu, 9 Jan 2025 13:22:40 -0800 Subject: [PATCH] load portals from XDG_DATA_DIR --- src/xdp-portal-impl.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/xdp-portal-impl.c b/src/xdp-portal-impl.c index 770c265ad..ec2c329a5 100644 --- a/src/xdp-portal-impl.c +++ b/src/xdp-portal-impl.c @@ -26,6 +26,7 @@ #include "xdp-portal-impl.h" #include +#include #include #include @@ -269,16 +270,11 @@ sort_impl_by_use_in_and_name (gconstpointer a, } void -load_installed_portals (gboolean opt_verbose) +load_installed_portals_dir (gboolean opt_verbose, + const char *portal_dir) { g_autoptr(GFileEnumerator) enumerator = NULL; g_autoptr(GFile) dir = NULL; - const char *portal_dir; - - /* We need to override this in the tests */ - portal_dir = g_getenv ("XDG_DESKTOP_PORTAL_DIR"); - if (portal_dir == NULL) - portal_dir = DATADIR "/xdg-desktop-portal/portals"; g_debug ("load portals from %s", portal_dir); @@ -319,6 +315,32 @@ load_installed_portals (gboolean opt_verbose) implementations = g_list_sort (implementations, sort_impl_by_use_in_and_name); } +void +load_installed_portals (gboolean opt_verbose) +{ + const char * const *iter; + const char *portal_dir; + + /* We need to override this in the tests */ + portal_dir = g_getenv ("XDG_DESKTOP_PORTAL_DIR"); + bool dir_set_from_env = (portal_dir == NULL); + if (portal_dir == NULL) + portal_dir = DATADIR "/xdg-desktop-portal/portals"; + + load_installed_portals_dir(opt_verbose, portal_dir); + + if(dir_set_from_env) + return; + + const char * const *dirs = g_get_system_data_dirs (); + + for (iter = dirs; iter != NULL && *iter != NULL; iter++) + { + g_autofree char *dir = g_build_filename (*iter, "xdg-desktop-portal", "portals", NULL); + load_installed_portals_dir(opt_verbose, dir); + } +} + static PortalConfig * load_portal_configuration_for_dir (gboolean opt_verbose, const char *base_directory,