Blame SOURCES/add-back-shell-extensions-support.patch

a7f877
From 82a85d6bbacb148e355680446c4bbd6a091ad2eb Mon Sep 17 00:00:00 2001
a7f877
From: Kalev Lember <klember@redhat.com>
a7f877
Date: Wed, 3 Jun 2020 15:50:41 +0200
a7f877
Subject: [PATCH 1/2] Revert "Remove support for Shell extensions"
a7f877
a7f877
This reverts commit 77bdc3855c26de0edc2ce5d73bb6be861721c37b.
a7f877
---
a7f877
 contrib/gnome-software.spec.in                |    1 +
a7f877
 meson_options.txt                             |    1 +
a7f877
 plugins/core/gs-appstream.c                   |   14 +-
a7f877
 plugins/core/gs-desktop-common.c              |    3 +
a7f877
 plugins/meson.build                           |    3 +
a7f877
 plugins/packagekit/gs-plugin-packagekit.c     |    3 +
a7f877
 plugins/shell-extensions/gs-appstream.c       |    1 +
a7f877
 plugins/shell-extensions/gs-appstream.h       |    1 +
a7f877
 .../gs-plugin-shell-extensions.c              | 1159 +++++++++++++++++
a7f877
 plugins/shell-extensions/gs-self-test.c       |  156 +++
a7f877
 plugins/shell-extensions/meson.build          |   47 +
a7f877
 src/gs-category-page.c                        |   25 +
a7f877
 src/gs-category-page.ui                       |   45 +
a7f877
 src/gs-details-page.c                         |   14 +-
a7f877
 src/gs-repo-row.c                             |    3 +-
a7f877
 src/gs-repos-dialog.c                         |    3 +-
a7f877
 src/gs-summary-tile.c                         |   15 +-
a7f877
 17 files changed, 1478 insertions(+), 16 deletions(-)
a7f877
 create mode 120000 plugins/shell-extensions/gs-appstream.c
a7f877
 create mode 120000 plugins/shell-extensions/gs-appstream.h
a7f877
 create mode 100644 plugins/shell-extensions/gs-plugin-shell-extensions.c
a7f877
 create mode 100644 plugins/shell-extensions/gs-self-test.c
a7f877
 create mode 100644 plugins/shell-extensions/meson.build
a7f877
a7f877
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
a7f877
index 587a72e6..7f415f51 100644
a7f877
--- a/contrib/gnome-software.spec.in
a7f877
+++ b/contrib/gnome-software.spec.in
a7f877
@@ -183,6 +183,7 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop
a7f877
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_provenance.so
a7f877
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_repos.so
a7f877
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_rewrite-resource.so
a7f877
+%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_shell-extensions.so
a7f877
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_systemd-updates.so
a7f877
 %{_sysconfdir}/xdg/autostart/gnome-software-service.desktop
a7f877
 %{_datadir}/app-info/xmls/org.gnome.Software.Featured.xml
a7f877
diff --git a/meson_options.txt b/meson_options.txt
a7f877
index f6068ba5..eba69ea2 100644
a7f877
--- a/meson_options.txt
a7f877
+++ b/meson_options.txt
a7f877
@@ -10,6 +10,7 @@ option('fwupd', type : 'boolean', value : true, description : 'enable fwupd supp
a7f877
 option('flatpak', type : 'boolean', value : true, description : 'enable Flatpak support')
a7f877
 option('malcontent', type : 'boolean', value : true, description : 'enable parental controls support using libmalcontent')
a7f877
 option('rpm_ostree', type : 'boolean', value : false, description : 'enable rpm-ostree support')
a7f877
+option('shell_extensions', type : 'boolean', value : true, description : 'enable shell extensions support')
a7f877
 option('odrs', type : 'boolean', value : true, description : 'enable ODRS support')
a7f877
 option('gudev', type : 'boolean', value : true, description : 'enable GUdev support')
a7f877
 option('snap', type : 'boolean', value : false, description : 'enable Snap support')
a7f877
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
a7f877
index a387f2e0..e507ac0f 100644
a7f877
--- a/plugins/core/gs-appstream.c
a7f877
+++ b/plugins/core/gs-appstream.c
a7f877
@@ -30,15 +30,6 @@ gs_appstream_create_app (GsPlugin *plugin, XbSilo *silo, XbNode *component, GErr
a7f877
 	if (gs_app_has_quirk (app_new, GS_APP_QUIRK_IS_WILDCARD))
a7f877
 		return g_steal_pointer (&app_new);
a7f877
 
a7f877
-	/* no longer supported */
a7f877
-	if (gs_app_get_kind (app_new) == AS_APP_KIND_SHELL_EXTENSION) {
a7f877
-		g_set_error (error,
a7f877
-			     GS_PLUGIN_ERROR,
a7f877
-			     GS_PLUGIN_ERROR_NOT_SUPPORTED,
a7f877
-			     "shell extensions no longer supported");
a7f877
-		return NULL;
a7f877
-	}
a7f877
-
a7f877
 	/* look for existing object */
a7f877
 	app = gs_plugin_cache_lookup (plugin, gs_app_get_unique_id (app_new));
a7f877
 	if (app != NULL)
a7f877
@@ -1548,6 +1539,11 @@ gs_appstream_component_add_extra_info (GsPlugin *plugin, XbBuilderNode *componen
a7f877
 		gs_appstream_component_add_category (component, "Addon");
a7f877
 		gs_appstream_component_add_category (component, "Font");
a7f877
 		break;
a7f877
+	case AS_APP_KIND_SHELL_EXTENSION:
a7f877
+		gs_appstream_component_add_category (component, "Addon");
a7f877
+		gs_appstream_component_add_category (component, "ShellExtension");
a7f877
+		gs_appstream_component_add_icon (component, "application-x-addon-symbolic");
a7f877
+		break;
a7f877
 	case AS_APP_KIND_DRIVER:
a7f877
 		gs_appstream_component_add_category (component, "Addon");
a7f877
 		gs_appstream_component_add_category (component, "Driver");
a7f877
diff --git a/plugins/core/gs-desktop-common.c b/plugins/core/gs-desktop-common.c
a7f877
index 33ae3fa2..17ed029d 100644
a7f877
--- a/plugins/core/gs-desktop-common.c
a7f877
+++ b/plugins/core/gs-desktop-common.c
a7f877
@@ -203,6 +203,9 @@ static const GsDesktopMap map_addons[] = {
a7f877
 	{ "language-packs",	NC_("Menu of Add-ons", "Language Packs"),
a7f877
 					{ "Addon::LanguagePack",
a7f877
 					  NULL} },
a7f877
+	{ "shell-extensions",	NC_("Menu of Add-ons", "Shell Extensions"),
a7f877
+					{ "Addon::ShellExtension",
a7f877
+					  NULL} },
a7f877
 	{ "localization",	NC_("Menu of Add-ons", "Localization"),
a7f877
 					{ "Addon::Localization",
a7f877
 					  NULL} },
a7f877
diff --git a/plugins/meson.build b/plugins/meson.build
a7f877
index d749b3df..d30f14d4 100644
a7f877
--- a/plugins/meson.build
a7f877
+++ b/plugins/meson.build
a7f877
@@ -39,6 +39,9 @@ subdir('repos')
a7f877
 if get_option('rpm_ostree')
a7f877
   subdir('rpm-ostree')
a7f877
 endif
a7f877
+if get_option('shell_extensions')
a7f877
+  subdir('shell-extensions')
a7f877
+endif
a7f877
 if get_option('snap')
a7f877
   subdir('snap')
a7f877
 endif
a7f877
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
a7f877
index d0bdabae..2c4e1644 100644
a7f877
--- a/plugins/packagekit/gs-plugin-packagekit.c
a7f877
+++ b/plugins/packagekit/gs-plugin-packagekit.c
a7f877
@@ -688,5 +688,8 @@ gs_plugin_launch (GsPlugin *plugin,
a7f877
 	if (g_strcmp0 (gs_app_get_management_plugin (app),
a7f877
 		       gs_plugin_get_name (plugin)) != 0)
a7f877
 		return TRUE;
a7f877
+	/* these are handled by the shell extensions plugin */
a7f877
+	if (gs_app_get_kind (app) == AS_APP_KIND_SHELL_EXTENSION)
a7f877
+		return TRUE;
a7f877
 	return gs_plugin_app_launch (plugin, app, error);
a7f877
 }
a7f877
diff --git a/plugins/shell-extensions/gs-appstream.c b/plugins/shell-extensions/gs-appstream.c
a7f877
new file mode 120000
a7f877
index 00000000..96326ab0
a7f877
--- /dev/null
a7f877
+++ b/plugins/shell-extensions/gs-appstream.c
a7f877
@@ -0,0 +1 @@
a7f877
+../core/gs-appstream.c
a7f877
\ No newline at end of file
a7f877
diff --git a/plugins/shell-extensions/gs-appstream.h b/plugins/shell-extensions/gs-appstream.h
a7f877
new file mode 120000
a7f877
index 00000000..4eabcb3c
a7f877
--- /dev/null
a7f877
+++ b/plugins/shell-extensions/gs-appstream.h
a7f877
@@ -0,0 +1 @@
a7f877
+../core/gs-appstream.h
a7f877
\ No newline at end of file
a7f877
diff --git a/plugins/shell-extensions/gs-plugin-shell-extensions.c b/plugins/shell-extensions/gs-plugin-shell-extensions.c
a7f877
new file mode 100644
a7f877
index 00000000..80a5d0eb
a7f877
--- /dev/null
a7f877
+++ b/plugins/shell-extensions/gs-plugin-shell-extensions.c
a7f877
@@ -0,0 +1,1159 @@
a7f877
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
a7f877
+ *
a7f877
+ * Copyright (C) 2016-2018 Richard Hughes <richard@hughsie.com>
a7f877
+ * Copyright (C) 2018 Kalev Lember <klember@redhat.com>
a7f877
+ *
a7f877
+ * SPDX-License-Identifier: GPL-2.0+
a7f877
+ */
a7f877
+
a7f877
+#include <config.h>
a7f877
+
a7f877
+#include <errno.h>
a7f877
+#include <glib/gi18n.h>
a7f877
+#include <json-glib/json-glib.h>
a7f877
+#include <xmlb.h>
a7f877
+
a7f877
+#include <gnome-software.h>
a7f877
+
a7f877
+#include "gs-appstream.h"
a7f877
+
a7f877
+#define SHELL_EXTENSIONS_API_URI 		"https://extensions.gnome.org/"
a7f877
+
a7f877
+/*
a7f877
+ * Things we want from the API:
a7f877
+ *
a7f877
+ *  - Size on disk/download
a7f877
+ *  - Existing review data for each extension?
a7f877
+ *  - A local icon for an installed shell extension
a7f877
+ *
a7f877
+ * See https://git.gnome.org/browse/extensions-web/tree/sweettooth/extensions/views.py
a7f877
+ * for the source to the web application.
a7f877
+ */
a7f877
+
a7f877
+struct GsPluginData {
a7f877
+	GDBusProxy	*proxy;
a7f877
+	gchar		*shell_version;
a7f877
+	GsApp		*cached_origin;
a7f877
+	GSettings	*settings;
a7f877
+	XbSilo		*silo;
a7f877
+	GRWLock		 silo_lock;
a7f877
+};
a7f877
+
a7f877
+typedef enum {
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_STATE_ENABLED		= 1,
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_STATE_DISABLED	= 2,
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_STATE_ERROR		= 3,
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_STATE_OUT_OF_DATE	= 4,
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_STATE_DOWNLOADING	= 5,
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_STATE_INITIALIZED	= 6,
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_STATE_UNINSTALLED	= 99,
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_STATE_LAST
a7f877
+} GsPluginShellExtensionState;
a7f877
+
a7f877
+typedef enum {
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_KIND_SYSTEM		= 1,
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_KIND_PER_USER		= 2,
a7f877
+	GS_PLUGIN_SHELL_EXTENSION_KIND_LAST
a7f877
+} GsPluginShellExtensionKind;
a7f877
+
a7f877
+static gboolean _check_silo (GsPlugin *plugin, GCancellable *cancellable, GError **error);
a7f877
+
a7f877
+void
a7f877
+gs_plugin_initialize (GsPlugin *plugin)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
a7f877
+
a7f877
+	/* XbSilo needs external locking as we destroy the silo and build a new
a7f877
+	 * one when something changes */
a7f877
+	g_rw_lock_init (&priv->silo_lock);
a7f877
+
a7f877
+	/* add source */
a7f877
+	priv->cached_origin = gs_app_new (gs_plugin_get_name (plugin));
a7f877
+	gs_app_set_kind (priv->cached_origin, AS_APP_KIND_SOURCE);
a7f877
+	gs_app_set_origin_hostname (priv->cached_origin, SHELL_EXTENSIONS_API_URI);
a7f877
+	gs_app_set_origin (priv->cached_origin, _("GNOME"));
a7f877
+
a7f877
+	priv->settings = g_settings_new ("org.gnome.software");
a7f877
+
a7f877
+	/* add the source to the plugin cache which allows us to match the
a7f877
+	 * unique ID to a GsApp when creating an event */
a7f877
+	gs_plugin_cache_add (plugin,
a7f877
+			     gs_app_get_unique_id (priv->cached_origin),
a7f877
+			     priv->cached_origin);
a7f877
+}
a7f877
+
a7f877
+void
a7f877
+gs_plugin_destroy (GsPlugin *plugin)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	g_free (priv->shell_version);
a7f877
+	if (priv->proxy != NULL)
a7f877
+		g_object_unref (priv->proxy);
a7f877
+	if (priv->silo != NULL)
a7f877
+		g_object_unref (priv->silo);
a7f877
+	g_object_unref (priv->cached_origin);
a7f877
+	g_object_unref (priv->settings);
a7f877
+	g_rw_lock_clear (&priv->silo_lock);
a7f877
+}
a7f877
+
a7f877
+void
a7f877
+gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
a7f877
+{
a7f877
+	if (gs_app_get_kind (app) == AS_APP_KIND_SHELL_EXTENSION &&
a7f877
+	    gs_app_get_scope (app) == AS_APP_SCOPE_USER) {
a7f877
+		gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
a7f877
+	}
a7f877
+}
a7f877
+
a7f877
+static AsAppState
a7f877
+gs_plugin_shell_extensions_convert_state (guint value)
a7f877
+{
a7f877
+	switch (value) {
a7f877
+	case GS_PLUGIN_SHELL_EXTENSION_STATE_DISABLED:
a7f877
+	case GS_PLUGIN_SHELL_EXTENSION_STATE_DOWNLOADING:
a7f877
+	case GS_PLUGIN_SHELL_EXTENSION_STATE_ENABLED:
a7f877
+	case GS_PLUGIN_SHELL_EXTENSION_STATE_ERROR:
a7f877
+	case GS_PLUGIN_SHELL_EXTENSION_STATE_INITIALIZED:
a7f877
+	case GS_PLUGIN_SHELL_EXTENSION_STATE_OUT_OF_DATE:
a7f877
+		return AS_APP_STATE_INSTALLED;
a7f877
+	case GS_PLUGIN_SHELL_EXTENSION_STATE_UNINSTALLED:
a7f877
+		return AS_APP_STATE_AVAILABLE;
a7f877
+	default:
a7f877
+		g_warning ("unknown state %u", value);
a7f877
+	}
a7f877
+	return AS_APP_STATE_UNKNOWN;
a7f877
+}
a7f877
+
a7f877
+static GsApp *
a7f877
+gs_plugin_shell_extensions_parse_installed (GsPlugin *plugin,
a7f877
+                                            const gchar *uuid,
a7f877
+                                            GVariantIter *iter,
a7f877
+                                            GError **error)
a7f877
+{
a7f877
+	const gchar *tmp;
a7f877
+	gchar *str;
a7f877
+	GVariant *val;
a7f877
+	g_autofree gchar *id = NULL;
a7f877
+	g_autoptr(AsIcon) ic = NULL;
a7f877
+	g_autoptr(GsApp) app = NULL;
a7f877
+
a7f877
+	id = as_utils_appstream_id_build (uuid);
a7f877
+	app = gs_app_new (id);
a7f877
+	gs_app_set_metadata (app, "GnomeSoftware::Creator",
a7f877
+			     gs_plugin_get_name (plugin));
a7f877
+	gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
a7f877
+	gs_app_set_metadata (app, "shell-extensions::uuid", uuid);
a7f877
+	gs_app_set_kind (app, AS_APP_KIND_SHELL_EXTENSION);
a7f877
+	gs_app_set_license (app, GS_APP_QUALITY_NORMAL, "GPL-2.0+");
a7f877
+	gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "GNOME Shell Extension");
a7f877
+	gs_app_set_origin_hostname (app, SHELL_EXTENSIONS_API_URI);
a7f877
+	gs_app_set_origin (app, _("GNOME"));
a7f877
+	while (g_variant_iter_loop (iter, "{sv}", &str, &val)) {
a7f877
+		if (g_strcmp0 (str, "description") == 0) {
a7f877
+			g_autofree gchar *tmp1 = NULL;
a7f877
+			g_autofree gchar *tmp2 = NULL;
a7f877
+			tmp1 = as_markup_import (g_variant_get_string (val, NULL),
a7f877
+						 AS_MARKUP_CONVERT_FORMAT_SIMPLE,
a7f877
+						 NULL);
a7f877
+			tmp2 = as_markup_convert_simple (tmp1, error);
a7f877
+			if (tmp2 == NULL) {
a7f877
+				gs_utils_error_convert_appstream (error);
a7f877
+				return NULL;
a7f877
+			}
a7f877
+			gs_app_set_description (app, GS_APP_QUALITY_NORMAL, tmp2);
a7f877
+			continue;
a7f877
+		}
a7f877
+		if (g_strcmp0 (str, "name") == 0) {
a7f877
+			gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
a7f877
+					 g_variant_get_string (val, NULL));
a7f877
+			continue;
a7f877
+		}
a7f877
+		if (g_strcmp0 (str, "version") == 0) {
a7f877
+			guint val_int = (guint) g_variant_get_double (val);
a7f877
+			g_autofree gchar *version = g_strdup_printf ("%u", val_int);
a7f877
+			gs_app_set_version (app, version);
a7f877
+			continue;
a7f877
+		}
a7f877
+		if (g_strcmp0 (str, "url") == 0) {
a7f877
+			gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
a7f877
+					g_variant_get_string (val, NULL));
a7f877
+			continue;
a7f877
+		}
a7f877
+		if (g_strcmp0 (str, "type") == 0) {
a7f877
+			guint val_int = (guint) g_variant_get_double (val);
a7f877
+			switch (val_int) {
a7f877
+			case GS_PLUGIN_SHELL_EXTENSION_KIND_SYSTEM:
a7f877
+				gs_app_set_scope (app, AS_APP_SCOPE_SYSTEM);
a7f877
+				break;
a7f877
+			case GS_PLUGIN_SHELL_EXTENSION_KIND_PER_USER:
a7f877
+				gs_app_set_scope (app, AS_APP_SCOPE_USER);
a7f877
+				break;
a7f877
+			default:
a7f877
+				g_warning ("%s unknown type %u", uuid, val_int);
a7f877
+				break;
a7f877
+			}
a7f877
+			continue;
a7f877
+		}
a7f877
+		if (g_strcmp0 (str, "state") == 0) {
a7f877
+			AsAppState st;
a7f877
+			guint val_int = (guint) g_variant_get_double (val);
a7f877
+			st = gs_plugin_shell_extensions_convert_state (val_int);
a7f877
+			gs_app_set_state (app, st);
a7f877
+			continue;
a7f877
+		}
a7f877
+		if (g_strcmp0 (str, "error") == 0) {
a7f877
+			tmp = g_variant_get_string (val, NULL);
a7f877
+			if (tmp != NULL && tmp[0] != '\0') {
a7f877
+				g_warning ("unhandled shell error: %s", tmp);
a7f877
+			}
a7f877
+			continue;
a7f877
+		}
a7f877
+		if (g_strcmp0 (str, "hasPrefs") == 0) {
a7f877
+			if (g_variant_get_boolean (val))
a7f877
+				gs_app_set_metadata (app, "shell-extensions::has-prefs", "");
a7f877
+			continue;
a7f877
+		}
a7f877
+		if (g_strcmp0 (str, "extension-id") == 0) {
a7f877
+			tmp = g_variant_get_string (val, NULL);
a7f877
+			gs_app_set_metadata (app, "shell-extensions::extension-id", tmp);
a7f877
+			continue;
a7f877
+		}
a7f877
+		if (g_strcmp0 (str, "path") == 0) {
a7f877
+			tmp = g_variant_get_string (val, NULL);
a7f877
+			gs_app_set_metadata (app, "shell-extensions::path", tmp);
a7f877
+			continue;
a7f877
+		}
a7f877
+	}
a7f877
+
a7f877
+	/* hardcode icon */
a7f877
+	ic = as_icon_new ();
a7f877
+	as_icon_set_kind (ic, AS_ICON_KIND_STOCK);
a7f877
+	as_icon_set_name (ic, "application-x-addon-symbolic");
a7f877
+	gs_app_add_icon (app, ic);
a7f877
+
a7f877
+	/* add categories */
a7f877
+	gs_app_add_category (app, "Addon");
a7f877
+	gs_app_add_category (app, "ShellExtension");
a7f877
+
a7f877
+	return g_steal_pointer (&app);
a7f877
+}
a7f877
+
a7f877
+static void
a7f877
+gs_plugin_shell_extensions_changed_cb (GDBusProxy *proxy,
a7f877
+				       const gchar *sender_name,
a7f877
+				       const gchar *signal_name,
a7f877
+				       GVariant *parameters,
a7f877
+				       GsPlugin *plugin)
a7f877
+{
a7f877
+	if (g_strcmp0 (signal_name, "ExtensionStatusChanged") == 0) {
a7f877
+		AsAppState st;
a7f877
+		GsApp *app;
a7f877
+		const gchar *error_str;
a7f877
+		const gchar *uuid;
a7f877
+		guint state;
a7f877
+
a7f877
+		/* get what changed */
a7f877
+		g_variant_get (parameters, "(&si&s)",
a7f877
+			       &uuid, &state, &error_str);
a7f877
+
a7f877
+		/* find it in the cache; do we care? */
a7f877
+		app = gs_plugin_cache_lookup (plugin, uuid);
a7f877
+		if (app == NULL) {
a7f877
+			g_debug ("no app for changed %s", uuid);
a7f877
+			return;
a7f877
+		}
a7f877
+
a7f877
+		/* set the new state in the UI */
a7f877
+		st = gs_plugin_shell_extensions_convert_state (state);
a7f877
+		gs_app_set_state (app, st);
a7f877
+
a7f877
+		/* not sure what to do here */
a7f877
+		if (error_str != NULL && error_str[0] != '\0') {
a7f877
+			g_warning ("%s has error: %s",
a7f877
+				   gs_app_get_id (app),
a7f877
+				   error_str);
a7f877
+		}
a7f877
+	}
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	g_autofree gchar *name_owner = NULL;
a7f877
+	g_autoptr(GVariant) version = NULL;
a7f877
+
a7f877
+	if (priv->proxy != NULL)
a7f877
+		return TRUE;
a7f877
+	priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
a7f877
+						     G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
a7f877
+						     NULL,
a7f877
+						     "org.gnome.Shell",
a7f877
+						     "/org/gnome/Shell",
a7f877
+						     "org.gnome.Shell.Extensions",
a7f877
+						     cancellable,
a7f877
+						     error);
a7f877
+	if (priv->proxy == NULL) {
a7f877
+		gs_utils_error_convert_gio (error);
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+
a7f877
+	/* not running under Shell */
a7f877
+	name_owner = g_dbus_proxy_get_name_owner (priv->proxy);
a7f877
+	if (name_owner == NULL) {
a7f877
+		g_set_error_literal (error,
a7f877
+				     GS_PLUGIN_ERROR,
a7f877
+				     GS_PLUGIN_ERROR_NOT_SUPPORTED,
a7f877
+				     "gnome-shell is not running");
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+
a7f877
+	g_signal_connect (priv->proxy, "g-signal",
a7f877
+			  G_CALLBACK (gs_plugin_shell_extensions_changed_cb), plugin);
a7f877
+
a7f877
+	/* get the GNOME Shell version */
a7f877
+	version = g_dbus_proxy_get_cached_property (priv->proxy,
a7f877
+						    "ShellVersion");
a7f877
+	if (version == NULL) {
a7f877
+		g_set_error_literal (error,
a7f877
+				     GS_PLUGIN_ERROR,
a7f877
+				     GS_PLUGIN_ERROR_NOT_SUPPORTED,
a7f877
+				     "unable to get shell version");
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+	priv->shell_version = g_variant_dup_string (version, NULL);
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_add_installed (GsPlugin *plugin,
a7f877
+			 GsAppList *list,
a7f877
+			 GCancellable *cancellable,
a7f877
+			 GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	GVariantIter *ext_iter;
a7f877
+	gchar *ext_uuid;
a7f877
+	g_autoptr(GVariantIter) iter = NULL;
a7f877
+	g_autoptr(GVariant) retval = NULL;
a7f877
+
a7f877
+	/* installed */
a7f877
+	retval = g_dbus_proxy_call_sync (priv->proxy,
a7f877
+					 "ListExtensions",
a7f877
+					 NULL,
a7f877
+					 G_DBUS_CALL_FLAGS_NONE,
a7f877
+					 -1,
a7f877
+					 cancellable,
a7f877
+					 error);
a7f877
+	if (retval == NULL) {
a7f877
+		gs_utils_error_convert_gdbus (error);
a7f877
+		gs_utils_error_convert_gio (error);
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+
a7f877
+	/* parse each installed extension */
a7f877
+	g_variant_get (retval, "(a{sa{sv}})", &iter);
a7f877
+	while (g_variant_iter_loop (iter, "{sa{sv}}", &ext_uuid, &ext_iter)) {
a7f877
+		g_autoptr(GsApp) app = NULL;
a7f877
+
a7f877
+		/* search in the cache */
a7f877
+		app = gs_plugin_cache_lookup (plugin, ext_uuid);
a7f877
+		if (app != NULL) {
a7f877
+			gs_app_list_add (list, app);
a7f877
+			continue;
a7f877
+		}
a7f877
+
a7f877
+		/* parse the data into an GsApp */
a7f877
+		app = gs_plugin_shell_extensions_parse_installed (plugin,
a7f877
+		                                                  ext_uuid,
a7f877
+		                                                  ext_iter,
a7f877
+		                                                  error);
a7f877
+		if (app == NULL)
a7f877
+			return FALSE;
a7f877
+
a7f877
+		/* ignore system installed */
a7f877
+		if (gs_app_get_scope (app) == AS_APP_SCOPE_SYSTEM)
a7f877
+			continue;
a7f877
+
a7f877
+		/* save in the cache */
a7f877
+		gs_plugin_cache_add (plugin, ext_uuid, app);
a7f877
+
a7f877
+		/* add to results */
a7f877
+		gs_app_list_add (list, app);
a7f877
+	}
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_add_sources (GsPlugin *plugin,
a7f877
+                       GsAppList *list,
a7f877
+                       GCancellable *cancellable,
a7f877
+                       GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	g_autoptr(GsApp) app = NULL;
a7f877
+
a7f877
+	/* create something that we can use to enable/disable */
a7f877
+	app = gs_app_new ("org.gnome.extensions");
a7f877
+	gs_app_set_kind (app, AS_APP_KIND_SOURCE);
a7f877
+	gs_app_set_scope (app, AS_APP_SCOPE_USER);
a7f877
+	if (g_settings_get_boolean (priv->settings, "enable-shell-extensions-repo"))
a7f877
+		gs_app_set_state (app, AS_APP_STATE_INSTALLED);
a7f877
+	else
a7f877
+		gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
a7f877
+	gs_app_add_quirk (app, GS_APP_QUIRK_NOT_LAUNCHABLE);
a7f877
+	gs_app_set_name (app, GS_APP_QUALITY_LOWEST,
a7f877
+	                 _("GNOME Shell Extensions Repository"));
a7f877
+	gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
a7f877
+	                SHELL_EXTENSIONS_API_URI);
a7f877
+	gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
a7f877
+	gs_app_list_add (list, app);
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_refine_app (GsPlugin *plugin,
a7f877
+		      GsApp *app,
a7f877
+		      GsPluginRefineFlags flags,
a7f877
+		      GCancellable *cancellable,
a7f877
+		      GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	const gchar *uuid;
a7f877
+	g_autofree gchar *xpath = NULL;
a7f877
+	g_autoptr(GError) error_local = NULL;
a7f877
+	g_autoptr(GRWLockReaderLocker) locker = NULL;
a7f877
+	g_autoptr(XbNode) component = NULL;
a7f877
+
a7f877
+	/* repo not enabled */
a7f877
+	if (!g_settings_get_boolean (priv->settings, "enable-shell-extensions-repo"))
a7f877
+		return TRUE;
a7f877
+
a7f877
+	/* only process this app if was created by this plugin */
a7f877
+	if (g_strcmp0 (gs_app_get_management_plugin (app),
a7f877
+		       gs_plugin_get_name (plugin)) != 0)
a7f877
+		return TRUE;
a7f877
+
a7f877
+	/* can we get the AppStream-created app state using the cache */
a7f877
+	uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
a7f877
+	if (uuid != NULL && gs_app_get_state (app) == AS_APP_STATE_UNKNOWN) {
a7f877
+		GsApp *app_cache = gs_plugin_cache_lookup (plugin, uuid);
a7f877
+		if (app_cache != NULL) {
a7f877
+			g_debug ("copy cached state for %s",
a7f877
+				 gs_app_get_id (app));
a7f877
+			gs_app_set_state (app, gs_app_get_state (app_cache));
a7f877
+		}
a7f877
+	}
a7f877
+
a7f877
+	/* assume apps are available if they exist in AppStream metadata */
a7f877
+	if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN)
a7f877
+		gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
a7f877
+
a7f877
+	/* FIXME: assume these are small */
a7f877
+	if (gs_app_get_size_installed (app) == 0)
a7f877
+		gs_app_set_size_installed (app, 1024 * 50);
a7f877
+	if (gs_app_get_size_download (app) == 0)
a7f877
+		gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE);
a7f877
+
a7f877
+
a7f877
+	/* check silo is valid */
a7f877
+	if (!_check_silo (plugin, cancellable, error))
a7f877
+		return FALSE;
a7f877
+
a7f877
+	locker = g_rw_lock_reader_locker_new (&priv->silo_lock);
a7f877
+
a7f877
+	/* find the component using the UUID */
a7f877
+	if (uuid == NULL)
a7f877
+		return TRUE;
a7f877
+
a7f877
+	xpath = g_strdup_printf ("components/component/custom/"
a7f877
+				 "value[@key='shell-extensions::uuid'][text()='%s']/../..",
a7f877
+				 uuid);
a7f877
+	component = xb_silo_query_first (priv->silo, xpath, &error_local);
a7f877
+	if (component == NULL) {
a7f877
+		if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
a7f877
+			return TRUE;
a7f877
+		if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT))
a7f877
+			return TRUE;
a7f877
+		g_propagate_error (error, g_steal_pointer (&error_local));
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+	return gs_appstream_refine_app (plugin, app, priv->silo, component, flags, error);
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_refine_wildcard (GsPlugin *plugin,
a7f877
+			   GsApp *app,
a7f877
+			   GsAppList *list,
a7f877
+			   GsPluginRefineFlags refine_flags,
a7f877
+			   GCancellable *cancellable,
a7f877
+			   GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	const gchar *id;
a7f877
+	g_autofree gchar *xpath = NULL;
a7f877
+	g_autoptr(GError) error_local = NULL;
a7f877
+	g_autoptr(GPtrArray) components = NULL;
a7f877
+	g_autoptr(GRWLockReaderLocker) locker = NULL;
a7f877
+
a7f877
+	/* repo not enabled */
a7f877
+	if (!g_settings_get_boolean (priv->settings, "enable-shell-extensions-repo"))
a7f877
+		return TRUE;
a7f877
+
a7f877
+	/* check silo is valid */
a7f877
+	if (!_check_silo (plugin, cancellable, error))
a7f877
+		return FALSE;
a7f877
+
a7f877
+	/* not enough info to find */
a7f877
+	id = gs_app_get_id (app);
a7f877
+	if (id == NULL)
a7f877
+		return TRUE;
a7f877
+
a7f877
+	locker = g_rw_lock_reader_locker_new (&priv->silo_lock);
a7f877
+
a7f877
+	/* find all apps */
a7f877
+	xpath = g_strdup_printf ("components/component/id[text()='%s']/..", id);
a7f877
+	components = xb_silo_query (priv->silo, xpath, 0, &error_local);
a7f877
+	if (components == NULL) {
a7f877
+		if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
a7f877
+			return TRUE;
a7f877
+		if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT))
a7f877
+			return TRUE;
a7f877
+		g_propagate_error (error, g_steal_pointer (&error_local));
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+	for (guint i = 0; i < components->len; i++) {
a7f877
+		XbNode *component = g_ptr_array_index (components, i);
a7f877
+		g_autoptr(GsApp) new = NULL;
a7f877
+		new = gs_appstream_create_app (plugin, priv->silo, component, error);
a7f877
+		if (new == NULL)
a7f877
+			return FALSE;
a7f877
+		gs_app_subsume_metadata (new, app);
a7f877
+		if (!gs_appstream_refine_app (plugin, new, priv->silo, component,
a7f877
+					      refine_flags, error))
a7f877
+			return FALSE;
a7f877
+		gs_app_list_add (list, new);
a7f877
+	}
a7f877
+
a7f877
+	/* success */
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+static gboolean
a7f877
+gs_plugin_shell_extensions_parse_version (GsPlugin *plugin,
a7f877
+					  const gchar *component_id,
a7f877
+					  XbBuilderNode *app,
a7f877
+					  JsonObject *ver_map,
a7f877
+					  GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	JsonObject *json_ver = NULL;
a7f877
+	gint64 version;
a7f877
+	g_autofree gchar *shell_version = NULL;
a7f877
+
a7f877
+	/* look for version, major.minor.micro */
a7f877
+	if (json_object_has_member (ver_map, priv->shell_version)) {
a7f877
+		json_ver = json_object_get_object_member (ver_map,
a7f877
+							  priv->shell_version);
a7f877
+	}
a7f877
+
a7f877
+	/* look for version, major.minor */
a7f877
+	if (json_ver == NULL) {
a7f877
+		g_auto(GStrv) ver_majmin = NULL;
a7f877
+		ver_majmin = g_strsplit (priv->shell_version, ".", -1);
a7f877
+		if (g_strv_length (ver_majmin) >= 2) {
a7f877
+			g_autofree gchar *tmp = NULL;
a7f877
+			tmp = g_strdup_printf ("%s.%s", ver_majmin[0], ver_majmin[1]);
a7f877
+			if (json_object_has_member (ver_map, tmp))
a7f877
+				json_ver = json_object_get_object_member (ver_map, tmp);
a7f877
+		}
a7f877
+	}
a7f877
+
a7f877
+	/* FIXME: mark as incompatible? */
a7f877
+	if (json_ver == NULL)
a7f877
+		return TRUE;
a7f877
+
a7f877
+	/* parse the version */
a7f877
+	version = json_object_get_int_member (json_ver, "version");
a7f877
+	if (version == 0) {
a7f877
+		g_set_error_literal (error,
a7f877
+				     GS_PLUGIN_ERROR,
a7f877
+				     GS_PLUGIN_ERROR_INVALID_FORMAT,
a7f877
+				     "no version in map!");
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+	shell_version = g_strdup_printf ("%" G_GINT64_FORMAT, version);
a7f877
+
a7f877
+	/* add a dummy release */
a7f877
+	xb_builder_node_insert_text (app, "release", NULL,
a7f877
+				     "version", shell_version,
a7f877
+				     NULL);
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+
a7f877
+
a7f877
+static XbBuilderNode *
a7f877
+gs_plugin_shell_extensions_parse_app (GsPlugin *plugin,
a7f877
+				      JsonObject *json_app,
a7f877
+				      GError **error)
a7f877
+{
a7f877
+	JsonObject *json_ver_map;
a7f877
+	const gchar *tmp;
a7f877
+	g_autofree gchar *component_id = NULL;
a7f877
+	g_autoptr(XbBuilderNode) app = NULL;
a7f877
+	g_autoptr(XbBuilderNode) categories = NULL;
a7f877
+	g_autoptr(XbBuilderNode) metadata = NULL;
a7f877
+
a7f877
+	app = xb_builder_node_new ("component");
a7f877
+	xb_builder_node_set_attr (app, "kind", "shell-extension");
a7f877
+	xb_builder_node_insert_text (app, "project_license", "GPL-2.0+", NULL);
a7f877
+	categories = xb_builder_node_insert (app, "categories", NULL);
a7f877
+	xb_builder_node_insert_text (categories, "category", "Addon", NULL);
a7f877
+	xb_builder_node_insert_text (categories, "category", "ShellExtension", NULL);
a7f877
+	metadata = xb_builder_node_insert (app, "custom", NULL);
a7f877
+
a7f877
+	tmp = json_object_get_string_member (json_app, "description");
a7f877
+	if (tmp != NULL) {
a7f877
+		g_auto(GStrv) paras = g_strsplit (tmp, "\n", -1);
a7f877
+		g_autoptr(XbBuilderNode) desc = xb_builder_node_insert (app, "description", NULL);
a7f877
+		for (guint i = 0; paras[i] != NULL; i++)
a7f877
+			xb_builder_node_insert_text (desc, "p", paras[i], NULL);
a7f877
+	}
a7f877
+	tmp = json_object_get_string_member (json_app, "screenshot");
a7f877
+	if (tmp != NULL) {
a7f877
+		g_autoptr(XbBuilderNode) screenshots = NULL;
a7f877
+		g_autoptr(XbBuilderNode) screenshot = NULL;
a7f877
+		g_autofree gchar *uri = NULL;
a7f877
+		screenshots = xb_builder_node_insert (app, "screenshots", NULL);
a7f877
+		screenshot = xb_builder_node_insert (screenshots, "screenshot",
a7f877
+						     "kind", "default",
a7f877
+						     NULL);
a7f877
+		uri = g_build_path ("/", SHELL_EXTENSIONS_API_URI, tmp, NULL);
a7f877
+		xb_builder_node_insert_text (screenshot, "image", uri,
a7f877
+					     "kind", "source",
a7f877
+					     NULL);
a7f877
+	}
a7f877
+	tmp = json_object_get_string_member (json_app, "name");
a7f877
+	if (tmp != NULL)
a7f877
+		xb_builder_node_insert_text (app, "name", tmp, NULL);
a7f877
+	tmp = json_object_get_string_member (json_app, "uuid");
a7f877
+	if (tmp != NULL) {
a7f877
+		component_id = as_utils_appstream_id_build (tmp);
a7f877
+		xb_builder_node_insert_text (app, "id", component_id, NULL);
a7f877
+		xb_builder_node_insert_text (metadata, "value", tmp,
a7f877
+					     "key", "shell-extensions::uuid",
a7f877
+					     NULL);
a7f877
+	}
a7f877
+	tmp = json_object_get_string_member (json_app, "link");
a7f877
+	if (tmp != NULL) {
a7f877
+		g_autofree gchar *uri = NULL;
a7f877
+		uri = g_build_filename (SHELL_EXTENSIONS_API_URI, tmp, NULL);
a7f877
+		xb_builder_node_insert_text (app, "url", uri,
a7f877
+					     "type", "homepage",
a7f877
+					     NULL);
a7f877
+	}
a7f877
+	tmp = json_object_get_string_member (json_app, "icon");
a7f877
+	if (tmp != NULL) {
a7f877
+		/* just use a stock icon as the remote icons are
a7f877
+		 * sometimes missing, poor quality and low resolution */
a7f877
+		xb_builder_node_insert_text (app, "icon",
a7f877
+					     "application-x-addon-symbolic",
a7f877
+					     "type", "stock",
a7f877
+					     NULL);
a7f877
+	}
a7f877
+
a7f877
+	/* try to get version */
a7f877
+	json_ver_map = json_object_get_object_member (json_app, "shell_version_map");
a7f877
+	if (json_ver_map != NULL) {
a7f877
+		if (!gs_plugin_shell_extensions_parse_version (plugin,
a7f877
+							       component_id,
a7f877
+							       app,
a7f877
+							       json_ver_map,
a7f877
+							       error))
a7f877
+			return NULL;
a7f877
+	}
a7f877
+
a7f877
+	return g_steal_pointer (&app);
a7f877
+}
a7f877
+
a7f877
+static GInputStream *
a7f877
+gs_plugin_appstream_load_json_cb (XbBuilderSource *self,
a7f877
+				  XbBuilderSourceCtx *ctx,
a7f877
+				  gpointer user_data,
a7f877
+				  GCancellable *cancellable,
a7f877
+				  GError **error)
a7f877
+{
a7f877
+	GsPlugin *plugin = GS_PLUGIN (user_data);
a7f877
+	JsonArray *json_extensions_array;
a7f877
+	JsonNode *json_extensions;
a7f877
+	JsonNode *json_root;
a7f877
+	JsonObject *json_item;
a7f877
+	gchar *xml;
a7f877
+	g_autoptr(JsonParser) json_parser = NULL;
a7f877
+	g_autoptr(XbBuilderNode) apps = NULL;
a7f877
+
a7f877
+	/* parse the data and find the success */
a7f877
+	json_parser = json_parser_new ();
a7f877
+	if (!json_parser_load_from_stream (json_parser,
a7f877
+					   xb_builder_source_ctx_get_stream (ctx),
a7f877
+					   cancellable, error)) {
a7f877
+		gs_utils_error_convert_json_glib (error);
a7f877
+		return NULL;
a7f877
+	}
a7f877
+	json_root = json_parser_get_root (json_parser);
a7f877
+	if (json_root == NULL) {
a7f877
+		g_set_error_literal (error,
a7f877
+				     GS_PLUGIN_ERROR,
a7f877
+				     GS_PLUGIN_ERROR_INVALID_FORMAT,
a7f877
+				     "no data root");
a7f877
+		return NULL;
a7f877
+	}
a7f877
+	if (json_node_get_node_type (json_root) != JSON_NODE_OBJECT) {
a7f877
+		g_set_error_literal (error,
a7f877
+				     GS_PLUGIN_ERROR,
a7f877
+				     GS_PLUGIN_ERROR_INVALID_FORMAT,
a7f877
+				     "no data object");
a7f877
+		return NULL;
a7f877
+	}
a7f877
+	json_item = json_node_get_object (json_root);
a7f877
+	if (json_item == NULL) {
a7f877
+		g_set_error_literal (error,
a7f877
+				     GS_PLUGIN_ERROR,
a7f877
+				     GS_PLUGIN_ERROR_INVALID_FORMAT,
a7f877
+				     "no data object");
a7f877
+		return NULL;
a7f877
+	}
a7f877
+
a7f877
+	/* load extensions */
a7f877
+	apps = xb_builder_node_new ("components");
a7f877
+	json_extensions = json_object_get_member (json_item, "extensions");
a7f877
+	if (json_extensions == NULL) {
a7f877
+		g_set_error_literal (error,
a7f877
+				     GS_PLUGIN_ERROR,
a7f877
+				     GS_PLUGIN_ERROR_INVALID_FORMAT,
a7f877
+				     "no extensions object");
a7f877
+		return NULL;
a7f877
+	}
a7f877
+	json_extensions_array = json_node_get_array (json_extensions);
a7f877
+	if (json_extensions_array == NULL) {
a7f877
+		g_set_error_literal (error,
a7f877
+				     GS_PLUGIN_ERROR,
a7f877
+				     GS_PLUGIN_ERROR_INVALID_FORMAT,
a7f877
+				     "no extensions array");
a7f877
+		return NULL;
a7f877
+	}
a7f877
+
a7f877
+	/* parse each app */
a7f877
+	for (guint i = 0; i < json_array_get_length (json_extensions_array); i++) {
a7f877
+		JsonNode *json_extension;
a7f877
+		JsonObject *json_extension_obj;
a7f877
+		g_autoptr(XbBuilderNode) component = NULL;
a7f877
+
a7f877
+		json_extension = json_array_get_element (json_extensions_array, i);
a7f877
+		json_extension_obj = json_node_get_object (json_extension);
a7f877
+		component = gs_plugin_shell_extensions_parse_app (plugin,
a7f877
+							    json_extension_obj,
a7f877
+							    error);
a7f877
+		if (component == NULL)
a7f877
+			return NULL;
a7f877
+		xb_builder_node_add_child (apps, component);
a7f877
+	}
a7f877
+
a7f877
+	/* convert back to XML */
a7f877
+	xml = xb_builder_node_export (apps, XB_NODE_EXPORT_FLAG_ADD_HEADER, error);
a7f877
+	if (xml == NULL)
a7f877
+		return NULL;
a7f877
+	return g_memory_input_stream_new_from_data (xml, -1, g_free);
a7f877
+}
a7f877
+
a7f877
+static gboolean
a7f877
+gs_plugin_shell_extensions_refresh (GsPlugin *plugin,
a7f877
+				    guint cache_age,
a7f877
+				    GCancellable *cancellable,
a7f877
+				    GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	g_autofree gchar *fn = NULL;
a7f877
+	g_autofree gchar *uri = NULL;
a7f877
+	g_autoptr(GFile) file = NULL;
a7f877
+	g_autoptr(GRWLockReaderLocker) locker = NULL;
a7f877
+	g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin));
a7f877
+
a7f877
+	/* get cache filename */
a7f877
+	fn = gs_utils_get_cache_filename ("shell-extensions",
a7f877
+					  "gnome.json",
a7f877
+					  GS_UTILS_CACHE_FLAG_WRITEABLE,
a7f877
+					  error);
a7f877
+	if (fn == NULL)
a7f877
+		return FALSE;
a7f877
+
a7f877
+	/* check age */
a7f877
+	file = g_file_new_for_path (fn);
a7f877
+	if (g_file_query_exists (file, NULL)) {
a7f877
+		guint age = gs_utils_get_file_age (file);
a7f877
+		if (age < cache_age) {
a7f877
+			g_debug ("%s is only %u seconds old, ignoring", fn, age);
a7f877
+			return TRUE;
a7f877
+		}
a7f877
+	}
a7f877
+
a7f877
+	/* download the file */
a7f877
+	uri = g_strdup_printf ("%s/static/extensions.json",
a7f877
+			       SHELL_EXTENSIONS_API_URI);
a7f877
+	gs_app_set_summary_missing (app_dl,
a7f877
+				    /* TRANSLATORS: status text when downloading */
a7f877
+				    _("Downloading shell extension metadata…"));
a7f877
+	if (!gs_plugin_download_file (plugin, app_dl, uri, fn, cancellable, error)) {
a7f877
+		gs_utils_error_add_origin_id (error, priv->cached_origin);
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+
a7f877
+	/* be explicit */
a7f877
+	locker = g_rw_lock_reader_locker_new (&priv->silo_lock);
a7f877
+	if (priv->silo != NULL)
a7f877
+		xb_silo_invalidate (priv->silo);
a7f877
+
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+static gboolean
a7f877
+_check_silo (GsPlugin *plugin, GCancellable *cancellable, GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	g_autofree gchar *blobfn = NULL;
a7f877
+	g_autofree gchar *fn = NULL;
a7f877
+	g_autoptr(GError) error_local = NULL;
a7f877
+	g_autoptr(GFile) blobfile = NULL;
a7f877
+	g_autoptr(GFile) file = NULL;
a7f877
+	g_autoptr(GRWLockReaderLocker) reader_locker = NULL;
a7f877
+	g_autoptr(GRWLockWriterLocker) writer_locker = NULL;
a7f877
+	g_autoptr(XbBuilder) builder = xb_builder_new ();
a7f877
+	g_autoptr(XbBuilderNode) info = NULL;
a7f877
+	g_autoptr(XbBuilderSource) source = xb_builder_source_new ();
a7f877
+
a7f877
+	reader_locker = g_rw_lock_reader_locker_new (&priv->silo_lock);
a7f877
+	/* everything is okay */
a7f877
+	if (priv->silo != NULL && xb_silo_is_valid (priv->silo)) {
a7f877
+		g_debug ("silo already valid");
a7f877
+		return TRUE;
a7f877
+	}
a7f877
+	g_clear_pointer (&reader_locker, g_rw_lock_reader_locker_free);
a7f877
+
a7f877
+	/* drat! silo needs regenerating */
a7f877
+	writer_locker = g_rw_lock_writer_locker_new (&priv->silo_lock);
a7f877
+	g_clear_object (&priv->silo);
a7f877
+
a7f877
+	/* verbose profiling */
a7f877
+	if (g_getenv ("GS_XMLB_VERBOSE") != NULL) {
a7f877
+		xb_builder_set_profile_flags (builder,
a7f877
+					      XB_SILO_PROFILE_FLAG_XPATH |
a7f877
+					      XB_SILO_PROFILE_FLAG_DEBUG);
a7f877
+	}
a7f877
+
a7f877
+	/* add metadata */
a7f877
+	info = xb_builder_node_insert (NULL, "info", NULL);
a7f877
+	xb_builder_node_insert_text (info, "scope", "user", NULL);
a7f877
+	xb_builder_source_set_info (source, info);
a7f877
+
a7f877
+	/* add support for JSON files */
a7f877
+	fn = gs_utils_get_cache_filename ("shell-extensions",
a7f877
+					  "gnome.json",
a7f877
+					  GS_UTILS_CACHE_FLAG_WRITEABLE,
a7f877
+					  error);
a7f877
+	if (fn == NULL)
a7f877
+		return FALSE;
a7f877
+	xb_builder_source_add_adapter (source, "application/json",
a7f877
+				       gs_plugin_appstream_load_json_cb,
a7f877
+				       plugin, NULL);
a7f877
+	file = g_file_new_for_path (fn);
a7f877
+	if (!xb_builder_source_load_file (source, file,
a7f877
+					  XB_BUILDER_SOURCE_FLAG_WATCH_FILE,
a7f877
+					  cancellable,
a7f877
+					  error)) {
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+	xb_builder_import_source (builder, source);
a7f877
+
a7f877
+	/* create binary cache */
a7f877
+	blobfn = gs_utils_get_cache_filename ("shell-extensions",
a7f877
+					      "extensions-web.xmlb",
a7f877
+					      GS_UTILS_CACHE_FLAG_WRITEABLE,
a7f877
+					      error);
a7f877
+	if (blobfn == NULL)
a7f877
+		return FALSE;
a7f877
+	blobfile = g_file_new_for_path (blobfn);
a7f877
+	g_debug ("ensuring %s", blobfn);
a7f877
+	priv->silo = xb_builder_ensure (builder, blobfile,
a7f877
+					XB_BUILDER_COMPILE_FLAG_IGNORE_INVALID,
a7f877
+					NULL, &error_local);
a7f877
+	if (priv->silo == NULL) {
a7f877
+		g_set_error (error,
a7f877
+			     GS_PLUGIN_ERROR,
a7f877
+			     GS_PLUGIN_ERROR_FAILED,
a7f877
+			     "failed to compile %s",
a7f877
+			     error_local->message);
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+
a7f877
+	/* success */
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+static void
a7f877
+_claim_components (GsPlugin *plugin, GsAppList *list)
a7f877
+{
a7f877
+	for (guint i = 0; i < gs_app_list_length (list); i++) {
a7f877
+		GsApp *app = gs_app_list_index (list, i);
a7f877
+		gs_app_set_kind (app, AS_APP_KIND_SHELL_EXTENSION);
a7f877
+		gs_app_set_origin_hostname (app, SHELL_EXTENSIONS_API_URI);
a7f877
+		gs_app_set_origin (app, _("GNOME"));
a7f877
+		gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
a7f877
+		gs_app_set_summary (app, GS_APP_QUALITY_LOWEST,
a7f877
+				    /* TRANSLATORS: the one-line summary */
a7f877
+				    _("GNOME Shell Extension"));
a7f877
+	}
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_add_search (GsPlugin *plugin, gchar **values, GsAppList *list,
a7f877
+		      GCancellable *cancellable, GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	g_autoptr(GRWLockReaderLocker) locker = NULL;
a7f877
+	g_autoptr(GsAppList) list_tmp = gs_app_list_new ();
a7f877
+	if (!g_settings_get_boolean (priv->settings, "enable-shell-extensions-repo"))
a7f877
+		return TRUE;
a7f877
+	if (!_check_silo (plugin, cancellable, error))
a7f877
+		return FALSE;
a7f877
+	locker = g_rw_lock_reader_locker_new (&priv->silo_lock);
a7f877
+	if (!gs_appstream_search (plugin, priv->silo, (const gchar * const *) values, list_tmp,
a7f877
+				  cancellable, error))
a7f877
+		return FALSE;
a7f877
+	_claim_components (plugin, list_tmp);
a7f877
+	gs_app_list_add_list (list, list_tmp);
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_add_category_apps (GsPlugin *plugin, GsCategory *category, GsAppList *list,
a7f877
+			     GCancellable *cancellable, GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	g_autoptr(GRWLockReaderLocker) locker = NULL;
a7f877
+	if (!g_settings_get_boolean (priv->settings, "enable-shell-extensions-repo"))
a7f877
+		return TRUE;
a7f877
+	if (!_check_silo (plugin, cancellable, error))
a7f877
+		return FALSE;
a7f877
+	locker = g_rw_lock_reader_locker_new (&priv->silo_lock);
a7f877
+	return gs_appstream_add_category_apps (plugin, priv->silo, category,
a7f877
+					       list, cancellable, error);
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_refresh (GsPlugin *plugin,
a7f877
+		   guint cache_age,
a7f877
+		   GCancellable *cancellable,
a7f877
+		   GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	if (!g_settings_get_boolean (priv->settings, "enable-shell-extensions-repo"))
a7f877
+		return TRUE;
a7f877
+	if (!gs_plugin_shell_extensions_refresh (plugin,
a7f877
+						 cache_age,
a7f877
+						 cancellable,
a7f877
+						 error))
a7f877
+		return FALSE;
a7f877
+	return _check_silo (plugin, cancellable, error);
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_app_remove (GsPlugin *plugin,
a7f877
+		      GsApp *app,
a7f877
+		      GCancellable *cancellable,
a7f877
+		      GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	const gchar *uuid;
a7f877
+	gboolean ret;
a7f877
+	g_autoptr(GVariant) retval = NULL;
a7f877
+
a7f877
+	/* only process this app if was created by this plugin */
a7f877
+	if (g_strcmp0 (gs_app_get_management_plugin (app),
a7f877
+		       gs_plugin_get_name (plugin)) != 0)
a7f877
+		return TRUE;
a7f877
+
a7f877
+	/* disable repository */
a7f877
+	if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE) {
a7f877
+		gs_app_set_state (app, AS_APP_STATE_REMOVING);
a7f877
+		g_settings_set_boolean (priv->settings, "enable-shell-extensions-repo", FALSE);
a7f877
+		/* remove appstream data */
a7f877
+		ret = gs_plugin_shell_extensions_refresh (plugin,
a7f877
+		                                          G_MAXUINT,
a7f877
+		                                          cancellable,
a7f877
+		                                          error);
a7f877
+		gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
a7f877
+		return ret;
a7f877
+	}
a7f877
+
a7f877
+	/* remove */
a7f877
+	gs_app_set_state (app, AS_APP_STATE_REMOVING);
a7f877
+	uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
a7f877
+	retval = g_dbus_proxy_call_sync (priv->proxy,
a7f877
+					 "UninstallExtension",
a7f877
+					 g_variant_new ("(s)", uuid),
a7f877
+					 G_DBUS_CALL_FLAGS_NONE,
a7f877
+					 -1,
a7f877
+					 cancellable,
a7f877
+					 error);
a7f877
+	if (retval == NULL) {
a7f877
+		gs_utils_error_convert_gio (error);
a7f877
+		gs_app_set_state_recover (app);
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+
a7f877
+	/* not sure why this would fail -- perhaps installed in /usr? */
a7f877
+	g_variant_get (retval, "(b)", &ret;;
a7f877
+	if (!ret) {
a7f877
+		gs_app_set_state_recover (app);
a7f877
+		g_set_error (error,
a7f877
+			     GS_PLUGIN_ERROR,
a7f877
+			     GS_PLUGIN_ERROR_NOT_SUPPORTED,
a7f877
+			     "failed to uninstall %s",
a7f877
+			     gs_app_get_id (app));
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+
a7f877
+	/* state is not known: we don't know if we can re-install this app */
a7f877
+	gs_app_set_state (app, AS_APP_STATE_UNKNOWN);
a7f877
+
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_app_install (GsPlugin *plugin,
a7f877
+		       GsApp *app,
a7f877
+		       GCancellable *cancellable,
a7f877
+		       GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	const gchar *uuid;
a7f877
+	const gchar *retstr;
a7f877
+	g_autoptr(GVariant) retval = NULL;
a7f877
+
a7f877
+	/* only process this app if was created by this plugin */
a7f877
+	if (g_strcmp0 (gs_app_get_management_plugin (app),
a7f877
+		       gs_plugin_get_name (plugin)) != 0)
a7f877
+		return TRUE;
a7f877
+
a7f877
+	/* enable repository */
a7f877
+	if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE) {
a7f877
+		gboolean ret;
a7f877
+
a7f877
+		gs_app_set_state (app, AS_APP_STATE_INSTALLING);
a7f877
+		g_settings_set_boolean (priv->settings, "enable-shell-extensions-repo", TRUE);
a7f877
+		/* refresh metadata */
a7f877
+		ret = gs_plugin_shell_extensions_refresh (plugin,
a7f877
+		                                          G_MAXUINT,
a7f877
+		                                          cancellable,
a7f877
+		                                          error);
a7f877
+		gs_app_set_state (app, AS_APP_STATE_INSTALLED);
a7f877
+		return ret;
a7f877
+	}
a7f877
+
a7f877
+	/* install */
a7f877
+	uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
a7f877
+	gs_app_set_state (app, AS_APP_STATE_INSTALLING);
a7f877
+	retval = g_dbus_proxy_call_sync (priv->proxy,
a7f877
+					 "InstallRemoteExtension",
a7f877
+					 g_variant_new ("(s)", uuid),
a7f877
+					 G_DBUS_CALL_FLAGS_NONE,
a7f877
+					 -1,
a7f877
+					 cancellable,
a7f877
+					 error);
a7f877
+	if (retval == NULL) {
a7f877
+		gs_app_set_state_recover (app);
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+	g_variant_get (retval, "(&s)", &retstr);
a7f877
+
a7f877
+	/* user declined download */
a7f877
+	if (g_strcmp0 (retstr, "cancelled") == 0) {
a7f877
+		gs_app_set_state_recover (app);
a7f877
+		g_set_error (error,
a7f877
+			     GS_PLUGIN_ERROR,
a7f877
+			     GS_PLUGIN_ERROR_CANCELLED,
a7f877
+			     "extension %s download was cancelled",
a7f877
+			     gs_app_get_id (app));
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+	g_debug ("shell returned: %s", retstr);
a7f877
+
a7f877
+	/* state is known */
a7f877
+	gs_app_set_state (app, AS_APP_STATE_INSTALLED);
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_launch (GsPlugin *plugin,
a7f877
+		  GsApp *app,
a7f877
+		  GCancellable *cancellable,
a7f877
+		  GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+	g_autofree gchar *uuid = NULL;
a7f877
+	g_autoptr(GVariant) retval = NULL;
a7f877
+
a7f877
+	/* launch both PackageKit-installed and user-installed */
a7f877
+	if (gs_app_get_kind (app) != AS_APP_KIND_SHELL_EXTENSION)
a7f877
+		return TRUE;
a7f877
+
a7f877
+	uuid = g_strdup (gs_app_get_metadata_item (app, "shell-extensions::uuid"));
a7f877
+	if (uuid == NULL) {
a7f877
+		const gchar *suffix = ".shell-extension";
a7f877
+		const gchar *id = gs_app_get_id (app);
a7f877
+		/* PackageKit-installed extension ID generated by appstream-builder */
a7f877
+		if (g_str_has_suffix (id, suffix))
a7f877
+			uuid = g_strndup (id, strlen (id) - strlen (suffix));
a7f877
+	}
a7f877
+	if (uuid == NULL) {
a7f877
+		g_set_error (error,
a7f877
+			     GS_PLUGIN_ERROR,
a7f877
+			     GS_PLUGIN_ERROR_FAILED,
a7f877
+			     "no uuid set for %s",
a7f877
+			     gs_app_get_id (app));
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+	/* launch */
a7f877
+	retval = g_dbus_proxy_call_sync (priv->proxy,
a7f877
+					 "LaunchExtensionPrefs",
a7f877
+					 g_variant_new ("(s)", uuid),
a7f877
+					 G_DBUS_CALL_FLAGS_NONE,
a7f877
+					 -1,
a7f877
+					 cancellable,
a7f877
+					 error);
a7f877
+	if (retval == NULL) {
a7f877
+		gs_utils_error_convert_gio (error);
a7f877
+		return FALSE;
a7f877
+	}
a7f877
+	return TRUE;
a7f877
+}
a7f877
+
a7f877
+gboolean
a7f877
+gs_plugin_add_categories (GsPlugin *plugin,
a7f877
+			  GPtrArray *list,
a7f877
+			  GCancellable *cancellable,
a7f877
+			  GError **error)
a7f877
+{
a7f877
+	GsPluginData *priv = gs_plugin_get_data (plugin);
a7f877
+
a7f877
+	/* repo not enabled */
a7f877
+	if (!g_settings_get_boolean (priv->settings, "enable-shell-extensions-repo"))
a7f877
+		return TRUE;
a7f877
+
a7f877
+	/* just ensure there is any data, no matter how old */
a7f877
+	return gs_plugin_shell_extensions_refresh (plugin,
a7f877
+						   G_MAXUINT,
a7f877
+						   cancellable,
a7f877
+						   error);
a7f877
+}
a7f877
diff --git a/plugins/shell-extensions/gs-self-test.c b/plugins/shell-extensions/gs-self-test.c
a7f877
new file mode 100644
a7f877
index 00000000..f96ee60d
a7f877
--- /dev/null
a7f877
+++ b/plugins/shell-extensions/gs-self-test.c
a7f877
@@ -0,0 +1,156 @@
a7f877
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
a7f877
+ *
a7f877
+ * Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
a7f877
+ *
a7f877
+ * SPDX-License-Identifier: GPL-2.0+
a7f877
+ */
a7f877
+
a7f877
+#include "config.h"
a7f877
+
a7f877
+#include <glib/gstdio.h>
a7f877
+#include <xmlb.h>
a7f877
+
a7f877
+#include "gnome-software-private.h"
a7f877
+
a7f877
+#include "gs-test.h"
a7f877
+
a7f877
+static void
a7f877
+gs_plugins_shell_extensions_installed_func (GsPluginLoader *plugin_loader)
a7f877
+{
a7f877
+	GsApp *app;
a7f877
+	g_autoptr(GError) error = NULL;
a7f877
+	g_autoptr(GsAppList) list = NULL;
a7f877
+	g_autoptr(GsPluginJob) plugin_job = NULL;
a7f877
+
a7f877
+	/* no shell-extensions, abort */
a7f877
+	if (!gs_plugin_loader_get_enabled (plugin_loader, "shell-extensions")) {
a7f877
+		g_test_skip ("not enabled");
a7f877
+		return;
a7f877
+	}
a7f877
+
a7f877
+	/* get installed packages */
a7f877
+	plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_INSTALLED,
a7f877
+					 "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_CATEGORIES,
a7f877
+					 NULL);
a7f877
+	list = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
a7f877
+	gs_test_flush_main_context ();
a7f877
+	g_assert_no_error (error);
a7f877
+	g_assert (list != NULL);
a7f877
+
a7f877
+	/* no shell-extensions installed, abort */
a7f877
+	if (gs_app_list_length (list) < 1) {
a7f877
+		g_test_skip ("no shell extensions installed");
a7f877
+		return;
a7f877
+	}
a7f877
+
a7f877
+	/* test properties */
a7f877
+	app = gs_app_list_lookup (list, "*/*/*/*/background-logo_fedorahosted.org/*");
a7f877
+	if (app == NULL) {
a7f877
+		g_test_skip ("not found");
a7f877
+		return;
a7f877
+	}
a7f877
+
a7f877
+	g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
a7f877
+	g_assert_cmpint (gs_app_get_scope (app), ==, AS_APP_SCOPE_USER);
a7f877
+	g_assert_cmpstr (gs_app_get_name (app), ==, "Background Logo");
a7f877
+	g_assert_cmpstr (gs_app_get_summary (app), ==, "GNOME Shell Extension");
a7f877
+	g_assert_cmpstr (gs_app_get_description (app), ==,
a7f877
+			 "Overlay a tasteful logo on the background to "
a7f877
+			 "enhance the user experience");
a7f877
+	g_assert_cmpstr (gs_app_get_license (app), ==, "GPL-2.0+");
a7f877
+	g_assert_cmpstr (gs_app_get_management_plugin (app), ==, "shell-extensions");
a7f877
+	g_assert (gs_app_has_category (app, "Addon"));
a7f877
+	g_assert (gs_app_has_category (app, "ShellExtension"));
a7f877
+	g_assert_cmpstr (gs_app_get_metadata_item (app, "shell-extensions::has-prefs"), ==, "");
a7f877
+	g_assert_cmpstr (gs_app_get_metadata_item (app, "shell-extensions::uuid"), ==,
a7f877
+			 "background-logo@fedorahosted.org");
a7f877
+}
a7f877
+
a7f877
+static void
a7f877
+gs_plugins_shell_extensions_remote_func (GsPluginLoader *plugin_loader)
a7f877
+{
a7f877
+	const gchar *cachedir = "/var/tmp/gs-self-test";
a7f877
+	gboolean ret;
a7f877
+	g_autofree gchar *fn = NULL;
a7f877
+	g_autoptr(GError) error = NULL;
a7f877
+	g_autoptr(GFile) file = NULL;
a7f877
+	g_autoptr(GPtrArray) components = NULL;
a7f877
+	g_autoptr(GsPluginJob) plugin_job = NULL;
a7f877
+	g_autoptr(XbSilo) silo = NULL;
a7f877
+
a7f877
+	/* no shell-extensions, abort */
a7f877
+	if (!gs_plugin_loader_get_enabled (plugin_loader, "shell-extensions")) {
a7f877
+		g_test_skip ("not enabled");
a7f877
+		return;
a7f877
+	}
a7f877
+
a7f877
+	/* ensure files are removed */
a7f877
+	g_setenv ("GS_SELF_TEST_CACHEDIR", cachedir, TRUE);
a7f877
+	gs_utils_rmtree (cachedir, NULL);
a7f877
+
a7f877
+	/* refresh the metadata */
a7f877
+	plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
a7f877
+					 "age", (guint64) G_MAXUINT,
a7f877
+					 NULL);
a7f877
+	ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
a7f877
+	g_assert_no_error (error);
a7f877
+	g_assert (ret);
a7f877
+
a7f877
+	/* ensure file was populated */
a7f877
+	silo = xb_silo_new ();
a7f877
+	fn = gs_utils_get_cache_filename ("shell-extensions",
a7f877
+					  "extensions-web.xmlb",
a7f877
+					  GS_UTILS_CACHE_FLAG_WRITEABLE,
a7f877
+					  &error);
a7f877
+	g_assert_no_error (error);
a7f877
+	g_assert_nonnull (fn);
a7f877
+	file = g_file_new_for_path (fn);
a7f877
+	ret = xb_silo_load_from_file (silo, file,
a7f877
+				      XB_SILO_LOAD_FLAG_NONE,
a7f877
+				      NULL, &error);
a7f877
+	g_assert_no_error (error);
a7f877
+	g_assert (ret);
a7f877
+	components = xb_silo_query (silo, "components/component", 0, &error);
a7f877
+	g_assert_no_error (error);
a7f877
+	g_assert_nonnull (components);
a7f877
+	g_assert_cmpint (components->len, >, 20);
a7f877
+}
a7f877
+
a7f877
+int
a7f877
+main (int argc, char **argv)
a7f877
+{
a7f877
+	gboolean ret;
a7f877
+	g_autoptr(GError) error = NULL;
a7f877
+	g_autoptr(GsPluginLoader) plugin_loader = NULL;
a7f877
+	const gchar *whitelist[] = {
a7f877
+		"shell-extensions",
a7f877
+		NULL
a7f877
+	};
a7f877
+
a7f877
+	g_test_init (&argc, &argv, NULL);
a7f877
+	g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
a7f877
+
a7f877
+	/* only critical and error are fatal */
a7f877
+	g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
a7f877
+
a7f877
+	/* we can only load this once per process */
a7f877
+	plugin_loader = gs_plugin_loader_new ();
a7f877
+	gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
a7f877
+	ret = gs_plugin_loader_setup (plugin_loader,
a7f877
+				      (gchar**) whitelist,
a7f877
+				      NULL,
a7f877
+				      NULL,
a7f877
+				      &error);
a7f877
+	g_assert_no_error (error);
a7f877
+	g_assert (ret);
a7f877
+
a7f877
+	/* plugin tests go here */
a7f877
+	g_test_add_data_func ("/gnome-software/plugins/shell-extensions/installed",
a7f877
+			      plugin_loader,
a7f877
+			      (GTestDataFunc) gs_plugins_shell_extensions_installed_func);
a7f877
+	g_test_add_data_func ("/gnome-software/plugins/shell-extensions/remote",
a7f877
+			      plugin_loader,
a7f877
+			      (GTestDataFunc) gs_plugins_shell_extensions_remote_func);
a7f877
+
a7f877
+	return g_test_run ();
a7f877
+}
a7f877
diff --git a/plugins/shell-extensions/meson.build b/plugins/shell-extensions/meson.build
a7f877
new file mode 100644
a7f877
index 00000000..3a008f7b
a7f877
--- /dev/null
a7f877
+++ b/plugins/shell-extensions/meson.build
a7f877
@@ -0,0 +1,47 @@
a7f877
+cargs = ['-DG_LOG_DOMAIN="GsPluginShellExtensions"']
a7f877
+cargs += ['-DLOCALPLUGINDIR="' + meson.current_build_dir() + '"']
a7f877
+
a7f877
+shared_module(
a7f877
+  'gs_plugin_shell-extensions',
a7f877
+  sources : [
a7f877
+    'gs-appstream.c',
a7f877
+    'gs-plugin-shell-extensions.c'
a7f877
+  ],
a7f877
+  include_directories : [
a7f877
+    include_directories('../..'),
a7f877
+    include_directories('../../lib'),
a7f877
+  ],
a7f877
+  install : true,
a7f877
+  install_dir: plugin_dir,
a7f877
+  c_args : cargs,
a7f877
+  dependencies : [
a7f877
+    plugin_libs,
a7f877
+    libxmlb,
a7f877
+  ],
a7f877
+  link_with : [
a7f877
+    libgnomesoftware
a7f877
+  ]
a7f877
+)
a7f877
+
a7f877
+if get_option('tests')
a7f877
+  e = executable(
a7f877
+    'gs-self-test-shell-extensions',
a7f877
+    compiled_schemas,
a7f877
+    sources : [
a7f877
+      'gs-self-test.c'
a7f877
+    ],
a7f877
+    include_directories : [
a7f877
+      include_directories('../..'),
a7f877
+      include_directories('../../lib'),
a7f877
+    ],
a7f877
+    dependencies : [
a7f877
+      plugin_libs,
a7f877
+      libxmlb,
a7f877
+    ],
a7f877
+    link_with : [
a7f877
+      libgnomesoftware
a7f877
+    ],
a7f877
+    c_args : cargs,
a7f877
+  )
a7f877
+  test('gs-self-test-shell-extensions', e, suite: ['plugins', 'shell-extensions'], env: test_env)
a7f877
+endif
a7f877
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
a7f877
index 10467436..a786d48d 100644
a7f877
--- a/src/gs-category-page.c
a7f877
+++ b/src/gs-category-page.c
a7f877
@@ -38,6 +38,8 @@ struct _GsCategoryPage
a7f877
 	guint		sort_name_handler_id;
a7f877
 	SubcategorySortType sort_type;
a7f877
 
a7f877
+	GtkWidget	*infobar_category_shell_extensions;
a7f877
+	GtkWidget	*button_category_shell_extensions;
a7f877
 	GtkWidget	*category_detail_box;
a7f877
 	GtkWidget	*scrolledwindow_category;
a7f877
 	GtkWidget	*subcats_filter_label;
a7f877
@@ -321,6 +323,12 @@ gs_category_page_reload (GsPage *page)
a7f877
 		gtk_widget_set_visible (self->subcats_sort_button, TRUE);
a7f877
 	}
a7f877
 
a7f877
+	/* show the shell extensions header */
a7f877
+	if (g_strcmp0 (gs_category_get_id (self->subcategory), "shell-extensions") == 0)
a7f877
+		gtk_widget_set_visible (self->infobar_category_shell_extensions, TRUE);
a7f877
+	else
a7f877
+		gtk_widget_set_visible (self->infobar_category_shell_extensions, FALSE);
a7f877
+
a7f877
 	if (self->sort_rating_handler_id > 0) {
a7f877
 		g_signal_handler_disconnect (self->sort_rating_button,
a7f877
 					     self->sort_rating_handler_id);
a7f877
@@ -524,6 +532,18 @@ gs_category_page_dispose (GObject *object)
a7f877
 	G_OBJECT_CLASS (gs_category_page_parent_class)->dispose (object);
a7f877
 }
a7f877
 
a7f877
+static void
a7f877
+button_shell_extensions_cb (GtkButton *button, GsCategoryPage *self)
a7f877
+{
a7f877
+	gboolean ret;
a7f877
+	g_autoptr(GError) error = NULL;
a7f877
+	const gchar *argv[] = { "gnome-shell-extension-prefs", NULL };
a7f877
+	ret = g_spawn_async (NULL, (gchar **) argv, NULL, G_SPAWN_SEARCH_PATH,
a7f877
+			     NULL, NULL, NULL, &error);
a7f877
+	if (!ret)
a7f877
+		g_warning ("failed to exec %s: %s", argv[0], error->message);
a7f877
+}
a7f877
+
a7f877
 static gboolean
a7f877
 gs_category_page_setup (GsPage *page,
a7f877
                         GsShell *shell,
a7f877
@@ -545,6 +565,9 @@ gs_category_page_setup (GsPage *page,
a7f877
 
a7f877
 	adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolledwindow_category));
a7f877
 	gtk_container_set_focus_vadjustment (GTK_CONTAINER (self->category_detail_box), adj);
a7f877
+
a7f877
+	g_signal_connect (self->button_category_shell_extensions, "clicked",
a7f877
+			  G_CALLBACK (button_shell_extensions_cb), self);
a7f877
 	return TRUE;
a7f877
 }
a7f877
 
a7f877
@@ -563,6 +586,8 @@ gs_category_page_class_init (GsCategoryPageClass *klass)
a7f877
 	gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-category-page.ui");
a7f877
 
a7f877
 	gtk_widget_class_bind_template_child (widget_class, GsCategoryPage, category_detail_box);
a7f877
+	gtk_widget_class_bind_template_child (widget_class, GsCategoryPage, infobar_category_shell_extensions);
a7f877
+	gtk_widget_class_bind_template_child (widget_class, GsCategoryPage, button_category_shell_extensions);
a7f877
 	gtk_widget_class_bind_template_child (widget_class, GsCategoryPage, scrolledwindow_category);
a7f877
 	gtk_widget_class_bind_template_child (widget_class, GsCategoryPage, subcats_filter_label);
a7f877
 	gtk_widget_class_bind_template_child (widget_class, GsCategoryPage, subcats_filter_button_label);
a7f877
diff --git a/src/gs-category-page.ui b/src/gs-category-page.ui
a7f877
index cbb82840..2a3c789f 100644
a7f877
--- a/src/gs-category-page.ui
a7f877
+++ b/src/gs-category-page.ui
a7f877
@@ -97,6 +97,51 @@
a7f877
                                 <property name="margin_end">24</property>
a7f877
                               </object>
a7f877
                             </child>
a7f877
+                            <child>
a7f877
+                              <object class="GtkInfoBar" id="infobar_category_shell_extensions">
a7f877
+                                <property name="visible">False</property>
a7f877
+                                <property name="app_paintable">True</property>
a7f877
+                                <property name="hexpand">True</property>
a7f877
+                                <property name="message_type">other</property>
a7f877
+                                <property name="margin_start">24</property>
a7f877
+                                <property name="margin_top">24</property>
a7f877
+                                <property name="margin_end">24</property>
a7f877
+                                <style>
a7f877
+                                  <class name="application-details-infobar"/>
a7f877
+                                </style>
a7f877
+                                <child internal-child="action_area">
a7f877
+                                  <object class="GtkButtonBox">
a7f877
+                                    <property name="spacing">6</property>
a7f877
+                                    <property name="layout_style">end</property>
a7f877
+                                    <child>
a7f877
+                                      <object class="GtkButton" id="button_category_shell_extensions">
a7f877
+                                        <property name="label" translatable="yes">Extension Settings</property>
a7f877
+                                        <property name="visible">True</property>
a7f877
+                                        <property name="can_focus">True</property>
a7f877
+                                        <property name="receives_default">True</property>
a7f877
+                                        <property name="hexpand">True</property>
a7f877
+                                      </object>
a7f877
+                                    </child>
a7f877
+                                  </object>
a7f877
+                                </child>
a7f877
+                                <child internal-child="content_area">
a7f877
+                                  <object class="GtkBox">
a7f877
+                                    <property name="halign">start</property>
a7f877
+                                    <property name="hexpand">True</property>
a7f877
+                                    <property name="spacing">16</property>
a7f877
+                                    <child>
a7f877
+                                      <object class="GtkLabel">
a7f877
+                                        <property name="visible">True</property>
a7f877
+                                        <property name="wrap">True</property>
a7f877
+                                        <property name="label" translatable="yes">Extensions are used at your own risk. If you have any system problems, it is recommended to disable them.</property>
a7f877
+                                        <property name="hexpand">True</property>
a7f877
+                                      </object>
a7f877
+                                    </child>
a7f877
+                                  </object>
a7f877
+                                </child>
a7f877
+                              </object>
a7f877
+                            </child>
a7f877
+
a7f877
                             <child>
a7f877
                               <object class="GtkBox">
a7f877
                                 <property name="visible">True</property>
a7f877
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
a7f877
index 8eb07bd3..37a717bf 100644
a7f877
--- a/src/gs-details-page.c
a7f877
+++ b/src/gs-details-page.c
a7f877
@@ -923,9 +923,17 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
a7f877
 		break;
a7f877
 	}
a7f877
 
a7f877
-	gtk_button_set_label (GTK_BUTTON (self->button_details_launch),
a7f877
-			      /* TRANSLATORS: A label for a button to execute the selected application. */
a7f877
-			      _("_Launch"));
a7f877
+	if (gs_app_get_kind (self->app) == AS_APP_KIND_SHELL_EXTENSION) {
a7f877
+		gtk_button_set_label (GTK_BUTTON (self->button_details_launch),
a7f877
+		                      /* TRANSLATORS: A label for a button to show the settings for
a7f877
+		                         the selected shell extension. */
a7f877
+		                      _("Extension Settings"));
a7f877
+	} else {
a7f877
+		gtk_button_set_label (GTK_BUTTON (self->button_details_launch),
a7f877
+		                      /* TRANSLATORS: A label for a button to execute the selected
a7f877
+		                         application. */
a7f877
+		                      _("_Launch"));
a7f877
+	}
a7f877
 
a7f877
 	/* don't show the launch and shortcut buttons if the app doesn't have a desktop ID */
a7f877
 	if (gs_app_get_id (self->app) == NULL) {
a7f877
diff --git a/src/gs-repo-row.c b/src/gs-repo-row.c
a7f877
index 35b35045..7ce7e618 100644
a7f877
--- a/src/gs-repo-row.c
a7f877
+++ b/src/gs-repo-row.c
a7f877
@@ -68,7 +68,8 @@ repo_supports_removal (GsApp *repo)
a7f877
 	/* can't remove a repo, only enable/disable existing ones */
a7f877
 	if (g_strcmp0 (management_plugin, "fwupd") == 0 ||
a7f877
 	    g_strcmp0 (management_plugin, "packagekit") == 0 ||
a7f877
-	    g_strcmp0 (management_plugin, "rpm-ostree") == 0)
a7f877
+	    g_strcmp0 (management_plugin, "rpm-ostree") == 0 ||
a7f877
+	    g_strcmp0 (management_plugin, "shell-extensions") == 0)
a7f877
 		return FALSE;
a7f877
 
a7f877
 	return TRUE;
a7f877
diff --git a/src/gs-repos-dialog.c b/src/gs-repos-dialog.c
a7f877
index 93830308..7c11dc78 100644
a7f877
--- a/src/gs-repos-dialog.c
a7f877
+++ b/src/gs-repos-dialog.c
a7f877
@@ -136,7 +136,8 @@ repo_supports_removal (GsApp *repo)
a7f877
 	/* can't remove a repo, only enable/disable existing ones */
a7f877
 	if (g_strcmp0 (management_plugin, "fwupd") == 0 ||
a7f877
 	    g_strcmp0 (management_plugin, "packagekit") == 0 ||
a7f877
-	    g_strcmp0 (management_plugin, "rpm-ostree") == 0)
a7f877
+	    g_strcmp0 (management_plugin, "rpm-ostree") == 0 ||
a7f877
+	    g_strcmp0 (management_plugin, "shell-extensions") == 0)
a7f877
 		return FALSE;
a7f877
 
a7f877
 	return TRUE;
a7f877
diff --git a/src/gs-summary-tile.c b/src/gs-summary-tile.c
a7f877
index 446200de..90e810c9 100644
a7f877
--- a/src/gs-summary-tile.c
a7f877
+++ b/src/gs-summary-tile.c
a7f877
@@ -41,7 +41,7 @@ gs_summary_tile_refresh (GsAppTile *self)
a7f877
 	const GdkPixbuf *pixbuf;
a7f877
 	gboolean installed;
a7f877
 	g_autofree gchar *name = NULL;
a7f877
-	const gchar *summary;
a7f877
+	g_autofree gchar *summary = NULL;
a7f877
 	const gchar *css;
a7f877
 
a7f877
 	if (app == NULL)
a7f877
@@ -53,7 +53,18 @@ gs_summary_tile_refresh (GsAppTile *self)
a7f877
 	/* set name */
a7f877
 	gtk_label_set_label (GTK_LABEL (tile->name), gs_app_get_name (app));
a7f877
 
a7f877
-	summary = gs_app_get_summary (app);
a7f877
+	/* some kinds have boring summaries */
a7f877
+	switch (gs_app_get_kind (app)) {
a7f877
+	case AS_APP_KIND_SHELL_EXTENSION:
a7f877
+		summary = g_strdup (gs_app_get_description (app));
a7f877
+		if (summary != NULL)
a7f877
+			g_strdelimit (summary, "\n\t", ' ');
a7f877
+		break;
a7f877
+	default:
a7f877
+		summary = g_strdup (gs_app_get_summary (app));
a7f877
+		break;
a7f877
+	}
a7f877
+
a7f877
 	gtk_label_set_label (GTK_LABEL (tile->summary), summary);
a7f877
 	gtk_widget_set_visible (tile->summary, summary && summary[0]);
a7f877
 
a7f877
-- 
a7f877
2.18.2
a7f877
a7f877
a7f877
From 420396f45380ce4da2a609f139e5f7f47a6d5d5d Mon Sep 17 00:00:00 2001
a7f877
From: Kalev Lember <klember@redhat.com>
a7f877
Date: Wed, 3 Jun 2020 15:50:44 +0200
a7f877
Subject: [PATCH 2/2] Revert "Update POTFILES.in"
a7f877
a7f877
This reverts commit 9afc91a6de17117a32e4d36210230ba218e8ea7d.
a7f877
---
a7f877
 po/POTFILES.in | 1 +
a7f877
 1 file changed, 1 insertion(+)
a7f877
a7f877
diff --git a/po/POTFILES.in b/po/POTFILES.in
a7f877
index a44a6ad3..c38c56e2 100644
a7f877
--- a/po/POTFILES.in
a7f877
+++ b/po/POTFILES.in
a7f877
@@ -88,5 +88,6 @@ plugins/fwupd/gs-plugin-fwupd.c
a7f877
 plugins/fwupd/org.gnome.Software.Plugin.Fwupd.metainfo.xml.in
a7f877
 plugins/odrs/gs-plugin-odrs.c
a7f877
 plugins/odrs/org.gnome.Software.Plugin.Odrs.metainfo.xml.in
a7f877
+plugins/shell-extensions/gs-plugin-shell-extensions.c
a7f877
 plugins/snap/gs-plugin-snap.c
a7f877
 plugins/snap/org.gnome.Software.Plugin.Snap.metainfo.xml.in
a7f877
-- 
a7f877
2.18.2
a7f877