[gnome-software] Allow plugins to inhibit the updates functionality



commit 81dbe62b22ec0e8479bb99521eda58ecafafd9ff
Author: Richard Hughes <richard hughsie com>
Date:   Fri Oct 28 21:03:40 2016 +0100

    Allow plugins to inhibit the updates functionality
    
    This allows us to move the PackageKit permission check into the right place,
    and also allows other plugins to offer new functionality.
    
    Based on a patch from Joaquim Rocha <jrocha endlessm com>, many thanks.

 data/org.gnome.software.gschema.xml     |    5 ++
 src/gs-plugin-loader.c                  |   94 +++++++++++++++++++++++++++++++
 src/gs-plugin-loader.h                  |    1 +
 src/gs-plugin.c                         |   29 ++++++++++
 src/gs-plugin.h                         |    6 ++-
 src/gs-shell-updates.c                  |   30 +++-------
 src/gs-shell.c                          |   30 +++-------
 src/gs-update-monitor.c                 |   26 ---------
 src/gs-update-monitor.h                 |    2 -
 src/plugins/gs-plugin-dummy.c           |   17 ++++++
 src/plugins/gs-plugin-systemd-updates.c |   21 +++++++
 11 files changed, 192 insertions(+), 69 deletions(-)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index 2f9f0f5..05467d5 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -5,6 +5,11 @@
       <summary>A list of compatible projects</summary>
       <description>This is a list of compatible projects we should show such as GNOME, KDE and 
XFCE.</description>
     </key>
+    <key name="allow-updates" type="b">
+      <default>true</default>
+      <summary>Whether to manage updates in GNOME Software</summary>
+      <description>If disabled, GNOME Software will hide the updates panel and not perform any automatic 
updates actions.</description>
+    </key>
     <key name="download-updates" type="b">
       <default>true</default>
       <summary>Whether to automatically download updates</summary>
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 9d7826a..f727ff7 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -64,6 +64,7 @@ typedef struct
        guint                    updates_changed_id;
        guint                    reload_id;
        gboolean                 online; 
+       GHashTable              *disallow_updates;      /* GsPlugin : const char *name */
 } GsPluginLoaderPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsPluginLoader, gs_plugin_loader, G_TYPE_OBJECT)
@@ -79,6 +80,7 @@ enum {
 enum {
        PROP_0,
        PROP_EVENTS,
+       PROP_ALLOW_UPDATES,
        PROP_LAST
 };
 
@@ -3563,6 +3565,26 @@ gs_plugin_loader_app_action_finish (GsPluginLoader *plugin_loader,
 
 /******************************************************************************/
 
+gboolean
+gs_plugin_loader_get_allow_updates (GsPluginLoader *plugin_loader)
+{
+       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       g_autoptr(GList) list = NULL;
+       GList *l;
+
+       /* nothing */
+       if (g_hash_table_size (priv->disallow_updates) == 0)
+               return TRUE;
+
+       /* list */
+       list = g_hash_table_get_values (priv->disallow_updates);
+       for (l = list; l != NULL; l = l->next) {
+               const gchar *reason = l->data;
+               g_debug ("managed updates inhibited by %s", reason);
+       }
+       return FALSE;
+}
+
 GsAppList *
 gs_plugin_loader_get_pending (GsPluginLoader *plugin_loader)
 {
@@ -3709,6 +3731,38 @@ gs_plugin_loader_report_event_cb (GsPlugin *plugin,
 }
 
 static void
+gs_plugin_loader_allow_updates_cb (GsPlugin *plugin,
+                                  gboolean allow_updates,
+                                  GsPluginLoader *plugin_loader)
+{
+       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       gpointer exists;
+
+       /* plugin now allowing gnome-software to show updates panel */
+       exists = g_hash_table_lookup (priv->disallow_updates, plugin);
+       if (allow_updates) {
+               if (exists == NULL)
+                       return;
+               g_debug ("plugin %s no longer inhibited managed updates",
+                        gs_plugin_get_name (plugin));
+               g_hash_table_remove (priv->disallow_updates, plugin);
+
+       /* plugin preventing the updates panel from being shown */
+       } else {
+               if (exists != NULL)
+                       return;
+               g_debug ("plugin %s inhibited managed updates",
+                        gs_plugin_get_name (plugin));
+               g_hash_table_insert (priv->disallow_updates,
+                                    (gpointer) plugin,
+                                    (gpointer) gs_plugin_get_name (plugin));
+       }
+
+       /* something possibly changed, so notify display layer */
+       g_object_notify (G_OBJECT (plugin_loader), "allow-updates");
+}
+
+static void
 gs_plugin_loader_status_changed_cb (GsPlugin *plugin,
                                    GsApp *app,
                                    GsPluginStatus status,
@@ -3820,6 +3874,9 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        g_signal_connect (plugin, "report-event",
                          G_CALLBACK (gs_plugin_loader_report_event_cb),
                          plugin_loader);
+       g_signal_connect (plugin, "allow-updates",
+                         G_CALLBACK (gs_plugin_loader_allow_updates_cb),
+                         plugin_loader);
        gs_plugin_set_soup_session (plugin, priv->soup_session);
        gs_plugin_set_auth_array (plugin, priv->auth_array);
        gs_plugin_set_profile (plugin, priv->profile);
@@ -4205,6 +4262,9 @@ gs_plugin_loader_get_property (GObject *object, guint prop_id,
        case PROP_EVENTS:
                g_value_set_pointer (value, priv->events_by_id);
                break;
+       case PROP_ALLOW_UPDATES:
+               g_value_set_boolean (value, gs_plugin_loader_get_allow_updates (plugin_loader));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -4257,6 +4317,7 @@ gs_plugin_loader_finalize (GObject *object)
        g_free (priv->language);
        g_object_unref (priv->global_cache);
        g_hash_table_unref (priv->events_by_id);
+       g_hash_table_unref (priv->disallow_updates);
 
        g_mutex_clear (&priv->pending_apps_mutex);
        g_mutex_clear (&priv->events_by_id_mutex);
@@ -4280,6 +4341,11 @@ gs_plugin_loader_class_init (GsPluginLoaderClass *klass)
                                     G_PARAM_READABLE);
        g_object_class_install_property (object_class, PROP_EVENTS, pspec);
 
+       pspec = g_param_spec_boolean ("allow-updates", NULL, NULL,
+                                     TRUE,
+                                     G_PARAM_READABLE);
+       g_object_class_install_property (object_class, PROP_ALLOW_UPDATES, pspec);
+
        signals [SIGNAL_STATUS_CHANGED] =
                g_signal_new ("status-changed",
                              G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
@@ -4307,6 +4373,28 @@ gs_plugin_loader_class_init (GsPluginLoaderClass *klass)
 }
 
 static void
+gs_plugin_loader_allow_updates_recheck (GsPluginLoader *plugin_loader)
+{
+       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       if (g_settings_get_boolean (priv->settings, "allow-updates")) {
+               g_hash_table_remove (priv->disallow_updates, plugin_loader);
+       } else {
+               g_hash_table_insert (priv->disallow_updates,
+                                    (gpointer) plugin_loader,
+                                    (gpointer) "GSettings");
+       }
+}
+
+static void
+gs_plugin_loader_settings_changed_cb (GSettings *settings,
+                                     const gchar *key,
+                                     GsPluginLoader *plugin_loader)
+{
+       if (g_strcmp0 (key, "allow-updates"))
+               gs_plugin_loader_allow_updates_recheck (plugin_loader);
+}
+
+static void
 gs_plugin_loader_init (GsPluginLoader *plugin_loader)
 {
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
@@ -4323,6 +4411,8 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
        priv->auth_array = g_ptr_array_new_with_free_func ((GFreeFunc) g_object_unref);
        priv->profile = as_profile_new ();
        priv->settings = g_settings_new ("org.gnome.software");
+       g_signal_connect (priv->settings, "changed",
+                         G_CALLBACK (gs_plugin_loader_settings_changed_cb), plugin_loader);
        priv->events_by_id = g_hash_table_new_full ((GHashFunc) as_utils_unique_id_hash,
                                                    (GEqualFunc) as_utils_unique_id_equal,
                                                    g_free,
@@ -4350,6 +4440,10 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
                        *match = '\0';
        }
 
+       /* the settings key sets the initial override */
+       priv->disallow_updates = g_hash_table_new (g_direct_hash, g_direct_equal);
+       gs_plugin_loader_allow_updates_recheck (plugin_loader);
+
        /* get the language from the locale */
        priv->language = g_strdup (priv->locale);
        match = g_strrstr (priv->language, "_");
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index 7501cc0..9049d8e 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -230,6 +230,7 @@ void                 gs_plugin_loader_refresh_async         (GsPluginLoader 
*plugin_loader,
                                                         GAsyncReadyCallback callback,
                                                         gpointer        user_data);
 GsAppList      *gs_plugin_loader_get_pending           (GsPluginLoader *plugin_loader);
+gboolean        gs_plugin_loader_get_allow_updates     (GsPluginLoader *plugin_loader);
 void            gs_plugin_loader_set_network_status    (GsPluginLoader *plugin_loader,
                                                         gboolean        online);
 gboolean        gs_plugin_loader_get_plugin_supported  (GsPluginLoader *plugin_loader,
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 9b2d318..3b70808 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -91,6 +91,7 @@ enum {
        SIGNAL_STATUS_CHANGED,
        SIGNAL_RELOAD,
        SIGNAL_REPORT_EVENT,
+       SIGNAL_ALLOW_UPDATES,
        SIGNAL_LAST
 };
 
@@ -1292,6 +1293,27 @@ gs_plugin_report_event (GsPlugin *plugin, GsPluginEvent *event)
 }
 
 /**
+ * gs_plugin_set_allow_updates:
+ * @plugin: a #GsPlugin
+ * @allow_updates: boolean
+ *
+ * This allows plugins to inhibit the showing of the updates panel.
+ * This will typically be used when the required permissions are not possible
+ * to obtain, or when a LiveUSB image is low on space.
+ *
+ * By default, the updates panel is shown so plugins do not need to call this
+ * function unless they called gs_plugin_set_allow_updates() with %FALSE.
+ *
+ * Since: 3.24
+ **/
+void
+gs_plugin_set_allow_updates (GsPlugin *plugin, gboolean allow_updates)
+{
+       g_return_if_fail (GS_IS_PLUGIN (plugin));
+       g_signal_emit (plugin, signals[SIGNAL_ALLOW_UPDATES], 0, allow_updates);
+}
+
+/**
  * gs_plugin_error_to_string:
  * @error: a #GsPluginError, e.g. %GS_PLUGIN_ERROR_NO_NETWORK
  *
@@ -1496,6 +1518,13 @@ gs_plugin_class_init (GsPluginClass *klass)
                              G_STRUCT_OFFSET (GsPluginClass, report_event),
                              NULL, NULL, g_cclosure_marshal_generic,
                              G_TYPE_NONE, 1, GS_TYPE_PLUGIN_EVENT);
+
+       signals [SIGNAL_ALLOW_UPDATES] =
+               g_signal_new ("allow-updates",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (GsPluginClass, allow_updates),
+                             NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
+                             G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 }
 
 static void
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 72ff9ec..b4977dd 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -51,7 +51,9 @@ struct _GsPluginClass
        void                    (*reload)               (GsPlugin       *plugin);
        void                    (*report_event)         (GsPlugin       *plugin,
                                                         GsPluginEvent  *event);
-       gpointer                 padding[27];
+       void                    (*allow_updates)        (GsPlugin       *plugin,
+                                                        gboolean        allow_updates);
+       gpointer                 padding[26];
 };
 
 typedef struct GsPluginData    GsPluginData;
@@ -119,6 +121,8 @@ void                 gs_plugin_reload                       (GsPlugin       *plugin);
 const gchar    *gs_plugin_status_to_string             (GsPluginStatus  status);
 void            gs_plugin_report_event                 (GsPlugin       *plugin,
                                                         GsPluginEvent  *event);
+void            gs_plugin_set_allow_updates            (GsPlugin       *plugin,
+                                                        gboolean        allow_updates);
 
 G_END_DECLS
 
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index cf66891..67b7088 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -526,7 +526,8 @@ gs_shell_updates_get_updates_cb (GsPluginLoader *plugin_loader,
        /* update the counter */
        widget = GTK_WIDGET (gtk_builder_get_object (self->builder,
                                                     "button_updates_counter"));
-       if (gs_app_list_length (list) > 0 && !gs_update_monitor_is_managed ()) {
+       if (gs_app_list_length (list) > 0 &&
+           gs_plugin_loader_get_allow_updates (self->plugin_loader)) {
                g_autofree gchar *text = NULL;
                text = g_strdup_printf ("%u", gs_app_list_length (list));
                gtk_label_set_label (GTK_LABEL (widget), text);
@@ -1280,12 +1281,11 @@ gs_shell_updates_status_changed_cb (GsPluginLoader *plugin_loader,
 }
 
 static void
-on_permission_changed (GPermission *permission,
-                       GParamSpec  *pspec,
-                       gpointer     data)
+gs_shell_updates_allow_updates_notify_cb (GsPluginLoader *plugin_loader,
+                                           GParamSpec *pspec,
+                                           GsShellUpdates *self)
 {
-       GsShellUpdates *self = GS_SHELL_UPDATES (data);
-       if (gs_update_monitor_is_managed()) {
+       if (!gs_plugin_loader_get_allow_updates (plugin_loader)) {
                gs_shell_updates_set_state (self, GS_SHELL_UPDATES_STATE_MANAGED);
                return;
        }
@@ -1293,17 +1293,6 @@ on_permission_changed (GPermission *permission,
 }
 
 static void
-gs_shell_updates_monitor_permission (GsShellUpdates *self)
-{
-        GPermission *permission;
-
-        permission = gs_update_monitor_permission_get ();
-       if (permission != NULL)
-               g_signal_connect (permission, "notify",
-                                 G_CALLBACK (on_permission_changed), self);
-}
-
-static void
 gs_shell_updates_upgrade_cancel_cb (GsUpgradeBanner *upgrade_banner,
                                    GsShellUpdates *self)
 {
@@ -1333,6 +1322,9 @@ gs_shell_updates_setup (GsShellUpdates *self,
        g_signal_connect (self->plugin_loader, "updates-changed",
                          G_CALLBACK (gs_shell_updates_changed_cb),
                          self);
+       g_signal_connect_object (self->plugin_loader, "notify::allow-updates",
+                                G_CALLBACK (gs_shell_updates_allow_updates_notify_cb),
+                                self, 0);
        self->builder = g_object_ref (builder);
        self->cancellable = g_object_ref (cancellable);
 
@@ -1387,10 +1379,8 @@ gs_shell_updates_setup (GsShellUpdates *self,
                          G_CALLBACK (gs_shell_updates_button_network_settings_cb),
                          self);
 
-       gs_shell_updates_monitor_permission (self);
-
        /* set initial state */
-       if (gs_update_monitor_is_managed ())
+       if (!gs_plugin_loader_get_allow_updates (self->plugin_loader))
                self->state = GS_SHELL_UPDATES_STATE_MANAGED;
 
        if (self->network_monitor != NULL) {
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 6c044b5..91c4db6 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -299,7 +299,8 @@ gs_shell_change_mode (GsShell *shell,
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_updates"));
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), mode == GS_SHELL_MODE_UPDATES);
-       gtk_widget_set_visible (widget, !gs_update_monitor_is_managed() || mode == GS_SHELL_MODE_UPDATES);
+       gtk_widget_set_visible (widget, gs_plugin_loader_get_allow_updates (priv->plugin_loader) ||
+                                       mode == GS_SHELL_MODE_UPDATES);
 
        priv->ignore_primary_buttons = FALSE;
 
@@ -668,27 +669,15 @@ gs_shell_main_window_mapped_cb (GtkWidget *widget, GsShell *shell)
 }
 
 static void
-on_permission_changed (GPermission *permission,
-                       GParamSpec  *pspec,
-                       gpointer     data)
+gs_shell_allow_updates_notify_cb (GsPluginLoader *plugin_loader,
+                                   GParamSpec *pspec,
+                                   GsShell *shell)
 {
-        GsShell *shell = data;
        GsShellPrivate *priv = gs_shell_get_instance_private (shell);
        GtkWidget *widget;
-
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_updates"));
-       gtk_widget_set_visible (widget, !gs_update_monitor_is_managed() || priv->mode == 
GS_SHELL_MODE_UPDATES);
-}
-
-static void
-gs_shell_monitor_permission (GsShell *shell)
-{
-        GPermission *permission;
-
-        permission = gs_update_monitor_permission_get ();
-       if (permission != NULL)
-               g_signal_connect (permission, "notify",
-                                 G_CALLBACK (on_permission_changed), shell);
+       gtk_widget_set_visible (widget, gs_plugin_loader_get_allow_updates (plugin_loader) ||
+                                       priv->mode == GS_SHELL_MODE_UPDATES);
 }
 
 typedef enum {
@@ -1436,10 +1425,11 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
        g_signal_connect_object (priv->plugin_loader, "notify::events",
                                 G_CALLBACK (gs_shell_events_notify_cb),
                                 shell, 0);
+       g_signal_connect_object (priv->plugin_loader, "notify::allow-updates",
+                                G_CALLBACK (gs_shell_allow_updates_notify_cb),
+                                shell, 0);
        priv->cancellable = g_object_ref (cancellable);
 
-       gs_shell_monitor_permission (shell);
-
        /* get UI */
        priv->builder = gtk_builder_new_from_resource ("/org/gnome/Software/gnome-software.ui");
        priv->main_window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "window_software"));
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index e47cb1e..afe576b 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -757,30 +757,4 @@ gs_update_monitor_new (GsApplication *application)
        return monitor;
 }
 
-GPermission *
-gs_update_monitor_permission_get (void)
-{
-       static GPermission *permission = NULL;
-#ifdef HAVE_PACKAGEKIT
-       if (permission == NULL)
-               permission = gs_utils_get_permission ("org.freedesktop.packagekit.trigger-offline-update");
-#endif
-       return permission;
-}
-
-gboolean
-gs_update_monitor_is_managed (void)
-{
-       GPermission *permission;
-       gboolean managed;
-
-       permission = gs_update_monitor_permission_get ();
-       if (permission == NULL)
-               return FALSE;
-       managed = !g_permission_get_allowed (permission) &&
-                  !g_permission_get_can_acquire (permission);
-
-       return managed;
-}
-
 /* vim: set noexpandtab: */
diff --git a/src/gs-update-monitor.h b/src/gs-update-monitor.h
index d30552d..15f57a6 100644
--- a/src/gs-update-monitor.h
+++ b/src/gs-update-monitor.h
@@ -36,8 +36,6 @@ G_DECLARE_FINAL_TYPE (GsUpdateMonitor, gs_update_monitor, GS, UPDATE_MONITOR, GO
 GsUpdateMonitor        *gs_update_monitor_new                  (GsApplication  *app);
 void            gs_update_monitor_show_error           (GsUpdateMonitor *monitor,
                                                         GsShell        *shell);
-GPermission    *gs_update_monitor_permission_get       (void);
-gboolean        gs_update_monitor_is_managed           (void);
 
 G_END_DECLS
 
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index 8244ea9..80cf496 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -30,11 +30,24 @@
 
 struct GsPluginData {
        guint                    quirk_id;
+       guint                    allow_updates_id;
+       gboolean                 allow_updates_inhibit;
        guint                    has_auth;
        GsAuth                  *auth;
        GsApp                   *cached_origin;
 };
 
+/* just flip-flop this every few seconds */
+static gboolean
+gs_plugin_dummy_allow_updates_cb (gpointer user_data)
+{
+       GsPlugin *plugin = GS_PLUGIN (user_data);
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       gs_plugin_set_allow_updates (plugin, priv->allow_updates_inhibit);
+       priv->allow_updates_inhibit = !priv->allow_updates_inhibit;
+       return G_SOURCE_CONTINUE;
+}
+
 void
 gs_plugin_initialize (GsPlugin *plugin)
 {
@@ -46,6 +59,10 @@ gs_plugin_initialize (GsPlugin *plugin)
                return;
        }
 
+       /* toggle this */
+       priv->allow_updates_id = g_timeout_add_seconds (10,
+               gs_plugin_dummy_allow_updates_cb, plugin);
+
        /* set up a dummy authentication provider */
        priv->auth = gs_auth_new (gs_plugin_get_name (plugin));
        gs_auth_set_provider_name (priv->auth, "GNOME SSO");
diff --git a/src/plugins/gs-plugin-systemd-updates.c b/src/plugins/gs-plugin-systemd-updates.c
index d368bfa..7d6bbd7 100644
--- a/src/plugins/gs-plugin-systemd-updates.c
+++ b/src/plugins/gs-plugin-systemd-updates.c
@@ -36,6 +36,7 @@
 
 struct GsPluginData {
        GFileMonitor            *monitor;
+       GPermission             *permission;
 };
 
 void
@@ -53,6 +54,17 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 static void
+gs_plugin_systemd_updates_permission_cb (GPermission *permission,
+                                        GParamSpec *pspec,
+                                        gpointer data)
+{
+       GsPlugin *plugin = GS_PLUGIN (data);
+       gboolean ret = g_permission_get_allowed (permission) ||
+                       g_permission_get_can_acquire (permission);
+       gs_plugin_set_allow_updates (plugin, ret);
+}
+
+static void
 gs_plugin_systemd_updates_changed_cb (GFileMonitor *monitor,
                                      GFile *file, GFile *other_file,
                                      GFileMonitorEvent event_type,
@@ -76,6 +88,15 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        g_signal_connect (priv->monitor, "changed",
                          G_CALLBACK (gs_plugin_systemd_updates_changed_cb),
                          plugin);
+
+       /* check if we have permission to trigger the update */
+       priv->permission = gs_utils_get_permission (
+               "org.freedesktop.packagekit.trigger-offline-update");
+       if (priv->permission != NULL) {
+               g_signal_connect (priv->permission, "notify",
+                                 G_CALLBACK (gs_plugin_systemd_updates_permission_cb),
+                                 plugin);
+       }
        return TRUE;
 }
 


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