[gnome-software: 4/14] flatpak: Make get_installed asynchronous




commit ae2d8840efa951b8e2b62f6e87a3742d44547cf3
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Dec 9 15:49:30 2021 +0000

    flatpak: Make get_installed asynchronous
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 plugins/flatpak/gs-plugin-flatpak.c | 57 +++++++++++++++++++++++++++++++------
 1 file changed, 49 insertions(+), 8 deletions(-)
---
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 6fad2a730..55789870f 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -335,20 +335,59 @@ gs_plugin_flatpak_shutdown_finish (GsPlugin      *plugin,
        return g_task_propagate_boolean (G_TASK (result), error);
 }
 
-gboolean
-gs_plugin_add_installed (GsPlugin *plugin,
-                        GsAppList *list,
-                        GCancellable *cancellable,
-                        GError **error)
+static void list_installed_apps_thread_cb (GTask        *task,
+                                           gpointer      source_object,
+                                           gpointer      task_data,
+                                           GCancellable *cancellable);
+
+static void
+gs_plugin_flatpak_list_installed_apps_async (GsPlugin            *plugin,
+                                             GCancellable        *cancellable,
+                                             GAsyncReadyCallback  callback,
+                                             gpointer             user_data)
 {
        GsPluginFlatpak *self = GS_PLUGIN_FLATPAK (plugin);
+       g_autoptr(GTask) task = NULL;
+
+       task = g_task_new (plugin, cancellable, callback, user_data);
+       g_task_set_source_tag (task, gs_plugin_flatpak_list_installed_apps_async);
+
+       /* Queue a job to get the installed apps. */
+       gs_worker_thread_queue (self->worker, G_PRIORITY_DEFAULT,
+                               list_installed_apps_thread_cb, g_steal_pointer (&task));
+}
+
+/* Run in @worker. */
+static void
+list_installed_apps_thread_cb (GTask        *task,
+                               gpointer      source_object,
+                               gpointer      task_data,
+                               GCancellable *cancellable)
+{
+       GsPluginFlatpak *self = GS_PLUGIN_FLATPAK (source_object);
+       g_autoptr(GsAppList) list = gs_app_list_new ();
+       g_autoptr(GError) local_error = NULL;
+
+       assert_in_worker (self);
 
        for (guint i = 0; i < self->installations->len; i++) {
                GsFlatpak *flatpak = g_ptr_array_index (self->installations, i);
-               if (!gs_flatpak_add_installed (flatpak, list, cancellable, error))
-                       return FALSE;
+
+               if (!gs_flatpak_add_installed (flatpak, list, cancellable, &local_error)) {
+                       g_task_return_error (task, g_steal_pointer (&local_error));
+                       return;
+               }
        }
-       return TRUE;
+
+       g_task_return_pointer (task, g_steal_pointer (&list), g_object_unref);
+}
+
+static GsAppList *
+gs_plugin_flatpak_list_installed_apps_finish (GsPlugin      *plugin,
+                                              GAsyncResult  *result,
+                                              GError       **error)
+{
+       return g_task_propagate_pointer (G_TASK (result), error);
 }
 
 gboolean
@@ -1886,6 +1925,8 @@ gs_plugin_flatpak_class_init (GsPluginFlatpakClass *klass)
        plugin_class->shutdown_finish = gs_plugin_flatpak_shutdown_finish;
        plugin_class->refine_async = gs_plugin_flatpak_refine_async;
        plugin_class->refine_finish = gs_plugin_flatpak_refine_finish;
+       plugin_class->list_installed_apps_async = gs_plugin_flatpak_list_installed_apps_async;
+       plugin_class->list_installed_apps_finish = gs_plugin_flatpak_list_installed_apps_finish;
 }
 
 GType


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