[gnome-software/1166-repository-dialog-design-updates: 66/73] flatpak: Extract scope ensure code into a separate function




commit 495576446b947c9ddb7ffdd3f301599e29d7d134
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 27 15:14:48 2021 +0200

    flatpak: Extract scope ensure code into a separate function
    
    Will be used on multiple places later.

 plugins/flatpak/gs-plugin-flatpak.c | 40 ++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 16 deletions(-)
---
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 1cd2b9d6a..f9532c370 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -929,13 +929,35 @@ app_has_local_source (GsApp *app)
        return FALSE;
 }
 
+static void
+gs_plugin_flatpak_ensure_scope (GsPlugin *plugin,
+                               GsApp *app)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+
+       if (gs_app_get_scope (app) == AS_COMPONENT_SCOPE_UNKNOWN) {
+               g_autoptr(GSettings) settings = g_settings_new ("org.gnome.software");
+
+               /* get the new GsFlatpak for handling of local files */
+               gs_app_set_scope (app, g_settings_get_boolean (settings, "install-bundles-system-wide") ?
+                                       AS_COMPONENT_SCOPE_SYSTEM : AS_COMPONENT_SCOPE_USER);
+               if (!priv->has_system_helper) {
+                       g_info ("no flatpak system helper is available, using user");
+                       gs_app_set_scope (app, AS_COMPONENT_SCOPE_USER);
+               }
+               if (priv->destdir_for_tests != NULL) {
+                       g_debug ("in self tests, using user");
+                       gs_app_set_scope (app, AS_COMPONENT_SCOPE_USER);
+               }
+       }
+}
+
 gboolean
 gs_plugin_app_install (GsPlugin *plugin,
                       GsApp *app,
                       GCancellable *cancellable,
                       GError **error)
 {
-       GsPluginData *priv = gs_plugin_get_data (plugin);
        GsFlatpak *flatpak;
        g_autoptr(FlatpakTransaction) transaction = NULL;
        g_autoptr(GError) error_local = NULL;
@@ -950,21 +972,7 @@ gs_plugin_app_install (GsPlugin *plugin,
        }
 
        /* set the app scope */
-       if (gs_app_get_scope (app) == AS_COMPONENT_SCOPE_UNKNOWN) {
-               g_autoptr(GSettings) settings = g_settings_new ("org.gnome.software");
-
-               /* get the new GsFlatpak for handling of local files */
-               gs_app_set_scope (app, g_settings_get_boolean (settings, "install-bundles-system-wide") ?
-                                       AS_COMPONENT_SCOPE_SYSTEM : AS_COMPONENT_SCOPE_USER);
-               if (!priv->has_system_helper) {
-                       g_info ("no flatpak system helper is available, using user");
-                       gs_app_set_scope (app, AS_COMPONENT_SCOPE_USER);
-               }
-               if (priv->destdir_for_tests != NULL) {
-                       g_debug ("in self tests, using user");
-                       gs_app_set_scope (app, AS_COMPONENT_SCOPE_USER);
-               }
-       }
+       gs_plugin_flatpak_ensure_scope (plugin, app);
 
        /* not supported */
        flatpak = gs_plugin_flatpak_get_handler (plugin, app);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]