[gnome-builder] flatpak: Make preference addin reload async



commit 2450f235ff64c4ca6de3d0f202a852ed8be234b5
Author: Matthew Leeds <mleeds redhat com>
Date:   Tue Mar 14 00:20:29 2017 -0500

    flatpak: Make preference addin reload async
    
    The call to flatpak_installation_list_remote_refs_sync in add_runtimes
    causes Builder's interface to freeze, so run it in a separate thread
    from the main one.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779895

 plugins/flatpak/gbp-flatpak-preferences-addin.c |   29 +++++++++++++++++++++-
 1 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-preferences-addin.c b/plugins/flatpak/gbp-flatpak-preferences-addin.c
index 4bf1383..91f318a 100644
--- a/plugins/flatpak/gbp-flatpak-preferences-addin.c
+++ b/plugins/flatpak/gbp-flatpak-preferences-addin.c
@@ -241,9 +241,13 @@ add_runtimes (GbpFlatpakPreferencesAddin *self,
 }
 
 static void
-gbp_flatpak_preferences_addin_reload (GbpFlatpakPreferencesAddin *self,
-                                      IdePreferences             *preferences)
+gbp_flatpak_preferences_addin_reload_worker (GTask        *task,
+                                             gpointer      source_object,
+                                             gpointer      task_data,
+                                             GCancellable *cancellable)
 {
+  GbpFlatpakPreferencesAddin *self = (GbpFlatpakPreferencesAddin *)source_object;
+  IdePreferences *preferences = (IdePreferences *)task_data;
   g_autoptr(FlatpakInstallation) system = NULL;
   g_autoptr(FlatpakInstallation) user = NULL;
   g_autoptr(GFile) file = NULL;
@@ -252,6 +256,7 @@ gbp_flatpak_preferences_addin_reload (GbpFlatpakPreferencesAddin *self,
 
   IDE_ENTRY;
 
+  g_assert (G_IS_TASK (task));
   g_assert (GBP_IS_FLATPAK_PREFERENCES_ADDIN (self));
   g_assert (IDE_IS_PREFERENCES (preferences));
 
@@ -274,6 +279,26 @@ gbp_flatpak_preferences_addin_reload (GbpFlatpakPreferencesAddin *self,
   if (system != NULL)
     add_runtimes (self, preferences, system);
 
+  g_task_return_boolean (task, TRUE);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_flatpak_preferences_addin_reload (GbpFlatpakPreferencesAddin *self,
+                                      IdePreferences             *preferences)
+{
+  g_autoptr(GTask) task = NULL;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_FLATPAK_PREFERENCES_ADDIN (self));
+  g_assert (IDE_IS_PREFERENCES (preferences));
+
+  task = g_task_new (self, NULL, NULL, NULL);
+  g_task_set_task_data (task, g_object_ref (preferences), g_object_unref);
+  g_task_run_in_thread (task, gbp_flatpak_preferences_addin_reload_worker);
+
   IDE_EXIT;
 }
 


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