[gnome-software/135-restart-and-install-update-button-does-not-trigger-reboot-when-using-lxde] gs-common: Use GTask internally in gs_utils_invoke_reboot_async()



commit 7fca4185e9007907a8acfdd6d07f26443b76c4f9
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jun 21 09:13:19 2022 +0200

    gs-common: Use GTask internally in gs_utils_invoke_reboot_async()
    
    It will allow to do multiple attempts, depending on the current desktop
    environment or similar circumstances.

 src/gs-common.c | 41 +++++++++++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/src/gs-common.c b/src/gs-common.c
index e0c6380b3..1b95bf60d 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -910,6 +910,22 @@ gs_utils_reboot_call_done_cb (GObject *source,
        }
 }
 
+static void
+gs_utils_invoke_reboot_ready_cb (GObject *source_object,
+                                GAsyncResult *result,
+                                gpointer user_data)
+{
+       g_autoptr(GTask) task = user_data;
+       g_autoptr(GVariant) ret_val = NULL;
+       g_autoptr(GError) error = NULL;
+
+       ret_val = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), result, &error);
+       if (ret_val != NULL)
+               g_task_return_boolean (task, TRUE);
+       else
+               g_task_return_error (task, g_steal_pointer (&error));
+}
+
 /**
  * gs_utils_invoke_reboot_async:
  * @cancellable: (nullable): a %GCancellable for the call, or %NULL
@@ -930,11 +946,22 @@ gs_utils_invoke_reboot_async (GCancellable *cancellable,
                              gpointer user_data)
 {
        g_autoptr(GDBusConnection) bus = NULL;
-       bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+       g_autoptr(GTask) task = NULL;
+       g_autoptr(GError) error = NULL;
 
        if (!ready_callback)
                ready_callback = gs_utils_reboot_call_done_cb;
 
+       task = g_task_new (NULL, cancellable, ready_callback, user_data);
+       g_task_set_source_tag (task, gs_utils_invoke_reboot_async);
+
+       bus = g_bus_get_sync (G_BUS_TYPE_SESSION, cancellable, &error);
+       if (bus == NULL) {
+               g_prefix_error (&error, "%s", "Failed to get D-Bus session bus:");
+               g_task_return_error (task, g_steal_pointer (&error));
+               return;
+       }
+
        g_dbus_connection_call (bus,
                                "org.gnome.SessionManager",
                                "/org/gnome/SessionManager",
@@ -942,8 +969,8 @@ gs_utils_invoke_reboot_async (GCancellable *cancellable,
                                "Reboot",
                                NULL, NULL, G_DBUS_CALL_FLAGS_NONE,
                                G_MAXINT, cancellable,
-                               ready_callback,
-                               user_data);
+                               gs_utils_invoke_reboot_ready_cb,
+                               g_steal_pointer (&task));
 }
 
 /**
@@ -963,9 +990,11 @@ gs_utils_invoke_reboot_finish (GObject *source_object,
                               GAsyncResult *result,
                               GError **error)
 {
-       g_autoptr(GVariant) res = NULL;
-       res = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), result, error);
-       return res != NULL;
+       g_return_val_if_fail (G_IS_TASK (result), FALSE);
+       g_return_val_if_fail (g_task_is_valid (result, source_object), FALSE);
+       g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gs_utils_invoke_reboot_async, FALSE);
+
+       return g_task_propagate_boolean (G_TASK (result), error);
 }
 
 /**


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