[gnome-games] mame: Make MameGameInfo.get_supported_games() async



commit 43df301168887301ef2b6a2c8f750f4df1ffaf31
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Aug 16 12:54:07 2016 +0200

    mame: Make MameGameInfo.get_supported_games() async
    
    This avoids to hang the UI when preparing the list of suported games.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769832

 plugins/mame/src/mame-game-info.vala        |    8 +++++++-
 plugins/mame/src/mame-game-uri-adapter.vala |    2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/plugins/mame/src/mame-game-info.vala b/plugins/mame/src/mame-game-info.vala
index 8e553d2..e04dd08 100644
--- a/plugins/mame/src/mame-game-info.vala
+++ b/plugins/mame/src/mame-game-info.vala
@@ -7,7 +7,7 @@ private struct Games.MameGameInfo {
        public string id;
        public string name;
 
-       public static HashTable<string, MameGameInfo?> get_supported_games () throws Error {
+       public static async HashTable<string, MameGameInfo?> get_supported_games () throws Error {
                if (supported_games != null)
                        return supported_games;
 
@@ -22,6 +22,9 @@ private struct Games.MameGameInfo {
                        var quoted = " *\" *(.*?) *\" *";
                        var pattern = 
@"$simple,$simple,$simple,$simple,$simple,$simple,$simple,$simple,$quoted,$quoted,$simple(?:,$simple)?";
                        game_regex = new Regex ("^GAMEL?\\(" + pattern + "\\) *$");
+
+                       Idle.add (get_supported_games.callback);
+                       yield;
                }
 
                foreach (var line in text.split ("\n")) {
@@ -34,6 +37,9 @@ private struct Games.MameGameInfo {
                                name = cleanup_string (match_info.fetch (10)) // FULLNAME
                        };
                        supported_games[game_info.id] = game_info;
+
+                       Idle.add (get_supported_games.callback);
+                       yield;
                }
 
                return supported_games;
diff --git a/plugins/mame/src/mame-game-uri-adapter.vala b/plugins/mame/src/mame-game-uri-adapter.vala
index fe23847..36fb9d8 100644
--- a/plugins/mame/src/mame-game-uri-adapter.vala
+++ b/plugins/mame/src/mame-game-uri-adapter.vala
@@ -7,7 +7,7 @@ private class Games.MameGameUriAdapter : GameUriAdapter, Object {
        private const bool SUPPORTS_SNAPSHOTTING = false;
 
        public async Game game_for_uri (string uri) throws Error {
-               var supported_games = MameGameInfo.get_supported_games ();
+               var supported_games = yield MameGameInfo.get_supported_games ();
 
                var file = File.new_for_uri (uri);
                var game_id = file.get_basename ();


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