[gnome-software] Do not filter the resolve and action vfuncs by management plugin



commit ef68a1593c211150ac6c05636517304b6b107ef6
Author: Richard Hughes <richard hughsie com>
Date:   Wed Apr 13 20:34:51 2016 +0100

    Do not filter the resolve and action vfuncs by management plugin
    
    Also, add the concept of plugins 'adopting' unknown apps so they can be handled
    exclusively by the plugin.
    
    This was too restrictive and did not allow plugins to work as intended.

 src/gs-plugin-loader.c                    |   75 ++++++++++++++++++-----------
 src/gs-plugin.h                           |    4 ++
 src/plugins/gs-appstream.c                |   11 +----
 src/plugins/gs-plugin-dummy.c             |    9 ++++
 src/plugins/gs-plugin-epiphany.c          |   40 ++++++++++++---
 src/plugins/gs-plugin-fwupd.c             |   18 +++++++
 src/plugins/gs-plugin-limba.c             |   10 ++++-
 src/plugins/gs-plugin-ostree.c            |    2 +-
 src/plugins/gs-plugin-packagekit-refine.c |   22 ++++++++-
 src/plugins/gs-plugin-packagekit.c        |   25 +++++++++-
 src/plugins/gs-plugin-shell-extensions.c  |   22 ++++++++-
 src/plugins/gs-plugin-steam.c             |   12 +++++
 src/plugins/gs-plugin-systemd-updates.c   |   13 +++++-
 src/plugins/gs-plugin-xdg-app.c           |   32 +++++++++++-
 14 files changed, 240 insertions(+), 55 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index bcea965..a05b419 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -111,6 +111,41 @@ gs_plugin_loader_app_sort_cb (gconstpointer a, gconstpointer b)
 }
 
 /**
+ * gs_plugin_loader_run_adopt:
+ **/
+static void
+gs_plugin_loader_run_adopt (GsPluginLoader *plugin_loader, GList *list)
+{
+       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       GList *l;
+       guint i;
+
+       /* go through each plugin in priority order */
+       for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginAdoptAppFunc adopt_app_func = NULL;
+               GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
+               if (!plugin->enabled)
+                       continue;
+               g_module_symbol (plugin->module, "gs_plugin_adopt_app",
+                                (gpointer *) &adopt_app_func);
+               if (adopt_app_func == NULL)
+                       continue;
+               for (l = list; l != NULL; l = l->next) {
+                       GsApp *app = GS_APP (l->data);
+                       if (gs_app_get_management_plugin (app) != NULL)
+                               continue;
+                       g_rw_lock_reader_lock (&plugin->rwlock);
+                       adopt_app_func (plugin, app);
+                       g_rw_lock_reader_unlock (&plugin->rwlock);
+                       if (gs_app_get_management_plugin (app) != NULL) {
+                               g_debug ("%s adopted %s", plugin->name,
+                                        gs_app_get_id (app));
+                       }
+               }
+       }
+}
+
+/**
  * gs_plugin_loader_run_refine:
  **/
 static gboolean
@@ -140,6 +175,9 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
        for (l = freeze_list; l != NULL; l = l->next)
                g_object_freeze_notify (G_OBJECT (l->data));
 
+       /* try to adopt each application with a plugin */
+       gs_plugin_loader_run_adopt (plugin_loader, *list);
+
        /* run each plugin */
        for (i = 0; i < priv->plugins->len; i++) {
                GsPluginRefineAppFunc plugin_app_func = NULL;
@@ -258,6 +296,15 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
                                goto out;
                }
        }
+
+       /* show a warning if nothing adopted this */
+       for (l = *list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (gs_app_get_management_plugin (app) != NULL)
+                       continue;
+               g_warning ("nothing adopted %s", gs_app_get_id (app));
+               g_print ("%s", gs_app_to_string (app));
+       }
 out:
        /* now emit all the changed signals */
        for (l = freeze_list; l != NULL; l = l->next)
@@ -582,15 +629,11 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
        GsPluginActionFunc plugin_func = NULL;
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        GsPlugin *plugin;
-       const gchar *management_plugin;
        gboolean anything_ran = FALSE;
        gboolean exists;
        gboolean ret;
        guint i;
 
-       /* don't force each plugin to check this */
-       management_plugin = gs_app_get_management_plugin (app);
-
        /* run each plugin */
        for (i = 0; i < priv->plugins->len; i++) {
                g_autoptr(AsProfileTask) ptask = NULL;
@@ -606,14 +649,6 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
                                          (gpointer *) &plugin_func);
                if (!exists)
                        continue;
-
-               /* only run method for the correct management plugin */
-               if (g_strcmp0 (management_plugin, plugin->name) != 0) {
-                       g_debug ("skipping %s:%s as invalid (%s)",
-                                plugin->name, function_name, management_plugin);
-                       continue;
-               }
-
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
@@ -631,13 +666,6 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
-       /* fall back to generic helper */
-       if (!anything_ran &&
-           g_strcmp0 (function_name, "gs_plugin_launch") == 0) {
-               g_debug ("using launch helper for %s", gs_app_get_id (app));
-               return gs_plugin_app_launch (NULL, app, error);
-       }
-
        /* nothing ran */
        if (!anything_ran) {
                g_set_error (error,
@@ -3893,18 +3921,9 @@ gs_plugin_loader_update_thread_cb (GTask *task,
                /* for each app */
                for (l = state->list; l != NULL; l = l->next) {
                        GsApp *app = GS_APP (l->data);
-                       const gchar *management_plugin;
                        g_autoptr(AsProfileTask) ptask = NULL;
                        g_autoptr(GError) error_local = NULL;
 
-                       /* only run method for the correct plugin */
-                       management_plugin = gs_app_get_management_plugin (app);
-                       if (g_strcmp0 (management_plugin, plugin->name) != 0) {
-                               g_debug ("skipping %s:%s as invalid (%s)",
-                                        plugin->name, function_name, management_plugin);
-                               continue;
-                       }
-
                        ptask = as_profile_start (priv->profile,
                                                  "GsPlugin::%s(%s){%s}",
                                                  plugin->name,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 26c06c9..c0830d9 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -199,10 +199,14 @@ typedef gboolean   (*GsPluginUpdateFunc)          (GsPlugin       *plugin,
                                                         GList          *apps,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
+typedef void            (*GsPluginAdoptAppFunc)        (GsPlugin       *plugin,
+                                                        GsApp          *app);
 
 const gchar    *gs_plugin_get_name                     (void);
 void            gs_plugin_initialize                   (GsPlugin       *plugin);
 void            gs_plugin_destroy                      (GsPlugin       *plugin);
+void            gs_plugin_adopt_app                    (GsPlugin       *plugin,
+                                                        GsApp          *app);
 void            gs_plugin_set_enabled                  (GsPlugin       *plugin,
                                                         gboolean        enabled);
 GBytes         *gs_plugin_download_data                (GsPlugin       *plugin,
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 9f3ed65..34bf9f8 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -314,7 +314,7 @@ gs_refine_item_management_plugin (GsApp *app, AsApp *item)
        for (i = 0; i < bundles->len; i++) {
                AsBundle *bundle = g_ptr_array_index (bundles, i);
                if (as_bundle_get_kind (bundle) == AS_BUNDLE_KIND_XDG_APP) {
-                       management_plugin = "xdg-app";
+                       gs_app_set_management_plugin (app, "xdg-app");
                        gs_app_add_source (app, as_bundle_get_id (bundle));
 
                        /* automatically add runtime */
@@ -331,18 +331,11 @@ gs_refine_item_management_plugin (GsApp *app, AsApp *item)
                        break;
                }
                if (as_bundle_get_kind (bundle) == AS_BUNDLE_KIND_LIMBA) {
-                       management_plugin = "limba";
+                       gs_app_set_management_plugin (app, "limba");
                        gs_app_add_source (app, as_bundle_get_id (bundle));
                        break;
                }
        }
-
-       /* fall back to PackageKit */
-       if (management_plugin == NULL &&
-           as_app_get_pkgname_default (item) != NULL)
-               management_plugin = "packagekit";
-       if (management_plugin != NULL)
-               gs_app_set_management_plugin (app, management_plugin);
 }
 
 /**
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index 654c74b..fc24ef4 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -369,6 +369,10 @@ gboolean
 gs_plugin_app_upgrade_download (GsPlugin *plugin, GsApp *app,
                                GCancellable *cancellable, GError **error)
 {
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        g_debug ("starting download");
        gs_app_set_state (app, AS_APP_STATE_INSTALLING);
        if (!gs_plugin_dummy_delay (plugin, app, 5000, cancellable, error))
@@ -383,6 +387,11 @@ gboolean
 gs_plugin_app_upgrade_trigger (GsPlugin *plugin, GsApp *app,
                               GCancellable *cancellable, GError **error)
 {
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
+       /* NOP */
        return TRUE;
 }
 
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
index 90f92b1..ce3f940 100644
--- a/src/plugins/gs-plugin-epiphany.c
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -76,6 +76,16 @@ gs_plugin_initialize (GsPlugin *plugin)
 }
 
 /**
+ * gs_plugin_adopt_app:
+ */
+void
+gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
+{
+       if (gs_app_get_kind (app) == AS_APP_KIND_WEB_APP)
+               gs_app_set_management_plugin (app, plugin->name);
+}
+
+/**
  * _gs_app_get_id_nonfull:
  */
 static gchar *
@@ -115,8 +125,8 @@ gs_plugin_app_install (GsPlugin *plugin, GsApp *app,
        g_autoptr(GFile) symlink_desktop = NULL;
        g_autoptr(GFile) symlink_icon = NULL;
 
-       /* only process web apps */
-       if (gs_app_get_kind (app) != AS_APP_KIND_WEB_APP)
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
                return TRUE;
 
        /* create the correct directory */
@@ -234,12 +244,12 @@ gs_plugin_app_remove (GsPlugin *plugin, GsApp *app,
        g_autoptr(GFile) file_app = NULL;
 
        /* only process this app if was created by this plugin */
-       epi_desktop = gs_app_get_source_id_default (app);
-       if (epi_desktop == NULL)
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
                return TRUE;
 
        /* remove the epi 'config' file */
        gs_app_set_state (app, AS_APP_STATE_REMOVING);
+       epi_desktop = gs_app_get_source_id_default (app);
        file_epi = g_file_new_for_path (epi_desktop);
        if (!g_file_delete (file_epi, NULL, error))
                return FALSE;
@@ -271,9 +281,8 @@ gs_plugin_refine_app (GsPlugin *plugin,
        g_autofree gchar *hash = NULL;
        g_autofree gchar *id_nonfull = NULL;
 
-       if (gs_app_get_kind (app) != AS_APP_KIND_WEB_APP)
-               return TRUE;
-       if (gs_app_get_source_id_default (app) != NULL)
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
                return TRUE;
 
        gs_app_set_size (app, 4096);
@@ -289,9 +298,24 @@ gs_plugin_refine_app (GsPlugin *plugin,
        if (g_file_test (fn, G_FILE_TEST_EXISTS)) {
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
                gs_app_add_source_id (app, fn);
-               gs_app_set_management_plugin (app, "epiphany");
+               gs_app_set_management_plugin (app, plugin->name);
                return TRUE;
        }
        gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
        return TRUE;
 }
+
+/**
+ * gs_plugin_launch:
+ */
+gboolean
+gs_plugin_launch (GsPlugin *plugin,
+                 GsApp *app,
+                 GCancellable *cancellable,
+                 GError **error)
+{
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+       return gs_plugin_app_launch (plugin, app, error);
+}
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index dd5a120..5e36f5f 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -96,6 +96,16 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 /**
+ * gs_plugin_adopt_app:
+ */
+void
+gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
+{
+       if (gs_app_get_kind (app) == AS_APP_KIND_FIRMWARE)
+               gs_app_set_management_plugin (app, plugin->name);
+}
+
+/**
  * gs_plugin_fwupd_changed_cb:
  */
 static void
@@ -667,6 +677,10 @@ gs_plugin_app_install (GsPlugin *plugin,
                       GCancellable *cancellable,
                       GError **error)
 {
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        return gs_plugin_fwupd_install (plugin, app, cancellable, error);
 }
 
@@ -681,6 +695,10 @@ gs_plugin_update_app (GsPlugin *plugin,
                      GCancellable *cancellable,
                      GError **error)
 {
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* locked devices need unlocking, rather than installing */
        if (gs_app_get_metadata_item (app, "fwupd::IsLocked") != NULL) {
                const gchar *device_id;
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index 7e2d076..2492127 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -91,7 +91,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
        g_autoptr(AsProfileTask) ptask = NULL;
 
        /* not us */
-       if (g_strcmp0 (gs_app_get_management_plugin (app), "limba") != 0)
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
                return TRUE;
 
        /* profile */
@@ -184,6 +184,10 @@ gs_plugin_app_remove (GsPlugin *plugin,
        GsPluginHelper helper;
        g_autoptr(GError) error_local = NULL;
 
+       /* not us */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        mgr = li_manager_new ();
 
        /* set up progress forwarding */
@@ -226,6 +230,10 @@ gs_plugin_app_install (GsPlugin *plugin,
        GsPluginHelper helper;
        g_autoptr(GError) error_local = NULL;
 
+       /* not us */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* create new installer and select remote package */
        inst = li_installer_new ();
        li_installer_open_remote (inst,
diff --git a/src/plugins/gs-plugin-ostree.c b/src/plugins/gs-plugin-ostree.c
index b8e7c61..f63a220 100644
--- a/src/plugins/gs-plugin-ostree.c
+++ b/src/plugins/gs-plugin-ostree.c
@@ -130,7 +130,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
 
                /* create app */
                app = gs_app_new (names[i]);
-               gs_app_set_management_plugin (app, "ostree");
+               gs_app_set_management_plugin (app, plugin->name);
                gs_app_set_kind (app, AS_APP_KIND_SOURCE);
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
                gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, url);
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 4c7ea34..c69420d 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -118,6 +118,22 @@ gs_plugin_destroy (GsPlugin *plugin)
        g_object_unref (plugin->priv->control);
 }
 
+/**
+ * gs_plugin_adopt_app:
+ */
+void
+gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
+{
+       const gchar *tmp;
+
+       /* this was installed system-wide and picked up by AppStream */
+       tmp = gs_app_get_metadata_item (app, "appstream::source-file");
+       if (tmp != NULL && g_str_has_prefix (tmp, "/usr/share/") &&
+           gs_app_get_source_default (app) != NULL) {
+               gs_app_set_management_plugin (app, "packagekit");
+               return;
+       }
+}
 
 typedef struct {
        GsPlugin        *plugin;
@@ -880,7 +896,8 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_kind (app) == AS_APP_KIND_WEB_APP)
                        continue;
-               if (g_strcmp0 (gs_app_get_management_plugin (app), "packagekit") != 0)
+               tmp = gs_app_get_management_plugin (app);
+               if (tmp != NULL && g_strcmp0 (tmp, "packagekit") != 0)
                        continue;
                sources = gs_app_get_sources (app);
                if (sources->len == 0)
@@ -948,7 +965,8 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_state (app) != AS_APP_STATE_UPDATABLE)
                        continue;
-               if (g_strcmp0 (gs_app_get_management_plugin (app), "packagekit") != 0)
+               tmp = gs_app_get_management_plugin (app);
+               if (tmp != NULL && g_strcmp0 (tmp, "packagekit") != 0)
                        continue;
                if (gs_plugin_refine_requires_update_details (app, flags))
                        updatedetails_all = g_list_prepend (updatedetails_all, app);
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 9a9699b..9cc7640 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -264,7 +264,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
                rd = g_ptr_array_index (array, i);
                id = pk_repo_detail_get_id (rd);
                app = gs_app_new (id);
-               gs_app_set_management_plugin (app, "packagekit");
+               gs_app_set_management_plugin (app, plugin->name);
                gs_app_set_kind (app, AS_APP_KIND_SOURCE);
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
                gs_app_set_name (app,
@@ -334,6 +334,10 @@ gs_plugin_app_install (GsPlugin *plugin,
        data.plugin = plugin;
        data.ptask = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* we enable the repo */
        if (gs_app_get_state (app) == AS_APP_STATE_UNAVAILABLE) {
 
@@ -564,6 +568,10 @@ gs_plugin_app_remove (GsPlugin *plugin,
        data.plugin = plugin;
        data.ptask = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* remove repo and all apps in it */
        if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE) {
                return gs_plugin_app_source_remove (plugin, app,
@@ -731,3 +739,18 @@ gs_plugin_add_search_what_provides (GsPlugin *plugin,
        /* add results */
        return gs_plugin_packagekit_add_results (plugin, list, results, error);
 }
+
+/**
+ * gs_plugin_launch:
+ */
+gboolean
+gs_plugin_launch (GsPlugin *plugin,
+                 GsApp *app,
+                 GCancellable *cancellable,
+                 GError **error)
+{
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+       return gs_plugin_app_launch (plugin, app, error);
+}
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index 0651fbb..7645bbe 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -94,6 +94,16 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 /**
+ * gs_plugin_adopt_app:
+ */
+void
+gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
+{
+       if (gs_app_get_kind (app) == AS_APP_KIND_SHELL_EXTENSION)
+               gs_app_set_management_plugin (app, plugin->name);
+}
+
+/**
  * gs_plugin_shell_extensions_id_from_uuid:
  */
 static gchar *
@@ -308,7 +318,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
 
        /* adopt any here */
        if (gs_app_get_management_plugin (app) == NULL)
-               gs_app_set_management_plugin (app, "shell-extensions");
+               gs_app_set_management_plugin (app, plugin->name);
 
        /* assume apps are available if they exist in AppStream metadata */
        if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN)
@@ -473,7 +483,7 @@ gs_plugin_shell_extensions_parse_app (GsPlugin *plugin,
 
        /* we have no data :/ */
        as_app_set_comment (app, NULL, "GNOME Shell Extension");
-       as_app_add_metadata (app, "ManagementPlugin", "shell-extensions");
+       as_app_add_metadata (app, "GnomeSoftware::Plugin", plugin->name);
        return app;
 }
 
@@ -714,6 +724,10 @@ gs_plugin_app_remove (GsPlugin *plugin,
        gboolean ret;
        g_autoptr(GVariant) retval = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* install */
        uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
        retval = g_dbus_proxy_call_sync (plugin->priv->proxy,
@@ -753,6 +767,10 @@ gs_plugin_app_install (GsPlugin *plugin,
        const gchar *retstr;
        g_autoptr(GVariant) retval = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* install */
        uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
        gs_app_set_state (app, AS_APP_STATE_INSTALLING);
diff --git a/src/plugins/gs-plugin-steam.c b/src/plugins/gs-plugin-steam.c
index 570353b..7ac3e37 100644
--- a/src/plugins/gs-plugin-steam.c
+++ b/src/plugins/gs-plugin-steam.c
@@ -924,6 +924,10 @@ gs_plugin_app_install (GsPlugin *plugin, GsApp *app,
        const gchar *gameid;
        g_autofree gchar *cmdline = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* this is async as steam is a different process: FIXME: use D-Bus */
        gs_app_set_state (app, AS_APP_STATE_INSTALLING);
        gameid = gs_app_get_metadata_item (app, "X-Steam-GameID");
@@ -941,6 +945,10 @@ gs_plugin_app_remove (GsPlugin *plugin, GsApp *app,
        const gchar *gameid;
        g_autofree gchar *cmdline = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* this is async as steam is a different process: FIXME: use D-Bus */
        gs_app_set_state (app, AS_APP_STATE_REMOVING);
        gameid = gs_app_get_metadata_item (app, "X-Steam-GameID");
@@ -958,6 +966,10 @@ gs_plugin_launch (GsPlugin *plugin, GsApp *app,
        const gchar *gameid;
        g_autofree gchar *cmdline = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* this is async as steam is a different process: FIXME: use D-Bus */
        gameid = gs_app_get_metadata_item (app, "X-Steam-GameID");
        cmdline = g_strdup_printf ("steam steam://run/%s", gameid);
diff --git a/src/plugins/gs-plugin-systemd-updates.c b/src/plugins/gs-plugin-systemd-updates.c
index 9b44413..b203ff5 100644
--- a/src/plugins/gs-plugin-systemd-updates.c
+++ b/src/plugins/gs-plugin-systemd-updates.c
@@ -128,7 +128,7 @@ gs_plugin_add_updates (GsPlugin *plugin,
                g_auto(GStrv) split = NULL;
                app = gs_app_new (NULL);
                gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_REBOOT);
-               gs_app_set_management_plugin (app, "PackageKit");
+               gs_app_set_management_plugin (app, "packagekit");
                gs_app_add_source_id (app, package_ids[i]);
                split = pk_package_id_split (package_ids[i]);
                gs_app_add_source (app, split[PK_PACKAGE_ID_NAME]);
@@ -154,6 +154,11 @@ gs_plugin_update (GsPlugin *plugin,
        /* any apps to process offline */
        for (l = apps; l != NULL; l = l->next) {
                GsApp *app = GS_APP (l->data);
+
+               /* only process this app if was created by this plugin */
+               if (g_strcmp0 (gs_app_get_management_plugin (app), "packagekit") != 0)
+                       continue;
+
                if (gs_app_get_state (app) == AS_APP_STATE_UPDATABLE) {
                        return pk_offline_trigger (PK_OFFLINE_ACTION_REBOOT,
                                                   cancellable, error);
@@ -171,6 +176,9 @@ gs_plugin_update_cancel (GsPlugin *plugin,
                         GCancellable *cancellable,
                         GError **error)
 {
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), "packagekit") != 0)
+               return TRUE;
        return pk_offline_cancel (NULL, error);
 }
 
@@ -183,5 +191,8 @@ gs_plugin_app_upgrade_trigger (GsPlugin *plugin,
                                GCancellable *cancellable,
                                GError **error)
 {
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), "packagekit") != 0)
+               return TRUE;
        return pk_offline_trigger_upgrade (PK_OFFLINE_ACTION_REBOOT, cancellable, error);
 }
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index 5366e93..2b04305 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -92,6 +92,18 @@ gs_plugin_destroy (GsPlugin *plugin)
                g_object_unref (plugin->priv->monitor);
 }
 
+/**
+ * gs_plugin_adopt_app:
+ */
+void
+gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
+{
+       if (g_str_has_prefix (gs_app_get_id (app), "user-xdgapp:") ||
+           g_str_has_prefix (gs_app_get_id (app), "xdgapp:")) {
+               gs_app_set_management_plugin (app, plugin->name);
+       }
+}
+
 /* helpers */
 #define gs_app_get_xdgapp_kind_as_str(app)     gs_app_get_metadata_item(app,"xdg-app::kind")
 #define gs_app_get_xdgapp_name(app)            gs_app_get_metadata_item(app,"xdg-app::name")
@@ -531,7 +543,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
                        continue;
 
                app = gs_app_new (xdg_app_remote_get_name (xremote));
-               gs_app_set_management_plugin (app, "xdg-app");
+               gs_app_set_management_plugin (app, plugin->name);
                gs_app_set_kind (app, AS_APP_KIND_SOURCE);
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
                gs_app_set_name (app,
@@ -1137,7 +1149,7 @@ gs_plugin_xdg_app_refine_app (GsPlugin *plugin,
        g_autoptr(AsProfileTask) ptask = NULL;
 
        /* only process this app if was created by this plugin */
-       if (g_strcmp0 (gs_app_get_management_plugin (app), "xdg-app") != 0)
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
                return TRUE;
 
        /* profile */
@@ -1204,6 +1216,10 @@ gs_plugin_launch (GsPlugin *plugin,
 {
        const gchar *branch = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* ensure we can set up the repo */
        if (!gs_plugin_ensure_installation (plugin, cancellable, error))
                return FALSE;
@@ -1231,6 +1247,10 @@ gs_plugin_app_remove (GsPlugin *plugin,
 {
        GsPluginHelper helper;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* ensure we can set up the repo */
        if (!gs_plugin_ensure_installation (plugin, cancellable, error))
                return FALSE;
@@ -1262,6 +1282,10 @@ gs_plugin_app_install (GsPlugin *plugin,
        GsPluginHelper helper;
        g_autoptr(XdgAppInstalledRef) xref = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* ensure we can set up the repo */
        if (!gs_plugin_ensure_installation (plugin, cancellable, error))
                return FALSE;
@@ -1359,6 +1383,10 @@ gs_plugin_update_app (GsPlugin *plugin,
        GsPluginHelper helper;
        g_autoptr(XdgAppInstalledRef) xref = NULL;
 
+       /* only process this app if was created by this plugin */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+               return TRUE;
+
        /* ensure we can set up the repo */
        if (!gs_plugin_ensure_installation (plugin, cancellable, error))
                return FALSE;


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