[gnome-software] Untrigger the offline update if we call Reboot() and it fails



commit 16b5de89a6b7517ae520a5ecbc3de8aff18b1b1f
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jan 28 16:13:54 2016 +0000

    Untrigger the offline update if we call Reboot() and it fails
    
    In this case the user dismissed the shell dialog, and we want to undo the
    trigger that we just set.

 src/gs-application.c                    |   57 +++++++++++++++++++++++++++++-
 src/gs-plugin-loader.c                  |    5 +++
 src/gs-plugin-loader.h                  |    1 +
 src/gs-plugin.h                         |    4 ++
 src/gs-shell-updates.c                  |   59 ++++++++++++++++++++++++++++++-
 src/gs-utils.c                          |   42 ----------------------
 src/gs-utils.h                          |    1 -
 src/plugins/gs-plugin-systemd-updates.c |   12 ++++++
 8 files changed, 136 insertions(+), 45 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 2d892a4..a637c20 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -369,6 +369,49 @@ profile_activated (GSimpleAction *action,
 }
 
 /**
+ * cancel_trigger_failed_cb:
+ **/
+static void
+cancel_trigger_failed_cb (GObject *source, GAsyncResult *res, gpointer user_data)
+{
+       GsApplication *app = GS_APPLICATION (user_data);
+       g_autoptr(GError) error = NULL;
+       if (!gs_plugin_loader_app_action_finish (app->plugin_loader, res, &error)) {
+               g_warning ("failed to cancel trigger: %s", error->message);
+               return;
+       }
+}
+
+/**
+ * reboot_failed_cb:
+ **/
+static void
+reboot_failed_cb (GObject *source, GAsyncResult *res, gpointer user_data)
+{
+       GsApplication *app = GS_APPLICATION (user_data);
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GVariant) retval = NULL;
+
+       /* get result */
+       retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
+       if (retval != NULL)
+               return;
+
+       if (error != NULL) {
+               g_warning ("Calling org.gnome.SessionManager.Reboot failed: %s",
+                          error->message);
+       }
+
+       /* cancel trigger */
+       gs_plugin_loader_app_action_async (app->plugin_loader,
+                                          NULL, /* everything! */
+                                          GS_PLUGIN_LOADER_ACTION_OFFLINE_UPDATE_CANCEL,
+                                          app->cancellable,
+                                          cancel_trigger_failed_cb,
+                                          app);
+}
+
+/**
  * offline_update_cb:
  **/
 static void
@@ -376,12 +419,24 @@ offline_update_cb (GsPluginLoader *plugin_loader,
                   GAsyncResult *res,
                   GsApplication *app)
 {
+       g_autoptr(GDBusConnection) bus = NULL;
        g_autoptr(GError) error = NULL;
        if (!gs_plugin_loader_offline_update_finish (plugin_loader, res, &error)) {
                g_warning ("Failed to trigger offline update: %s", error->message);
                return;
        }
-       gs_reboot (NULL);
+
+       /* trigger reboot */
+       bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+       g_dbus_connection_call (bus,
+                               "org.gnome.SessionManager",
+                               "/org/gnome/SessionManager",
+                               "org.gnome.SessionManager",
+                               "Reboot",
+                               NULL, NULL, G_DBUS_CALL_FLAGS_NONE,
+                               G_MAXINT, NULL,
+                               reboot_failed_cb,
+                               app);
 }
 
 static void
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index f88ed47..3aa9512 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -2621,6 +2621,11 @@ gs_plugin_loader_app_action_async (GsPluginLoader *plugin_loader,
                state->state_success = AS_APP_STATE_UNKNOWN;
                state->state_failure = AS_APP_STATE_UNKNOWN;
                break;
+       case GS_PLUGIN_LOADER_ACTION_OFFLINE_UPDATE_CANCEL:
+               state->function_name = "gs_plugin_offline_update_cancel";
+               state->state_success = AS_APP_STATE_UNKNOWN;
+               state->state_failure = AS_APP_STATE_UNKNOWN;
+               break;
        default:
                g_assert_not_reached ();
                break;
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index f5b7efb..8dff2b3 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -60,6 +60,7 @@ typedef enum {
        GS_PLUGIN_LOADER_ACTION_UPGRADE_DOWNLOAD,
        GS_PLUGIN_LOADER_ACTION_UPGRADE_TRIGGER,
        GS_PLUGIN_LOADER_ACTION_LAUNCH,
+       GS_PLUGIN_LOADER_ACTION_OFFLINE_UPDATE_CANCEL,
        GS_PLUGIN_LOADER_ACTION_LAST
 } GsPluginLoaderAction;
 
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 3cfdf7b..e346371 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -251,6 +251,10 @@ gboolean    gs_plugin_launch                       (GsPlugin       *plugin,
                                                         GsApp          *app,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
+gboolean        gs_plugin_offline_update_cancel        (GsPlugin       *plugin,
+                                                        GsApp          *app,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 gboolean        gs_plugin_app_install                  (GsPlugin       *plugin,
                                                         GsApp          *app,
                                                         GCancellable   *cancellable,
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 478a714..7327a5e 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -814,6 +814,51 @@ gs_shell_updates_pending_apps_changed_cb (GsPluginLoader *plugin_loader,
 }
 
 /**
+ * cancel_trigger_failed_cb:
+ **/
+static void
+cancel_trigger_failed_cb (GObject *source, GAsyncResult *res, gpointer user_data)
+{
+       GsShellUpdates *self = GS_SHELL_UPDATES (user_data);
+       g_autoptr(GError) error = NULL;
+       if (!gs_plugin_loader_app_action_finish (self->plugin_loader, res, &error)) {
+               g_warning ("failed to cancel trigger: %s", error->message);
+               return;
+       }
+}
+
+/**
+ * gs_shell_updates_reboot_failed_cb:
+ **/
+static void
+gs_shell_updates_reboot_failed_cb (GObject *source, GAsyncResult *res, gpointer user_data)
+{
+       GsShellUpdates *self = GS_SHELL_UPDATES (user_data);
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GList) apps = NULL;
+       g_autoptr(GVariant) retval = NULL;
+
+       /* get result */
+       retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
+       if (retval != NULL)
+               return;
+
+       if (error != NULL) {
+               g_warning ("Calling org.gnome.SessionManager.Reboot failed: %s",
+                          error->message);
+       }
+
+       /* cancel trigger */
+       apps = gs_update_list_get_apps (GS_UPDATE_LIST (self->list_box_updates));
+       gs_plugin_loader_app_action_async (self->plugin_loader,
+                                          GS_APP (apps->data),
+                                          GS_PLUGIN_LOADER_ACTION_OFFLINE_UPDATE_CANCEL,
+                                          self->cancellable,
+                                          cancel_trigger_failed_cb,
+                                          self);
+}
+
+/**
  * gs_shell_updates_offline_update_cb:
  **/
 static void
@@ -821,6 +866,7 @@ gs_shell_updates_offline_update_cb (GsPluginLoader *plugin_loader,
                                     GAsyncResult *res,
                                     GsShellUpdates *self)
 {
+       g_autoptr(GDBusConnection) bus = NULL;
        g_autoptr(GError) error = NULL;
 
        /* get the results */
@@ -828,7 +874,18 @@ gs_shell_updates_offline_update_cb (GsPluginLoader *plugin_loader,
                g_warning ("Failed to trigger offline update: %s", error->message);
                return;
        }
-       gs_reboot (NULL);
+
+       /* trigger reboot */
+       bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+       g_dbus_connection_call (bus,
+                               "org.gnome.SessionManager",
+                               "/org/gnome/SessionManager",
+                               "org.gnome.SessionManager",
+                               "Reboot",
+                               NULL, NULL, G_DBUS_CALL_FLAGS_NONE,
+                               G_MAXINT, NULL,
+                               gs_shell_updates_reboot_failed_cb,
+                               self);
 }
 
 static void
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 648c1f6..81721f1 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -395,48 +395,6 @@ gs_mkdir_parent (const gchar *path, GError **error)
        return TRUE;
 }
 
-static void
-reboot_done (GObject *source, GAsyncResult *res, gpointer data)
-{
-       GCallback reboot_failed = data;
-       g_autoptr(GVariant) ret = NULL;
-       g_autoptr(GError) error = NULL;
-
-       ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
-       if (ret)
-               return;
-
-       if (error != NULL) {
-               g_warning ("Calling org.gnome.SessionManager.Reboot failed: %s",
-                          error->message);
-       }
-
-       if (reboot_failed != NULL)
-               reboot_failed ();
-}
-
-void
-gs_reboot (GCallback reboot_failed)
-{
-       g_autoptr(GDBusConnection) bus = NULL;
-
-       g_debug ("calling org.gnome.SessionManager.Reboot");
-
-       bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
-       g_dbus_connection_call (bus,
-                               "org.gnome.SessionManager",
-                               "/org/gnome/SessionManager",
-                               "org.gnome.SessionManager",
-                               "Reboot",
-                               NULL,
-                               NULL,
-                               G_DBUS_CALL_FLAGS_NONE,
-                               G_MAXINT,
-                               NULL,
-                               reboot_done,
-                               reboot_failed);
-}
-
 /**
  * gs_image_set_from_pixbuf_with_scale:
  **/
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 8c1acd0..7fd038b 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -52,7 +52,6 @@ guint  gs_string_replace              (GString        *string,
                                         const gchar    *replace);
 gboolean gs_mkdir_parent               (const gchar    *path,
                                         GError         **error);
-void     gs_reboot                      (GCallback       reboot_failed);
 
 void   gs_image_set_from_pixbuf_with_scale     (GtkImage               *image,
                                                 const GdkPixbuf        *pixbuf,
diff --git a/src/plugins/gs-plugin-systemd-updates.c b/src/plugins/gs-plugin-systemd-updates.c
index 4444963..47bb154 100644
--- a/src/plugins/gs-plugin-systemd-updates.c
+++ b/src/plugins/gs-plugin-systemd-updates.c
@@ -160,3 +160,15 @@ gs_plugin_offline_update (GsPlugin *plugin,
 {
        return pk_offline_trigger (PK_OFFLINE_ACTION_REBOOT, cancellable, error);
 }
+
+/**
+ * gs_plugin_offline_update_cancel:
+ */
+gboolean
+gs_plugin_offline_update_cancel (GsPlugin *plugin,
+                                GsApp *app,
+                                GCancellable *cancellable,
+                                GError **error)
+{
+       return pk_offline_cancel (NULL, error);
+}


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