[gnome-music/wip/jfelder/3-38-empty-view-launch: 2/2] window: Wait before checking songs availability on launch




commit a19c71613a457fbb7a76745409b8da76b4eb5a3e
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Nov 13 21:33:25 2020 +0100

    window: Wait before checking songs availability on launch
    
    A 'songs-available' checks happens on launch to check that the music
    library is not empty. If no music is available, an empty view is
    displayed. This relies on Tracker being already loaded. However, if
    Tracker is not yet available, the EmptyView is shown for a very short
    time and then the AlbumsView is displayed once Tracker becomes
    available.
    
    This issue is fixed by adding a timeout to ensure that Tracker is
    loaded before checking songs availability.
    
    Related: #423

 gnomemusic/window.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 60b9f59eb..3f9b101e8 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -93,6 +93,7 @@ class Window(Gtk.ApplicationWindow):
         self._player = app.props.player
         self._search = app.props.search
 
+        self._startup_timeout_id = 0
         self._setup_view()
 
         MediaKeys(self._player, self)
@@ -174,10 +175,8 @@ class Window(Gtk.ApplicationWindow):
         self._app.props.coregrilo.connect(
             "notify::tracker-available", self._on_tracker_available)
 
-        if self._app.props.coremodel.props.songs_available:
-            self._switch_to_player_view()
-        else:
-            self._switch_to_empty_view()
+        self._startup_timeout_id = GLib.timeout_add(
+            2000, self._on_songs_available, None, None)
 
     def _switch_to_empty_view(self):
         did_initial_state = self._settings.get_boolean('did-initial-state')
@@ -204,6 +203,10 @@ class Window(Gtk.ApplicationWindow):
             self._headerbar_stack.props.visible_child_name = "main"
 
     def _on_songs_available(self, klass, value):
+        if self._startup_timeout_id > 0:
+            GLib.source_remove(self._startup_timeout_id)
+            self._startup_timeout_id = 0
+
         if self._app.props.coremodel.props.songs_available:
             self._switch_to_player_view()
         else:


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