[gnome-software: 7/20] gs-application: Inline initialize_plugins()




commit 60978b3dae83a516cfaceb54b337e891b8d29525
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Mar 7 15:09:56 2022 +0000

    gs-application: Inline initialize_plugins()
    
    It’s only called in one place, and its code needs rearranging to solve
    issue #1670.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1670

 src/gs-application.c | 103 ++++++++++++++++++++++-----------------------------
 1 file changed, 45 insertions(+), 58 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index dfc342f78..c56b6dec1 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -171,63 +171,6 @@ async_result_cb (GObject      *source_object,
        g_main_context_wakeup (g_main_context_get_thread_default ());
 }
 
-static void
-gs_application_initialize_plugins (GsApplication *app)
-{
-       static gboolean initialized = FALSE;
-       g_auto(GStrv) plugin_blocklist = NULL;
-       g_auto(GStrv) plugin_allowlist = NULL;
-       g_autoptr(GError) error = NULL;
-       const gchar *tmp;
-       g_autoptr(GAsyncResult) setup_result = NULL;
-
-       if (initialized)
-               return;
-
-       initialized = TRUE;
-
-       /* allow for debugging */
-       tmp = g_getenv ("GNOME_SOFTWARE_PLUGINS_BLOCKLIST");
-       if (tmp != NULL)
-               plugin_blocklist = g_strsplit (tmp, ",", -1);
-       tmp = g_getenv ("GNOME_SOFTWARE_PLUGINS_ALLOWLIST");
-       if (tmp != NULL)
-               plugin_allowlist = g_strsplit (tmp, ",", -1);
-
-       app->plugin_loader = gs_plugin_loader_new ();
-       if (g_file_test (LOCALPLUGINDIR, G_FILE_TEST_EXISTS))
-               gs_plugin_loader_add_location (app->plugin_loader, LOCALPLUGINDIR);
-
-       /* Set up the plugins. Manually iterate the thread-default #GMainContext
-        * at this point to save refactoring all this code to be async (FIXME:
-        * we should do that in future).
-        *
-        * We can’t use gs_plugin_loader_setup() from gs-plugin-loader-sync.c
-        * here because that uses a custom #GMainContext, which means that a lot
-        * of objects in plugins are initialised with the wrong #GMainContext
-        * for subsequent callbacks. */
-       gs_plugin_loader_setup_async (app->plugin_loader,
-                                     (const gchar * const *) plugin_allowlist,
-                                     (const gchar * const *) plugin_blocklist,
-                                     NULL,
-                                     async_result_cb,
-                                     &setup_result);
-
-       while (setup_result == NULL)
-               g_main_context_iteration (g_main_context_get_thread_default (), TRUE);
-
-       if (!gs_plugin_loader_setup_finish (app->plugin_loader,
-                                           setup_result,
-                                           &error)) {
-               g_warning ("Failed to setup plugins: %s", error->message);
-               exit (1);
-       }
-
-       /* show the priority of each plugin */
-       gs_plugin_loader_dump_state (app->plugin_loader);
-
-}
-
 static gboolean
 gs_application_dbus_register (GApplication    *application,
                               GDBusConnection *connection,
@@ -996,6 +939,12 @@ gs_application_startup (GApplication *application)
 {
        GSettings *settings;
        GsApplication *app = GS_APPLICATION (application);
+       g_auto(GStrv) plugin_blocklist = NULL;
+       g_auto(GStrv) plugin_allowlist = NULL;
+       g_autoptr(GError) error = NULL;
+       const gchar *tmp;
+       g_autoptr(GAsyncResult) setup_result = NULL;
+
        G_APPLICATION_CLASS (gs_application_parent_class)->startup (application);
 
        gs_application_add_wrapper_actions (application);
@@ -1004,7 +953,45 @@ gs_application_startup (GApplication *application)
                                         actions, G_N_ELEMENTS (actions),
                                         application);
 
-       gs_application_initialize_plugins (app);
+       /* allow for debugging */
+       tmp = g_getenv ("GNOME_SOFTWARE_PLUGINS_BLOCKLIST");
+       if (tmp != NULL)
+               plugin_blocklist = g_strsplit (tmp, ",", -1);
+       tmp = g_getenv ("GNOME_SOFTWARE_PLUGINS_ALLOWLIST");
+       if (tmp != NULL)
+               plugin_allowlist = g_strsplit (tmp, ",", -1);
+
+       app->plugin_loader = gs_plugin_loader_new ();
+       if (g_file_test (LOCALPLUGINDIR, G_FILE_TEST_EXISTS))
+               gs_plugin_loader_add_location (app->plugin_loader, LOCALPLUGINDIR);
+
+       /* Set up the plugins. Manually iterate the thread-default #GMainContext
+        * at this point to save refactoring all this code to be async (FIXME:
+        * we should do that in future).
+        *
+        * We can’t use gs_plugin_loader_setup() from gs-plugin-loader-sync.c
+        * here because that uses a custom #GMainContext, which means that a lot
+        * of objects in plugins are initialised with the wrong #GMainContext
+        * for subsequent callbacks. */
+       gs_plugin_loader_setup_async (app->plugin_loader,
+                                     (const gchar * const *) plugin_allowlist,
+                                     (const gchar * const *) plugin_blocklist,
+                                     NULL,
+                                     async_result_cb,
+                                     &setup_result);
+
+       while (setup_result == NULL)
+               g_main_context_iteration (g_main_context_get_thread_default (), TRUE);
+
+       if (!gs_plugin_loader_setup_finish (app->plugin_loader,
+                                           setup_result,
+                                           &error)) {
+               g_warning ("Failed to setup plugins: %s", error->message);
+               exit (1);
+       }
+
+       /* show the priority of each plugin */
+       gs_plugin_loader_dump_state (app->plugin_loader);
 
        gs_shell_search_provider_setup (app->search_provider, app->plugin_loader);
 


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