[gnome-music/wip/carlosg/tracker3: 30/68] coregrilo: Load plugins once coregrilo is built



commit 3ba74ffb1b494a26a5f0bce198ba7149a9c02a24
Author: Jean Felder <jfelder src gnome org>
Date:   Sun May 17 21:24:20 2020 +0200

    coregrilo: Load plugins once coregrilo is built
    
    Some sources need access to the registry in order to retrieve custom
    keys (for example, the chromaprint source introduced in a later
    commit). Such sources wrappers retrieve the CoreGrilo object (and thus
    the Grilo registry) by accessing the coregrilo property of the
    Application.
    
    However, because of the asynchronous nature of the
    `grl_registry_load_all_plugins` function, a wrapper may be created
    before the CoreGrilo is initialized. In that case, it will be
    impossible to access the Grilo registry.
    
    This issue is fixed by loading all the plugins once the CorGrilo is
    initialized. This function can only be called once to prevent any
    misuse.

 gnomemusic/application.py |  1 +
 gnomemusic/coregrilo.py   | 11 +++++++++++
 2 files changed, 12 insertions(+)
---
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index ba8f4d45..0b32cac6 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -68,6 +68,7 @@ class Application(Gtk.Application):
         # Order is important: CoreGrilo initializes the Grilo sources,
         # which in turn use CoreModel & CoreSelection extensively.
         self._coregrilo = CoreGrilo(self)
+        self._coregrilo.load_plugins()
 
         self._settings = Gio.Settings.new('org.gnome.Music')
         self._lastfm_scrobbler = LastFmScrobbler(self)
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index a7a4936e..63ddbf5c 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -89,6 +89,17 @@ class CoreGrilo(GObject.GObject):
         self._registry.connect('source-added', self._on_source_added)
         self._registry.connect('source-removed', self._on_source_removed)
 
+        self._plugins_loaded = False
+
+    def load_plugins(self):
+        """Load all the plugins.
+
+        This function can only be called once.
+        """
+        if self._plugins_loaded:
+            self._log.warning("Grilo plugins have already been loaded")
+
+        self._plugins_loaded = True
         self._registry.load_all_plugins(True)
 
         weakref.finalize(self, Grl.deinit)


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