[gnome-games/wip/exalm/pause-collection] application-window: Pause loading in game
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/pause-collection] application-window: Pause loading in game
- Date: Thu, 14 Feb 2019 05:36:40 +0000 (UTC)
commit 60d9f96aeeafade9471e0c5b71902bb3694ce4e7
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 | 6 +++++-
src/ui/application.vala | 14 ++++++++++----
3 files changed, 25 insertions(+), 7 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..0e1327b0 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -38,6 +38,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
break;
}
+ app.set_pause_loading (ui_state != UiState.COLLECTION);
+
konami_code.reset ();
}
}
@@ -79,6 +81,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
[GtkChild]
private DisplayHeaderBar display_header_bar;
+ private Application app;
private Settings settings;
private Binding box_search_binding;
@@ -104,7 +107,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
private KonamiCode konami_code;
- public ApplicationWindow (ListModel collection) {
+ public ApplicationWindow (Application app, ListModel collection) {
+ this.app = app;
collection_box.collection = collection;
collection.items_changed.connect (() => {
is_collection_empty = collection.get_n_items () == 0;
diff --git a/src/ui/application.vala b/src/ui/application.vala
index a448661f..95edb16b 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) => {
@@ -233,7 +234,7 @@ public class Games.Application : Gtk.Application {
return;
}
- window = new ApplicationWindow (list_store);
+ window = new ApplicationWindow (this, list_store);
this.add_window (window);
window.destroy.connect (() => {
quit_application ();
@@ -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]