[gnome-software: 28/29] gs-plugin-dummy: Move setup out into a setup vfunc




commit 157bfc5012f976a417f8076cff0a7e8900fb4bcb
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Oct 12 08:09:24 2021 +0100

    gs-plugin-dummy: Move setup out into a setup vfunc
    
    Rather than creating dummy apps in the class’ init function. This no
    longer works as `gs_plugin_get_name()` won’t return a non-`NULL` value
    until after init has returned and the plugin object has been fully
    constructed.
    
    Moving the app creation out into `setup()` is in-line with what other
    plugins do.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 plugins/dummy/gs-plugin-dummy.c | 42 +++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)
---
diff --git a/plugins/dummy/gs-plugin-dummy.c b/plugins/dummy/gs-plugin-dummy.c
index 35ef7e017..059f1c4ae 100644
--- a/plugins/dummy/gs-plugin-dummy.c
+++ b/plugins/dummy/gs-plugin-dummy.c
@@ -54,6 +54,31 @@ gs_plugin_dummy_init (GsPluginDummy *self)
                return;
        }
 
+       /* need help from appstream */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "os-release");
+}
+
+static void
+gs_plugin_dummy_dispose (GObject *object)
+{
+       GsPluginDummy *self = GS_PLUGIN_DUMMY (object);
+
+       g_clear_pointer (&self->installed_apps, g_hash_table_unref);
+       g_clear_pointer (&self->available_apps, g_hash_table_unref);
+       g_clear_handle_id (&self->quirk_id, g_source_remove);
+       g_clear_object (&self->cached_origin);
+
+       G_OBJECT_CLASS (gs_plugin_dummy_parent_class)->dispose (object);
+}
+
+gboolean
+gs_plugin_setup (GsPlugin      *plugin,
+                 GCancellable  *cancellable,
+                 GError       **error)
+{
+       GsPluginDummy *self = GS_PLUGIN_DUMMY (plugin);
+
        /* toggle this */
        if (g_getenv ("GS_SELF_TEST_TOGGLE_ALLOW_UPDATES") != NULL) {
                self->allow_updates_id = g_timeout_add_seconds (10,
@@ -86,22 +111,7 @@ gs_plugin_dummy_init (GsPluginDummy *self)
                             g_strdup ("com.hughski.ColorHug2.driver"),
                             GUINT_TO_POINTER (1));
 
-       /* need help from appstream */
-       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
-       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "os-release");
-}
-
-static void
-gs_plugin_dummy_dispose (GObject *object)
-{
-       GsPluginDummy *self = GS_PLUGIN_DUMMY (object);
-
-       g_clear_pointer (&self->installed_apps, g_hash_table_unref);
-       g_clear_pointer (&self->available_apps, g_hash_table_unref);
-       g_clear_handle_id (&self->quirk_id, g_source_remove);
-       g_clear_object (&self->cached_origin);
-
-       G_OBJECT_CLASS (gs_plugin_dummy_parent_class)->dispose (object);
+       return TRUE;
 }
 
 void


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