Skip to content

Commit

Permalink
load portals from XDG_DATA_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
andychenbruce committed Jan 9, 2025
1 parent 34ff12c commit e6c009a
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/xdp-portal-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "xdp-portal-impl.h"

#include <stdio.h>
#include <stdbool.h>
#include <string.h>

#include <glib.h>
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e6c009a

Please sign in to comment.