[gnome-builder/gnome-builder-3-32] foundry: unload foundry during project unload



commit d1b3639a660d61c2ad7a4017bded4f3500070ad7
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 28 11:54:42 2019 -0700

    foundry: unload foundry during project unload
    
    This ensures we save the config-manager during the shutdown proceedure.

 src/libide/foundry/ide-foundry-init.c | 59 +++++++++++++++++++++++++++++++++++
 src/libide/foundry/ide-foundry-init.h | 18 +++++++----
 src/libide/gui/ide-workbench.c        | 36 ++++++++++++++++-----
 3 files changed, 100 insertions(+), 13 deletions(-)
---
diff --git a/src/libide/foundry/ide-foundry-init.c b/src/libide/foundry/ide-foundry-init.c
index 516bcba1b..cb23e0f30 100644
--- a/src/libide/foundry/ide-foundry-init.c
+++ b/src/libide/foundry/ide-foundry-init.c
@@ -159,3 +159,62 @@ _ide_foundry_init_finish (GAsyncResult  *result,
 
   return ide_task_propagate_boolean (IDE_TASK (result), error);
 }
+
+static void
+ide_foundry_init_unload_config_manager_cb (GObject      *object,
+                                           GAsyncResult *result,
+                                           gpointer      user_data)
+{
+  IdeConfigManager *config_manager = (IdeConfigManager *)object;
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GError) error = NULL;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_CONFIG_MANAGER (config_manager));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_TASK (task));
+
+  if (!ide_config_manager_save_finish (config_manager, result, &error))
+    g_warning ("Failed to save build configs: %s", error->message);
+
+  ide_task_return_boolean (task, TRUE);
+
+  IDE_EXIT;
+}
+
+void
+_ide_foundry_unload_async (IdeContext          *context,
+                           GCancellable        *cancellable,
+                           GAsyncReadyCallback  callback,
+                           gpointer             user_data)
+{
+  g_autoptr(IdeTask) task = NULL;
+  IdeConfigManager *config_manager;
+
+  IDE_ENTRY;
+
+  g_return_if_fail (IDE_IS_CONTEXT (context));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = ide_task_new (context, cancellable, callback, user_data);
+  ide_task_set_source_tag (task, _ide_foundry_unload_async);
+
+  config_manager = ide_config_manager_from_context (context);
+
+  ide_config_manager_save_async (config_manager,
+                                 cancellable,
+                                 ide_foundry_init_unload_config_manager_cb,
+                                 g_steal_pointer (&task));
+
+  IDE_EXIT;
+}
+
+gboolean
+_ide_foundry_unload_finish (GAsyncResult  *result,
+                            GError       **error)
+{
+  g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
+
+  return ide_task_propagate_boolean (IDE_TASK (result), error);
+}
diff --git a/src/libide/foundry/ide-foundry-init.h b/src/libide/foundry/ide-foundry-init.h
index a12915b16..cfcee29ff 100644
--- a/src/libide/foundry/ide-foundry-init.h
+++ b/src/libide/foundry/ide-foundry-init.h
@@ -24,11 +24,17 @@
 
 G_BEGIN_DECLS
 
-void     _ide_foundry_init_async  (IdeContext           *context,
-                                   GCancellable         *cancellable,
-                                   GAsyncReadyCallback   callback,
-                                   gpointer              user_data);
-gboolean _ide_foundry_init_finish (GAsyncResult         *result,
-                                   GError              **error);
+void     _ide_foundry_init_async    (IdeContext           *context,
+                                     GCancellable         *cancellable,
+                                     GAsyncReadyCallback   callback,
+                                     gpointer              user_data);
+gboolean _ide_foundry_init_finish   (GAsyncResult         *result,
+                                     GError              **error);
+void     _ide_foundry_unload_async  (IdeContext           *context,
+                                     GCancellable         *cancellable,
+                                     GAsyncReadyCallback   callback,
+                                     gpointer              user_data);
+gboolean _ide_foundry_unload_finish (GAsyncResult         *result,
+                                     GError              **error);
 
 G_END_DECLS
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 35aa809f2..8b651dce0 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -1455,22 +1455,45 @@ ide_workbench_get_project_info (IdeWorkbench *self)
 }
 
 static void
-ide_workbench_unload_project_completed (IdeWorkbench *self,
-                                        IdeTask      *task)
+ide_workbench_unload_foundry_cb (GObject      *object,
+                                 GAsyncResult *result,
+                                 gpointer      user_data)
 {
-  g_assert (IDE_IS_WORKBENCH (self));
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GError) error = NULL;
+  IdeWorkbench *self;
+
+  g_assert (G_IS_ASYNC_RESULT (result));
   g_assert (IDE_IS_TASK (task));
 
-  g_clear_object (&self->addins);
-  ide_workbench_foreach_workspace (self, (GtkCallback)gtk_widget_destroy, NULL);
+  self = ide_task_get_source_object (task);
+
+  if (!_ide_foundry_unload_finish (result, &error))
+    ide_task_return_error (task, g_steal_pointer (&error));
+  else
+    ide_task_return_boolean (task, TRUE);
 
   if (self->context != NULL)
     {
       ide_object_destroy (IDE_OBJECT (self->context));
       g_clear_object (&self->context);
     }
+}
 
-  ide_task_return_boolean (task, TRUE);
+static void
+ide_workbench_unload_project_completed (IdeWorkbench *self,
+                                        IdeTask      *task)
+{
+  g_assert (IDE_IS_WORKBENCH (self));
+  g_assert (IDE_IS_TASK (task));
+
+  g_clear_object (&self->addins);
+  ide_workbench_foreach_workspace (self, (GtkCallback)gtk_widget_destroy, NULL);
+
+  _ide_foundry_unload_async (self->context,
+                             ide_task_get_cancellable (task),
+                             ide_workbench_unload_foundry_cb,
+                             g_object_ref (task));
 }
 
 static void
@@ -1628,7 +1651,6 @@ ide_workbench_unload_async (IdeWorkbench        *self,
                           cancellable,
                           ide_workbench_session_save_cb,
                           g_steal_pointer (&task));
-
 }
 
 /**


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