[gnome-software: 5/29] flatpak: Split shutdown code out into new plugin shutdown vfunc




commit 502f255e398750c7a5e5f546e5a71c835fe7b15c
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Oct 14 15:33:48 2021 +0100

    flatpak: Split shutdown code out into new plugin shutdown vfunc
    
    This code is only really used from the unit tests, but it does belong in
    the new shutdown vfunc rather than at the start of setup.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 plugins/flatpak/gs-plugin-flatpak.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 65fd054c9..879d4a327 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -143,8 +143,8 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        GsPluginFlatpak *self = GS_PLUGIN_FLATPAK (plugin);
        g_autoptr(GPtrArray) installations = NULL;
 
-       /* clear in case we're called from resetup in the self tests */
-       g_ptr_array_set_size (self->installations, 0);
+       /* Shouldn’t end up setting up twice */
+       g_assert (self->installations == NULL || self->installations->len == 0);
 
        /* if we're not just running the tests */
        if (self->destdir_for_tests == NULL) {
@@ -223,6 +223,31 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        return TRUE;
 }
 
+static void
+gs_plugin_flatpak_shutdown_async (GsPlugin            *plugin,
+                                  GCancellable        *cancellable,
+                                  GAsyncReadyCallback  callback,
+                                  gpointer             user_data)
+{
+       g_autoptr(GTask) task = NULL;
+
+       task = g_task_new (self, cancellable, callback, user_data);
+       g_task_set_source_tag (task, gs_plugin_flatpak_shutdown_async);
+
+       /* Clear the flatpak installations */
+       g_ptr_array_set_size (self->installations, 0);
+
+       g_task_return_boolean (task, TRUE);
+}
+
+static gboolean
+gs_plugin_flatpak_shutdown_finish (GsPlugin      *plugin,
+                                   GAsyncResult  *result,
+                                   GError       **error)
+{
+       return g_task_propagate_boolean (G_TASK (result), error);
+}
+
 gboolean
 gs_plugin_add_installed (GsPlugin *plugin,
                         GsAppList *list,
@@ -1708,8 +1733,12 @@ static void
 gs_plugin_flatpak_class_init (GsPluginFlatpakClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GsPluginClass *plugin_class = GS_PLUGIN_CLASS (klass);
 
        object_class->dispose = gs_plugin_flatpak_dispose;
+
+       plugin_class->shutdown_async = gs_plugin_flatpak_shutdown_async;
+       plugin_class->shutdown_finish = gs_plugin_flatpak_shutdown_finish;
 }
 
 GType


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