From c51ed54f890957955c43d5e94a071e99127d0438 Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Sat, 13 Jan 2024 07:30:56 -0500 Subject: [PATCH] Move calls to obtain installers from the service onto AsyncCall. --- lutris/services/base.py | 16 ++++++++++++++++ lutris/services/flathub.py | 11 +++-------- lutris/services/steam.py | 8 +------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lutris/services/base.py b/lutris/services/base.py index d261b8150..b430f0b8b 100644 --- a/lutris/services/base.py +++ b/lutris/services/base.py @@ -186,6 +186,22 @@ class BaseService(GObject.Object): """Used to generate an installer from the data returned from the services""" return {} + def install_from_api(self, db_game, appid=None): + """Install a game, using the API or generate_installer() to obtain the installer.""" + if not appid: + appid = db_game["appid"] + + def on_installers_ready(service_installers, error): + if error: + raise error # bounce any error off the backstop + + if not service_installers: + service_installers = [self.generate_installer(db_game)] + application = Gio.Application.get_default() + application.show_installer_window(service_installers, service=self, appid=appid) + + AsyncCall(self.get_installers_from_api, on_installers_ready, appid) + def get_installer_files(self, installer, installer_file_id, selected_extras): """Used to obtains the content files from the service, when an 'N/A' file is left in the installer. This handles 'extras', and must return a tuple; first a list of diff --git a/lutris/services/flathub.py b/lutris/services/flathub.py index 4a9b1871b..35241c0fb 100644 --- a/lutris/services/flathub.py +++ b/lutris/services/flathub.py @@ -6,7 +6,6 @@ from gettext import gettext as _ from pathlib import Path import requests -from gi.repository import Gio from lutris import settings from lutris.exceptions import MissingExecutableError @@ -108,14 +107,10 @@ class FlathubService(BaseService): logger.debug("Installing %s from service %s", app_id, self.id) # Check if Flathub repo is active on the system if not self.is_flathub_remote_active(): - logger.error("Flathub is not configured on the system. Visit https://flatpak.org/setup/ for instructions.") - return + raise RuntimeError( + _("Flathub is not configured on the system. Visit https://flatpak.org/setup/ for instructions.")) # Install the game - service_installers = self.get_installers_from_api(app_id) - if not service_installers: - service_installers = [self.generate_installer(db_game)] - application = Gio.Application.get_default() - application.show_installer_window(service_installers, service=self, appid=app_id) + self.install_from_api(db_game, app_id) def get_installed_apps(self): """Get list of installed Flathub apps""" diff --git a/lutris/services/steam.py b/lutris/services/steam.py index 9211ac845..577d8d99a 100644 --- a/lutris/services/steam.py +++ b/lutris/services/steam.py @@ -4,8 +4,6 @@ import os from collections import defaultdict from gettext import gettext as _ -from gi.repository import Gio - from lutris import settings from lutris.config import LutrisConfig, write_game_config from lutris.database import sql @@ -242,8 +240,4 @@ class SteamService(BaseService): game = Game(existing_game.id) game.save() return - service_installers = self.get_installers_from_api(appid) - if not service_installers: - service_installers = [self.generate_installer(db_game)] - application = Gio.Application.get_default() - application.show_installer_window(service_installers, service=self, appid=appid) + self.install_from_api(db_game, appid)