[gnome-software/wip/jrocha/fix-startup: 4/6] Fix app creation from the plugin loader



commit 050c0b8cca3567dec4f2740893becef52177303d
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Mon Oct 16 14:37:59 2017 +0200

    Fix app creation from the plugin loader
    
    Plugins like the Flatpak one use their own specialized type of GsApp.
    However, when apps are created using the plugin-loader's app creation
    function, they will be regular GsApps and thus incompatible with the
    mentioned plugins.
    
    In order to fix this, this patch first creates the GsApp as usually,
    then it checks if a plugin wants to adopt it, and if there's one that
    does, it will re-create the app using the plugin's app creation function
    instead. This is not very efficient but with the current architecture
    design, we need to do it like this.

 lib/gs-plugin-loader.c |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 3820c2f..5faf35c 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -447,9 +447,10 @@ gs_plugin_error_handle_failure (GsPluginLoaderHelper *helper,
        return TRUE;
 }
 
-static void
+static GsPlugin *
 gs_plugin_loader_run_adopt (GsPluginLoader *plugin_loader, GsAppList *list)
 {
+       GsPlugin *adopter = NULL;
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        guint i;
        guint j;
@@ -474,6 +475,7 @@ gs_plugin_loader_run_adopt (GsPluginLoader *plugin_loader, GsAppList *list)
                                g_debug ("%s adopted %s",
                                         gs_plugin_get_name (plugin),
                                         gs_app_get_unique_id (app));
+                               adopter = plugin;
                        }
                }
        }
@@ -485,6 +487,8 @@ gs_plugin_loader_run_adopt (GsPluginLoader *plugin_loader, GsAppList *list)
                        continue;
                g_debug ("nothing adopted %s", gs_app_get_unique_id (app));
        }
+
+       return adopter;
 }
 
 static gint
@@ -3633,6 +3637,8 @@ GsApp *
 gs_plugin_loader_app_create (GsPluginLoader *plugin_loader, const gchar *unique_id)
 {
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       GsPlugin *plugin = NULL;
+       g_autoptr(GsAppList) list = NULL;
        GsApp *app;
 
        /* already exists */
@@ -3643,6 +3649,24 @@ gs_plugin_loader_app_create (GsPluginLoader *plugin_loader, const gchar *unique_
        /* create and add */
        app = gs_app_new (NULL);
        gs_app_set_from_unique_id (app, unique_id);
+
+       list = gs_app_list_new ();
+       gs_app_list_add (list, app);
+
+       /* XXX: plugins like the Flatpak one only operate over their own type of
+        * apps, thus we should check if any plugin wants to adopt the app, and
+        * then create a new app with the type desired by that plugin; otherwise
+        * e.g. the Flatpak plugin won't refine any apps that have not been created
+        * with its desired type;
+        * this is a bit clumbersome but ATM it's the fastest way to ensure we use the
+        * right type for the apps */
+       plugin = gs_plugin_loader_run_adopt (plugin_loader, list);
+       if (plugin != NULL) {
+               g_object_unref (app);
+               app = gs_plugin_app_new (plugin, NULL);
+               gs_app_set_from_unique_id (app, unique_id);
+       }
+
        gs_app_list_add (priv->global_cache, app);
        return app;
 }


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