[gnome-music/wip/jfelder/songeditor-gtk4: 61/76] coregrilo: Load plugins once coregrilo is built
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/songeditor-gtk4: 61/76] coregrilo: Load plugins once coregrilo is built
- Date: Wed, 23 Feb 2022 20:36:45 +0000 (UTC)
commit 8af06f30824e68ca0499b7c2f34214b33a804b99
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 | 16 ++++++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index 30ba7606d..439e0e06b 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -73,6 +73,7 @@ class Application(Adw.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 e5c17acab..d18ed6d8a 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -85,6 +85,20 @@ 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
+
+ weakref.finalize(self, Grl.deinit)
+
+ 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")
+ return
+
+ self._plugins_loaded = True
self._registry.load_all_plugins(False)
tracker_available_state = self._tracker_wrapper.props.tracker_available
@@ -107,8 +121,6 @@ class CoreGrilo(GObject.GObject):
self._log.debug(
"Failed to activate {} plugin.".format(plugin_id))
- weakref.finalize(self, Grl.deinit)
-
def _on_tracker_available_changed(self, klass, value):
# FIXME:No removal support yet.
new_state = self._tracker_wrapper.props.tracker_available
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]