diff --git a/hu.kramo.Cartridges.json b/hu.kramo.Cartridges.json index 7d07a4f..c9b46e4 100644 --- a/hu.kramo.Cartridges.json +++ b/hu.kramo.Cartridges.json @@ -10,6 +10,8 @@ "--device=dri", "--socket=wayland", "--talk-name=org.freedesktop.Flatpak", + "--talk-name=org.gtk.vfs.*", + "--filesystem=xdg-run/gvfsd", "--filesystem=~/.steam/steam/:ro", "--filesystem=xdg-config/heroic/:ro", "--filesystem=xdg-data/bottles/:ro", diff --git a/python3-modules.json b/python3-modules.json index a5b1d30..bfa1a0a 100644 --- a/python3-modules.json +++ b/python3-modules.json @@ -16,60 +16,6 @@ "sha256": "68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2" } ] - }, - { - "name": "python3-steam", - "buildsystem": "simple", - "build-commands": [ - "pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"steam\" --no-build-isolation" - ], - "sources": [ - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/db/14/2b48a834d349eee94677e8702ea2ef98b7c674b090153ea8d3f6a788584e/cachetools-5.3.0-py3-none-any.whl", - "sha256": "429e1a1e845c008ea6c85aa35d4b98b65d6a9763eeef3e37e92728a12d1de9d4" - }, - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/71/4c/3db2b8021bd6f2f0ceb0e088d6b2d49147671f25832fb17970e9b583d742/certifi-2022.12.7-py3-none-any.whl", - "sha256": "4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18" - }, - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/ff/d7/8d757f8bd45be079d76309248845a04f09619a7b17d6dfc8c9ff6433cac2/charset-normalizer-3.1.0.tar.gz", - "sha256": "34e0a2f9c370eb95597aae63bf85eb5e96826d81e3dcf88b8886012906f509b5" - }, - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/fc/34/3030de6f1370931b9dbb4dad48f6ab1015ab1d32447850b9fc94e60097be/idna-3.4-py3-none-any.whl", - "sha256": "90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2" - }, - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/3d/07/cfd8f52b9068877801317d26dc7225e19421bc659e1395d2cd6933b1a351/pycryptodomex-3.17.tar.gz", - "sha256": "0af93aad8d62e810247beedef0261c148790c52f3cd33643791cc6396dd217c1" - }, - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/d2/f4/274d1dbe96b41cf4e0efb70cbced278ffd61b5c7bb70338b62af94ccb25b/requests-2.28.2-py3-none-any.whl", - "sha256": "64299f4909223da747622c030b781c0d7811e359c37124b4bd368fb8c6518baa" - }, - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/9a/31/62ac25584988182dee5ee949395e08943ff8b11634dc33abab7078d28433/steam-1.4.4.tar.gz", - "sha256": "2b5bd6911c0d4a7312f441b8d162b9d8d47c8bebb8efc6c8867393b0323fa52e" - }, - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/7b/f5/890a0baca17a61c1f92f72b81d3c31523c99bec609e60c292ea55b387ae8/urllib3-1.26.15-py2.py3-none-any.whl", - "sha256": "aa751d169e23c7479ce47a0cb0da579e3ede798f994f5816a74e4f4500dcea42" - }, - { - "type": "file", - "url": "https://files.pythonhosted.org/packages/96/60/6456b687cf55cf60020dcd01f9bc51561c3cc84f05fd8e0feb71ce60f894/vdf-3.4-py2.py3-none-any.whl", - "sha256": "68c1a125cc49e343d535af2dd25074e9cb0908c6607f073947c4a04bbe234534" - } - ] } ] } \ No newline at end of file diff --git a/src/main.py b/src/main.py index d9b5f24..5e376d6 100644 --- a/src/main.py +++ b/src/main.py @@ -21,6 +21,10 @@ import sys import time import gi + +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") + from gi.repository import Adw, Gio, GLib, Gtk from .bottles_parser import bottles_parser @@ -34,9 +38,6 @@ from .steam_parser import steam_parser from .toggle_hidden import toggle_hidden from .window import CartridgesWindow -gi.require_version("Gtk", "4.0") -gi.require_version("Adw", "1") - class CartridgesApplication(Adw.Application): def __init__(self): @@ -130,9 +131,8 @@ class CartridgesApplication(Adw.Application): PreferencesWindow(self.win).present() def on_steam_import_action(self, _widget, _callback=None): - games = steam_parser(self.win, self.on_steam_import_action) - save_games(games) - self.win.update_games(games.keys()) + # Handle the updating of games inside of the module because the function is async. + steam_parser(self.win, self.on_steam_import_action) def on_heroic_import_action(self, _widget, _callback=None): games = heroic_parser(self.win, self.on_heroic_import_action) diff --git a/src/utils/steam_parser.py b/src/utils/steam_parser.py index 8debd29..8453435 100644 --- a/src/utils/steam_parser.py +++ b/src/utils/steam_parser.py @@ -17,15 +17,16 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +import json import os import re import time -from gi.repository import GLib, Gtk -from steam.utils.appcache import parse_appinfo +from gi.repository import Gio, GLib, Gtk, Adw from .create_dialog import create_dialog from .save_cover import save_cover +from .save_games import save_games def steam_parser(parent_widget, action): @@ -93,17 +94,21 @@ def steam_parser(parent_widget, action): if os.path.isfile(path) and "appmanifest" in open_file: appmanifests.append(path) - with open("/home/kramo/.steam/steam/appcache/appinfo.vdf", "rb") as open_file: - _header, apps = parse_appinfo(open_file) + import_statuspage = Adw.StatusPage( + title="Importing games...", + description="Talking to Steam", + ) - developers = { - app["appid"]: app["data"]["appinfo"]["common"]["associations"]["0"]["name"] - for app in apps - if "common" in app["data"]["appinfo"] - and app["data"]["appinfo"]["common"]["type"] == "Game" - and "associations" in app["data"]["appinfo"]["common"] - and "0" in app["data"]["appinfo"]["common"]["associations"] - } + import_dialog = Adw.Window( + content=import_statuspage, + modal=True, + default_width=350, + default_height=200, + transient_for=parent_widget, + deletable=False, + ) + + queue = [] for appmanifest in appmanifests: values = {} @@ -122,18 +127,70 @@ def steam_parser(parent_widget, action): ): continue - # If the developer is empty, it means that the app is not an actual game - try: - values["developer"] = developers[int(values["appid"])] - except KeyError: - continue - values["executable"] = "xdg-open steam://rungameid/" + values["appid"] values["hidden"] = False values["source"] = "steam" values["added"] = current_time values["last_played"] = 0 + def steam_api_callback(current_file, result, values): + try: + _success, content, _etag = current_file.load_contents_finish(result) + basic_data = json.loads(content)[values["appid"]] + + if not basic_data["success"]: + steam_games.pop(values["game_id"]) + else: + data = basic_data["data"] + steam_games[values["game_id"]]["developer"] = ", ".join( + data["developers"] + ) + + if data["type"] != "game": + steam_games.pop(values["game_id"]) + + except GLib.GError: + pass + + queue.remove(values["appid"]) + if not queue: + import_dialog.close() + + if not steam_games: + create_dialog( + parent_widget, + _("No Games Found"), + _("No new games were found in the Steam library."), + ) + elif len(steam_games) == 1: + create_dialog( + parent_widget, + _("Steam Games Imported"), + _("Successfully imported 1 game."), + ) + elif len(steam_games) > 1: + create_dialog( + parent_widget, + _("Steam Games Imported"), + _("Successfully imported") + + " " + + str(len(steam_games)) + + " " + + _("games."), + ) + save_games(steam_games) + parent_widget.update_games(steam_games.keys()) + + open_file = Gio.File.new_for_uri( + "https://store.steampowered.com/api/appdetails?appids=" + values["appid"] + ) + + if not import_dialog.is_visible(): + import_dialog.show() + + queue.append(values["appid"]) + open_file.load_contents_async(None, steam_api_callback, values) + if os.path.isfile( os.path.join( steam_dir, @@ -155,24 +212,9 @@ def steam_parser(parent_widget, action): steam_games[values["game_id"]] = values - if len(steam_games) == 0: + if not steam_games: create_dialog( parent_widget, _("No Games Found"), _("No new games were found in the Steam library."), ) - elif len(steam_games) == 1: - create_dialog( - parent_widget, _("Steam Games Imported"), _("Successfully imported 1 game.") - ) - elif len(steam_games) > 1: - create_dialog( - parent_widget, - _("Steam Games Imported"), - _("Successfully imported") - + " " - + str(len(steam_games)) - + " " - + _("games."), - ) - return steam_games