Move calls to obtain installers from the service onto AsyncCall.

This commit is contained in:
Daniel Johnson 2024-01-13 07:30:56 -05:00 committed by Mathieu Comandon
parent 2b9358e7f2
commit c51ed54f89
3 changed files with 20 additions and 15 deletions

View file

@ -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

View file

@ -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"""

View file

@ -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)