[gnome-games/wip/exalm/loading: 23/29] steam: Add runner factory



commit 579a42f9f6b72d36bffae1d38803ed36ad42f0ce
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Nov 12 01:06:59 2019 +0500

    steam: Add runner factory

 plugins/steam/src/steam-plugin.vala | 44 +++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
---
diff --git a/plugins/steam/src/steam-plugin.vala b/plugins/steam/src/steam-plugin.vala
index 9a90c88b..99242ae1 100644
--- a/plugins/steam/src/steam-plugin.vala
+++ b/plugins/steam/src/steam-plugin.vala
@@ -62,6 +62,13 @@ private class Games.SteamPlugin : Object, Plugin {
                return { factory, factory_flatpak };
        }
 
+       public RunnerFactory[] get_runner_factories () {
+               var factory = new GenericRunnerFactory (create_runner);
+               factory.add_platform (platform);
+
+               return { factory };
+       }
+
        private static Game game_for_steam_uri (Uri uri) throws Error {
                return create_game (uri, "steam", "", { "steam" });
        }
@@ -101,6 +108,43 @@ private class Games.SteamPlugin : Object, Plugin {
 
                return game;
        }
+
+       private static Runner? create_runner (Game game) throws Error {
+               var uri = game.get_uri ();
+               var scheme = uri.get_scheme ();
+
+               string[] command;
+               switch (scheme) {
+               case STEAM_FILE_SCHEME:
+                       command = { "steam" };
+                       break;
+
+               case FLATPAK_STEAM_FILE_SCHEME:
+                       command = { "flatpak", "run", STEAM_APPID };
+                       break;
+
+               default:
+                       assert_not_reached ();
+               }
+
+               /* FIXME: Deduplicate the following code with create_game() */
+               var file_uri = new Uri.from_uri_and_scheme (uri, "file");
+               var file = file_uri.to_file ();
+               var appmanifest_path = file.get_path ();
+               var registry = new SteamRegistry (appmanifest_path);
+               var game_id = registry.get_data ({"AppState", "appid"});
+               /* The gamegames_id sometimes is identified by appID
+                * see issue https://github.com/Kekun/gnome-games/issues/169 */
+               if (game_id == null)
+                       game_id = registry.get_data ({"AppState", "appID"});
+
+               if (game_id == null)
+                       throw new SteamError.NO_APPID (_("Couldn’t get Steam appid from manifest “%s”."), 
appmanifest_path);
+
+               command += @"steam://rungameid/$game_id";
+               print(@"WTF $game_id\n");
+               return new CommandRunner (command);
+       }
 }
 
 [ModuleInit]


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