[gnome-builder/wip/gtk4-port] libide/gui: load typelibs earlier in application startup



commit 7664a49080870b5c082c44b023ec192cef493c2b
Author: Christian Hergert <chergert redhat com>
Date:   Sun May 8 13:37:46 2022 -0700

    libide/gui: load typelibs earlier in application startup
    
    This is necessary so that we have access to load the proper Ide before
    the specific version is required by keybindings.gsl.

 src/libide/gui/ide-application-plugins.c | 24 +------------------
 src/libide/gui/ide-application-private.h |  3 +++
 src/libide/gui/ide-application.c         | 41 ++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 23 deletions(-)
---
diff --git a/src/libide/gui/ide-application-plugins.c b/src/libide/gui/ide-application-plugins.c
index e7c37c497..a1ee6b30b 100644
--- a/src/libide/gui/ide-application-plugins.c
+++ b/src/libide/gui/ide-application-plugins.c
@@ -360,7 +360,6 @@ void
 _ide_application_load_plugins (IdeApplication *self)
 {
   g_autofree gchar *user_plugins_dir = NULL;
-  g_autoptr(GError) error = NULL;
   const GList *plugins;
   PeasEngine *engine;
 
@@ -404,28 +403,7 @@ _ide_application_load_plugins (IdeApplication *self)
                                        NULL);
   peas_engine_prepend_search_path (engine, user_plugins_dir, NULL);
 
-  /* Ensure that we have all our required GObject Introspection packages
-   * loaded so that plugins don't need to require_version() as that is
-   * tedious and annoying to keep up to date.
-   *
-   * If we can't load any of our dependent packages, then fail to load
-   * python3 plugins altogether to avoid loading anything improper into
-   * the process space.
-   */
-  g_irepository_prepend_search_path (PACKAGE_LIBDIR"/gnome-builder/girepository-1.0");
-  if (!g_irepository_require (NULL, "GtkSource", "5", 0, &error) ||
-      !g_irepository_require (NULL, "Gio", "2.0", 0, &error) ||
-      !g_irepository_require (NULL, "GLib", "2.0", 0, &error) ||
-      !g_irepository_require (NULL, "Gtk", "4.0", 0, &error) ||
-      !g_irepository_require (NULL, "Jsonrpc", "1.0", 0, &error) ||
-      !g_irepository_require (NULL, "Template", "1.0", 0, &error) ||
-      !g_irepository_require (NULL, "Vte", "3.91", 0, &error) ||
-#ifdef HAVE_WEBKIT
-      !g_irepository_require (NULL, "WebKit2", "5.0", 0, &error) ||
-#endif
-      !g_irepository_require (NULL, "Ide", PACKAGE_ABI_S, 0, &error))
-    g_critical ("Cannot enable Python 3 plugins: %s", error->message);
-  else
+  if (self->loaded_typelibs)
     peas_engine_enable_loader (engine, "python3");
 
   peas_engine_rescan_plugins (engine);
diff --git a/src/libide/gui/ide-application-private.h b/src/libide/gui/ide-application-private.h
index 62e3884c6..51c0e5908 100644
--- a/src/libide/gui/ide-application-private.h
+++ b/src/libide/gui/ide-application-private.h
@@ -97,6 +97,9 @@ struct _IdeApplication
   /* If we've detected we lost network access */
   GNetworkMonitor *network_monitor;
   guint has_network : 1;
+
+  /* If all our typelibs were loaded successfully */
+  guint loaded_typelibs : 1;
 };
 
 IdeApplication *_ide_application_new                      (gboolean                 standalone);
diff --git a/src/libide/gui/ide-application.c b/src/libide/gui/ide-application.c
index b24c53cba..9feb93894 100644
--- a/src/libide/gui/ide-application.c
+++ b/src/libide/gui/ide-application.c
@@ -113,6 +113,44 @@ ide_application_local_command_line (GApplication   *app,
   return G_APPLICATION_CLASS (ide_application_parent_class)->local_command_line (app, arguments, 
exit_status);
 }
 
+static void
+ide_application_load_typelibs (IdeApplication *self)
+{
+  g_autoptr(GError) error = NULL;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_APPLICATION (self));
+
+  g_irepository_prepend_search_path (PACKAGE_LIBDIR"/gnome-builder/girepository-1.0");
+
+  /* Ensure that we have all our required GObject Introspection packages
+   * loaded so that plugins don't need to require_version() as that is
+   * tedious and annoying to keep up to date.
+   *
+   * If we can't load any of our dependent packages, then fail to load
+   * python3 plugins altogether to avoid loading anything improper into
+   * the process space.
+   */
+  if (!g_irepository_require (NULL, "GtkSource", "5", 0, &error) ||
+      !g_irepository_require (NULL, "Gio", "2.0", 0, &error) ||
+      !g_irepository_require (NULL, "GLib", "2.0", 0, &error) ||
+      !g_irepository_require (NULL, "Gtk", "4.0", 0, &error) ||
+      !g_irepository_require (NULL, "Jsonrpc", "1.0", 0, &error) ||
+      !g_irepository_require (NULL, "Template", "1.0", 0, &error) ||
+      !g_irepository_require (NULL, "Vte", "3.91", 0, &error) ||
+#ifdef HAVE_WEBKIT
+      !g_irepository_require (NULL, "WebKit2", "5.0", 0, &error) ||
+#endif
+      !g_irepository_require (NULL, "Ide", PACKAGE_ABI_S, 0, &error))
+    g_critical ("Cannot enable Python 3 plugins: %s", error->message);
+  else
+    self->loaded_typelibs = TRUE;
+
+  IDE_EXIT;
+}
+
 static void
 ide_application_startup (GApplication *app)
 {
@@ -479,6 +517,9 @@ ide_application_init (IdeApplication *self)
   g_application_set_default (G_APPLICATION (self));
   gtk_window_set_default_icon_name (ide_get_application_id ());
 
+  /* Make sure we've loaded typelibs into process for early access */
+  ide_application_load_typelibs (self);
+
   /* Ensure our core data is loaded early. */
   _ide_application_add_resources (self, "resource:///org/gnome/libide-sourceview/");
   _ide_application_add_resources (self, "resource:///org/gnome/libide-gui/");


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