portal: Add a getter for dconf access

Add method to find whether the sandbox provides
access to dconf. This will be used to tweak
the priorities for the keyfile settings backend.
This commit is contained in:
Matthias Clasen 2019-07-12 11:30:30 -04:00 committed by Michael Catanzaro
parent 98f598b665
commit 0bc4825443
2 changed files with 19 additions and 0 deletions

View File

@ -23,6 +23,7 @@
static gboolean flatpak_info_read;
static gboolean use_portal;
static gboolean network_available;
static gboolean dconf_access;
static void
read_flatpak_info (void)
@ -40,11 +41,13 @@ read_flatpak_info (void)
use_portal = TRUE;
network_available = FALSE;
dconf_access = FALSE;
keyfile = g_key_file_new ();
if (g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL))
{
char **shared = NULL;
char *dconf_policy = NULL;
shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL);
if (shared)
@ -52,6 +55,14 @@ read_flatpak_info (void)
network_available = g_strv_contains ((const char * const *)shared, "network");
g_strfreev (shared);
}
dconf_policy = g_key_file_get_string (keyfile, "Session Bus Policy", "ca.desrt.dconf", NULL);
if (dconf_policy)
{
if (strcmp (dconf_policy, "talk") == 0)
dconf_access = TRUE;
g_free (dconf_policy);
}
}
g_key_file_unref (keyfile);
@ -64,6 +75,7 @@ read_flatpak_info (void)
if (var && var[0] == '1')
use_portal = TRUE;
network_available = TRUE;
dconf_access = TRUE;
}
}
@ -81,3 +93,9 @@ glib_network_available_in_sandbox (void)
return network_available;
}
gboolean
glib_has_dconf_access_in_sandbox (void)
{
read_flatpak_info ();
return dconf_access;
}

View File

@ -24,6 +24,7 @@ G_BEGIN_DECLS
gboolean glib_should_use_portal (void);
gboolean glib_network_available_in_sandbox (void);
gboolean glib_has_dconf_access_in_sandbox (void);
G_END_DECLS