[gnome-games] game-collection: Add load pausing back
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] game-collection: Add load pausing back
- Date: Wed, 12 Feb 2020 11:42:16 +0000 (UTC)
commit 9d613ed76c712cb0e9c87e0137412f9439243b37
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Feb 12 16:18:30 2020 +0500
game-collection: Add load pausing back
I removed it in 7a4bd62d3689a6b7b046cbc54ea4230dc6144388, as it would make
the code more complex. However, it seems it's not that bad, so add it back.
src/core/game-collection.vala | 55 +++++++++++++++++++++++++++---------------
src/ui/application-window.vala | 5 ++++
src/ui/application.vala | 10 ++++++++
3 files changed, 51 insertions(+), 19 deletions(-)
---
diff --git a/src/core/game-collection.vala b/src/core/game-collection.vala
index f3e63b6a..2fdd8abb 100644
--- a/src/core/game-collection.vala
+++ b/src/core/game-collection.vala
@@ -19,8 +19,11 @@ private class Games.GameCollection : Object {
private HashTable<Platform, Array<RunnerFactory>> runner_factories_for_platforms;
private SourceFunc search_games_cb;
+ private bool is_preloading_done;
private bool is_loading_done;
+ public bool paused { get; set; }
+
public GameCollection (Database database) {
this.database = database;
@@ -95,34 +98,48 @@ private class Games.GameCollection : Object {
search_games_cb = search_games.callback;
ThreadFunc<void*> run = () => {
- try {
- database.list_cached_games ((game) => {
- cached_games[game.get_uri ().to_string ()] = game;
+ if (!is_preloading_done) {
+ try {
+ database.list_cached_games ((game) => {
+ cached_games[game.get_uri ().to_string ()] = game;
- string? uid = null;
- try {
- uid = game.get_uid ().get_uid ();
- }
- catch (Error e) {}
+ string? uid = null;
+ try {
+ uid = game.get_uid ().get_uid ();
+ }
+ catch (Error e) {}
- if (games.contains (uid))
- return;
+ if (games.contains (uid))
+ return;
- games[uid] = game;
+ games[uid] = game;
- Idle.add (() => {
- game_added (game);
- return Source.REMOVE;
+ Idle.add (() => {
+ game_added (game);
+ return Source.REMOVE;
+ });
});
- });
- }
- catch (Error e) {
- critical ("Couldn't load cached games: %s", e.message);
+ }
+ catch (Error e) {
+ critical ("Couldn't load cached games: %s", e.message);
+ }
+
+ is_preloading_done = true;
+
+ if (paused) {
+ Idle.add ((owned) search_games_cb);
+ return null;
+ }
}
foreach (var source in sources)
- foreach (var uri in source)
+ foreach (var uri in source) {
+ if (paused) {
+ Idle.add ((owned) search_games_cb);
+ return null;
+ }
add_uri (uri);
+ }
cached_games.foreach_steal ((uri, game) => {
var removed = false;
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index a3269442..95f56d06 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -21,6 +21,11 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
if (current_view != null)
current_view.is_view_active = true;
+
+ var app = application as Application;
+ assert (app != null);
+
+ app.set_pause_loading (current_view != collection_view);
}
}
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 26e42703..61adf735 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -405,6 +405,16 @@ public class Games.Application : Gtk.Application {
window.loading_notification = false;
}
+ public void set_pause_loading (bool paused) {
+ if (game_collection.paused == paused)
+ return;
+
+ game_collection.paused = paused;
+
+ if (!paused)
+ load_game_list.begin ();
+ }
+
private void preferences () {
if (preferences_window == null) {
preferences_window = new PreferencesWindow ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]