[gnome-games/wip/exalm/pause-collection] application-window: Pause loading in game



commit 02e8512c951c7b736a0ad94ce676b081e017cc3d
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Feb 14 10:36:00 2019 +0500

    application-window: Pause loading in game
    
    Improve performance by pausing collection loading when starting the game
    And resuming it when exiting to collection.

 src/core/game-collection.vala  | 12 ++++++++++--
 src/ui/application-window.vala |  3 +++
 src/ui/application.vala        | 12 +++++++++---
 3 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/src/core/game-collection.vala b/src/core/game-collection.vala
index ce954868..3dacd275 100644
--- a/src/core/game-collection.vala
+++ b/src/core/game-collection.vala
@@ -10,6 +10,8 @@ private class Games.GameCollection : Object {
        private HashTable<string, Array<UriGameFactory>> factories_for_mime_type;
        private HashTable<string, Array<UriGameFactory>> factories_for_scheme;
 
+       public bool paused { get; set; }
+
        construct {
                games = new GenericSet<Game> (Game.hash, Game.equal);
                factories_for_mime_type = new HashTable<string, Array<UriGameFactory>> (str_hash, str_equal);
@@ -61,10 +63,16 @@ private class Games.GameCollection : Object {
                return games[0];
        }
 
-       public async void search_games () {
+       public async bool search_games () {
                foreach (var source in sources)
-                       foreach (var uri in source)
+                       foreach (var uri in source) {
+                               if (paused)
+                                       return false;
+
                                yield add_uri (uri);
+                       }
+
+               return true;
        }
 
        private async UriGameFactory[] get_factories_for_uri (Uri uri) {
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 0d6b80fa..c606c33c 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -38,6 +38,9 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                                break;
                        }
 
+                       assert (application is Application);
+                       (application as Application).set_pause_loading (ui_state != UiState.COLLECTION);
+
                        konami_code.reset ();
                }
        }
diff --git a/src/ui/application.vala b/src/ui/application.vala
index a448661f..4dcecb6c 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -219,6 +219,7 @@ public class Games.Application : Gtk.Application {
                var provider = load_css ("gtk-style.css");
                Gtk.StyleContext.add_provider_for_screen (screen, provider, 600);
 
+               init_game_sources ();
                load_game_list.begin ();
                ListStore list_store = new ListStore (typeof (Game));
                game_collection.game_added.connect ((game) => {
@@ -339,15 +340,20 @@ public class Games.Application : Gtk.Application {
        }
 
        internal async void load_game_list () {
-               init_game_sources ();
-
-               yield game_collection.search_games ();
+               if (!yield game_collection.search_games ())
+                       return;
 
                game_list_loaded = true;
                if (window != null)
                        window.loading_notification = false;
        }
 
+       public async void set_pause_loading (bool paused) {
+               game_collection.paused = paused;
+
+               load_game_list.begin ();
+       }
+
        private void preferences () {
                if (preferences_window != null) {
                        preferences_window.present ();


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