[gnome-software: 8/72] hardcoded-blocklist: Make refine asynchronous




commit ae4d31513d3acea471b8c0d8af4eb75b81cb7c87
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Oct 20 14:44:15 2021 +0100

    hardcoded-blocklist: Make refine asynchronous
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 plugins/core/gs-plugin-hardcoded-blocklist.c | 41 ++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 9 deletions(-)
---
diff --git a/plugins/core/gs-plugin-hardcoded-blocklist.c b/plugins/core/gs-plugin-hardcoded-blocklist.c
index 036430395..f9434962f 100644
--- a/plugins/core/gs-plugin-hardcoded-blocklist.c
+++ b/plugins/core/gs-plugin-hardcoded-blocklist.c
@@ -16,6 +16,8 @@
 /*
  * SECTION:
  * Blocklists some applications based on a hardcoded list.
+ *
+ * This plugin executes entirely in the main thread.
  */
 
 struct _GsPluginHardcodedBlocklist
@@ -70,25 +72,46 @@ refine_app (GsPlugin             *plugin,
        return TRUE;
 }
 
-gboolean
-gs_plugin_refine (GsPlugin             *plugin,
-                 GsAppList            *list,
-                 GsPluginRefineFlags   flags,
-                 GCancellable         *cancellable,
-                 GError              **error)
+static void
+gs_plugin_hardcoded_blocklist_refine_async (GsPlugin            *plugin,
+                                            GsAppList           *list,
+                                            GsPluginRefineFlags  flags,
+                                            GCancellable        *cancellable,
+                                            GAsyncReadyCallback  callback,
+                                            gpointer             user_data)
 {
+       g_autoptr(GTask) task = NULL;
+       g_autoptr(GError) local_error = NULL;
+
+       task = g_task_new (plugin, cancellable, callback, user_data);
+       g_task_set_source_tag (task, gs_plugin_hardcoded_blocklist_refine_async);
+
        for (guint i = 0; i < gs_app_list_length (list); i++) {
                GsApp *app = gs_app_list_index (list, i);
-               if (!refine_app (plugin, app, flags, cancellable, error))
-                       return FALSE;
+               if (!refine_app (plugin, app, flags, cancellable, &local_error)) {
+                       g_task_return_error (task, g_steal_pointer (&local_error));
+                       return;
+               }
        }
 
-       return TRUE;
+       g_task_return_boolean (task, TRUE);
+}
+
+static gboolean
+gs_plugin_hardcoded_blocklist_refine_finish (GsPlugin      *plugin,
+                                             GAsyncResult  *result,
+                                             GError       **error)
+{
+       return g_task_propagate_boolean (G_TASK (result), error);
 }
 
 static void
 gs_plugin_hardcoded_blocklist_class_init (GsPluginHardcodedBlocklistClass *klass)
 {
+       GsPluginClass *plugin_class = GS_PLUGIN_CLASS (klass);
+
+       plugin_class->refine_async = gs_plugin_hardcoded_blocklist_refine_async;
+       plugin_class->refine_finish = gs_plugin_hardcoded_blocklist_refine_finish;
 }
 
 GType


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