[gnome-software/wip/kalev/shell-extensions-enable-disable: 1/2] shell extensions: Implement repo enable/disable
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/kalev/shell-extensions-enable-disable: 1/2] shell extensions: Implement repo enable/disable
- Date: Tue, 20 Feb 2018 19:36:46 +0000 (UTC)
commit 700f204c700b7b08828e3ad13079dbddaff4369a
Author: Kalev Lember <klember redhat com>
Date: Tue Feb 20 18:43:41 2018 +0100
shell extensions: Implement repo enable/disable
Add a gsettings key for controlling whether extensions.gnome.org repo is
enabled, and implement plugin functions for enabling/disabling the repo
so that it correctly shows up in the repos dialog as "GNOME Shell
Extensions Repository".
data/org.gnome.software.gschema.xml | 4 ++
.../shell-extensions/gs-plugin-shell-extensions.c | 72 ++++++++++++++++++++++
2 files changed, 76 insertions(+)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index 0722fe46..0d07c985 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -130,5 +130,9 @@
<default>false</default>
<summary>Install the AppStream files to a system-wide location for all users</summary>
</key>
+ <key name="enable-shell-extensions-repo" type="b">
+ <default>true</default>
+ <summary>Enable GNOME Shell extensions repository</summary>
+ </key>
</schema>
</schemalist>
diff --git a/plugins/shell-extensions/gs-plugin-shell-extensions.c
b/plugins/shell-extensions/gs-plugin-shell-extensions.c
index 75d8c494..2ea817f1 100644
--- a/plugins/shell-extensions/gs-plugin-shell-extensions.c
+++ b/plugins/shell-extensions/gs-plugin-shell-extensions.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <glib/gi18n.h>
+#include <glib/gstdio.h>
#include <json-glib/json-glib.h>
#include <gnome-software.h>
@@ -44,6 +45,7 @@ struct GsPluginData {
GDBusProxy *proxy;
gchar *shell_version;
GsApp *cached_origin;
+ GSettings *settings;
};
typedef enum {
@@ -73,6 +75,8 @@ gs_plugin_initialize (GsPlugin *plugin)
gs_app_set_kind (priv->cached_origin, AS_APP_KIND_SOURCE);
gs_app_set_origin_hostname (priv->cached_origin, SHELL_EXTENSIONS_API_URI);
+ priv->settings = g_settings_new ("org.gnome.software");
+
/* add the source to the plugin cache which allows us to match the
* unique ID to a GsApp when creating an event */
gs_plugin_cache_add (plugin,
@@ -88,6 +92,7 @@ gs_plugin_destroy (GsPlugin *plugin)
if (priv->proxy != NULL)
g_object_unref (priv->proxy);
g_object_unref (priv->cached_origin);
+ g_object_unref (priv->settings);
}
void
@@ -359,6 +364,33 @@ gs_plugin_add_installed (GsPlugin *plugin,
return TRUE;
}
+gboolean
+gs_plugin_add_sources (GsPlugin *plugin,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_autoptr(GsApp) app = NULL;
+
+ /* create something that we can use to enable/disable */
+ app = gs_app_new ("org.gnome.extensions");
+ gs_app_set_kind (app, AS_APP_KIND_SOURCE);
+ gs_app_set_scope (app, AS_APP_SCOPE_USER);
+ if (g_settings_get_boolean (priv->settings, "enable-shell-extensions-repo"))
+ gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+ else
+ gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+ gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
+ gs_app_set_name (app, GS_APP_QUALITY_LOWEST,
+ _("GNOME Shell Extensions Repository"));
+ gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
+ SHELL_EXTENSIONS_API_URI);
+ gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
+ gs_app_list_add (list, app);
+ return TRUE;
+}
+
gboolean
gs_plugin_refine_app (GsPlugin *plugin,
GsApp *app,
@@ -710,7 +742,9 @@ gs_plugin_shell_extensions_refresh (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
AsApp *app;
+ gboolean repo_enabled;
const gchar *fn_test;
guint i;
g_autofree gchar *fn = NULL;
@@ -718,6 +752,11 @@ gs_plugin_shell_extensions_refresh (GsPlugin *plugin,
g_autoptr(AsStore) store = NULL;
g_autoptr(GFile) file = NULL;
+ /* repo disabled? */
+ repo_enabled = g_settings_get_boolean (priv->settings, "enable-shell-extensions-repo");
+ if (!repo_enabled)
+ return TRUE;
+
/* no longer interesting */
if ((flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) == 0)
return TRUE;
@@ -801,6 +840,23 @@ gs_plugin_app_remove (GsPlugin *plugin,
gs_plugin_get_name (plugin)) != 0)
return TRUE;
+ /* disable repository */
+ if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE) {
+ g_autofree gchar *fn = NULL;
+
+ gs_app_set_state (app, AS_APP_STATE_REMOVING);
+ g_settings_set_boolean (priv->settings, "enable-shell-extensions-repo", FALSE);
+ /* remove appstream data */
+ fn = g_build_filename (g_get_user_data_dir (),
+ "app-info",
+ "xmls",
+ "extensions-web.xml",
+ NULL);
+ g_unlink (fn);
+ gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+ return TRUE;
+ }
+
/* remove */
gs_app_set_state (app, AS_APP_STATE_REMOVING);
uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
@@ -851,6 +907,22 @@ gs_plugin_app_install (GsPlugin *plugin,
gs_plugin_get_name (plugin)) != 0)
return TRUE;
+ /* enable repository */
+ if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE) {
+ gboolean ret;
+
+ gs_app_set_state (app, AS_APP_STATE_INSTALLING);
+ g_settings_set_boolean (priv->settings, "enable-shell-extensions-repo", TRUE);
+ /* refresh metadata */
+ ret = gs_plugin_shell_extensions_refresh (plugin,
+ G_MAXUINT,
+ GS_PLUGIN_REFRESH_FLAGS_METADATA,
+ cancellable,
+ error);
+ gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+ return ret;
+ }
+
/* install */
uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
gs_app_set_state (app, AS_APP_STATE_INSTALLING);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]