[gnome-music/wip/mschraal/coregrilo-cleanup-plugin-loading] coregrilo: Clean up plugin activation for Tracker




commit a55350568892615106033d280b39686077aa6573
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Jul 29 14:36:07 2020 +0200

    coregrilo: Clean up plugin activation for Tracker
    
    The Tracker plugin loading has proven to be problematic over time, due
    to how the plugin behaves and it interacts with Grilo and Music code,
    see d7425fabf6 and 11f796999c for reference. This has resulted in
    a difficult to comprehend loading procedure which needs background
    knowledge to make sense.
    
    Rework CoreGrilo plugin loading and activation to be different steps and
    only activate the Tracker plugin when TrackerWrapper becomes available.

 gnomemusic/coregrilo.py | 44 ++++++++++++++++++++++----------------------
 meson.build             |  2 +-
 2 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index dcdfa8f8..ed9a1869 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -74,9 +74,6 @@ class CoreGrilo(GObject.GObject):
             "tracker-available", self, "tracker-available",
             GObject.BindingFlags.SYNC_CREATE)
 
-        self._tracker_wrapper.connect(
-            "notify::tracker-available", self._on_tracker_available_changed)
-
         GLib.setenv("GRL_PLUGIN_RANKS", self._grl_plugin_ranks, True)
 
         Grl.init(None)
@@ -89,17 +86,29 @@ class CoreGrilo(GObject.GObject):
         self._registry.connect('source-added', self._on_source_added)
         self._registry.connect('source-removed', self._on_source_removed)
 
-        self._registry.load_all_plugins(True)
+        self._registry.load_all_plugins(False)
+
+        self._tracker_wrapper.connect(
+            "notify::tracker-available", self._on_tracker_available_changed)
+
+        for plugin in self._registry.get_plugins(False):
+            plugin_id = plugin.get_id()
+            # Activate the Tracker plugin only when TrackerWrapper
+            # is available by listening to the tracker-available
+            # property, so skip it here.
+            if plugin_id != "grl-tracker":
+                try:
+                    self._registry.activate_plugin_by_id(plugin_id)
+                except GLib.GError:
+                    self._log.debug(
+                        "Failed to activate {} plugin.".format(plugin_id))
 
         weakref.finalize(self, Grl.deinit)
 
     def _on_tracker_available_changed(self, klass, value):
-        new_state = self._tracker_wrapper.props.tracker_available
         # FIXME:No removal support yet.
+        new_state = self._tracker_wrapper.props.tracker_available
         if new_state == TrackerState.AVAILABLE:
-            tracker_plugin = self._registry.lookup_plugin("grl-tracker")
-            if tracker_plugin:
-                self._registry.unload_plugin("grl-tracker")
             self._registry.activate_plugin_by_id("grl-tracker")
 
     def _on_source_added(self, registry, source):
@@ -128,21 +137,12 @@ class CoreGrilo(GObject.GObject):
                 self._thumbnail_sources_timeout = GLib.timeout_add_seconds(
                     5, _trigger_art_update)
 
-        new_wrapper = None
-
-        new_state = self._tracker_wrapper.props.tracker_available
         if (source.props.source_id == "grl-tracker-source"
-                and self._tracker_wrapper.location_filter() is not None
-                and new_state == TrackerState.AVAILABLE):
-            if source.props.source_id not in self._wrappers.keys():
-                new_wrapper = GrlTrackerWrapper(
-                    source, self._application, self._tracker_wrapper)
-                self._wrappers[source.props.source_id] = new_wrapper
-                self._log.debug("Adding wrapper {}".format(new_wrapper))
-            else:
-                grl_tracker_wrapper = self._wrappers[source.props.source_id]
-                registry.unregister_source(grl_tracker_wrapper.props.source)
-                grl_tracker_wrapper.props.source = source
+                and self._tracker_wrapper.location_filter() is not None):
+            new_wrapper = GrlTrackerWrapper(
+                source, self._application, self._tracker_wrapper)
+            self._wrappers[source.props.source_id] = new_wrapper
+            self._log.debug("Adding wrapper {}".format(new_wrapper))
         elif (source.props.source_id not in self._search_wrappers.keys()
                 and source.props.source_id not in self._wrappers.keys()
                 and source.props.source_id != "grl-tracker-source"
diff --git a/meson.build b/meson.build
index 0ef5b9b9..7a86b1b1 100644
--- a/meson.build
+++ b/meson.build
@@ -46,7 +46,7 @@ dependency('tracker-sparql-2.0', version: '>= 2.3.0')
 dependency('pango', version: '>= 1.44.0')
 dependency('pygobject-3.0', version: '>= 3.36.1')
 dependency('py3cairo', version: '>= 1.14.0')
-dependency('grilo-0.3', version: '>= 0.3.12', fallback: ['grilo', 'libgrl_dep'])
+dependency('grilo-0.3', version: '>= 0.3.13', fallback: ['grilo', 'libgrl_dep'])
 dependency('grilo-plugins-0.3', version: '>= 0.3.10', fallback: ['grilo-plugins', 'grilo_plugins_dep'])
 
 subproject('libgd',


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