[gnome-software] Use the same app instance when using --install= and the regular plugin methods



commit 7094e1b435c0d8bffa0e1ebaf52d2f26c753c9bb
Author: Richard Hughes <richard hughsie com>
Date:   Fri Jan 13 15:12:31 2017 +0000

    Use the same app instance when using --install= and the regular plugin methods
    
    Based on a patch from Mario Sanchez Prada <mario endlessm com>, many thanks.

 src/gs-application.c   |    4 ++--
 src/gs-plugin-loader.c |   26 ++++++++++++++++++++++++++
 src/gs-plugin-loader.h |    2 ++
 3 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 0f57dbd..ae7b92a 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -543,7 +543,7 @@ details_activated (GSimpleAction *action,
                g_autoptr (GsApp) a = NULL;
 
                if (as_utils_unique_id_valid (id))
-                       a = gs_app_new_from_unique_id (id);
+                       a = gs_plugin_loader_app_create (app->plugin_loader, id);
                else
                        a = gs_app_new (id);
 
@@ -587,7 +587,7 @@ install_activated (GSimpleAction *action,
        else
                gs_application_initialize_ui (app);
 
-       a = gs_app_new_from_unique_id (id);
+       a = gs_plugin_loader_app_create (app->plugin_loader, id);
        if (a == NULL) {
                g_warning ("Could not create app from unique-id: %s", id);
                return;
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 797cb6f..472ceaa 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -4579,6 +4579,32 @@ gs_plugin_loader_get_plugin_supported (GsPluginLoader *plugin_loader,
        return FALSE;
 }
 
+/**
+ * gs_plugin_loader_app_create:
+ * @plugin_loader: a #GsPluginLoader
+ * @unique_id: a unique_id
+ *
+ * Returns an application from the global cache, creating if required.
+ *
+ * Returns: (transfer full): a #GsApp
+ **/
+GsApp *
+gs_plugin_loader_app_create (GsPluginLoader *plugin_loader, const gchar *unique_id)
+{
+       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       GsApp *app;
+
+       /* already exists */
+       app = gs_app_list_lookup (priv->global_cache, unique_id);
+       if (app != NULL)
+               return g_object_ref (app);
+
+       /* create and add */
+       app = gs_app_new_from_unique_id (unique_id);
+       gs_app_list_add (priv->global_cache, app);
+       return app;
+}
+
 /******************************************************************************/
 
 AsProfile *
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index bbb7479..c7507e5 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -264,6 +264,8 @@ GsPluginEvent       *gs_plugin_loader_get_event_default     (GsPluginLoader *plugin_loader
 void            gs_plugin_loader_remove_events         (GsPluginLoader *plugin_loader);
 
 AsProfile      *gs_plugin_loader_get_profile           (GsPluginLoader *plugin_loader);
+GsApp          *gs_plugin_loader_app_create            (GsPluginLoader *plugin_loader,
+                                                        const gchar    *unique_id);
 
 G_END_DECLS
 


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