Skip to content

Commit

Permalink
Make SteamInstaller not a GObject and change it to use NotificationSo…
Browse files Browse the repository at this point in the history
…urce instead of signals.
  • Loading branch information
danieljohnson2 committed Apr 29, 2024
1 parent 070d1f0 commit cce8ef7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
12 changes: 10 additions & 2 deletions lutris/gui/installer/file_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def get_file_provider_widget(self):
if isinstance(self.installer_file, InstallerFileCollection):
raise RuntimeError("Installer file is type InstallerFileCollection and do not support 'steam' provider")
steam_installer = SteamInstaller(self.installer_file.url, self.installer_file.id)
steam_installer.connect("steam-game-installed", self.on_download_complete)
steam_installer.connect("steam-state-changed", self.on_state_changed)
steam_installer.game_installed.register(self.on_steam_game_installed)
steam_installer.game_state_changed.register(self.on_steam_game_state_changed)
self.start_func = steam_installer.install_steam_game
self.stop_func = steam_installer.stop_func

Expand Down Expand Up @@ -196,6 +196,10 @@ def on_state_changed(self, _widget, state):
"""Update the state label with a new state"""
self.state_label.set_text(state)

def on_steam_game_state_changed(self, installer):
"""Update the state label with a new state"""
self.state_label.set_text(installer.state)

def start(self):
"""Starts the download of the file"""
self.started = True
Expand Down Expand Up @@ -226,3 +230,7 @@ def on_download_complete(self, widget, _data=None):
else:
self.cache_file()
self.emit("file-available")

def on_steam_game_installed(self, installer):
self.installer_file.dest_file = installer.get_steam_data_path()
self.emit("file-available")
19 changes: 7 additions & 12 deletions lutris/installer/steam_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
import time
from gettext import gettext as _

from gi.repository import GObject

from lutris.config import LutrisConfig
from lutris.gui.widgets import NotificationSource
from lutris.installer.errors import ScriptingError
from lutris.runners import steam
from lutris.util.jobs import AsyncCall, schedule_repeating_at_idle
from lutris.util.log import logger
from lutris.util.steam.log import get_app_state_log


class SteamInstaller(GObject.Object):
class SteamInstaller:
"""Handles installation of Steam games"""

__gsignals__ = {
"steam-game-installed": (GObject.SIGNAL_RUN_FIRST, None, (str,)),
"steam-state-changed": (GObject.SIGNAL_RUN_FIRST, None, (str,)),
}

def __init__(self, steam_uri, file_id):
"""
Params:
Expand All @@ -31,7 +25,8 @@ def __init__(self, steam_uri, file_id):
- The relative path of files to retrieve
file_id: The lutris installer internal id for the game files
"""
super().__init__()
self.game_installed = NotificationSource()
self.game_state_changed = NotificationSource()
self.steam_poll = None
self.prev_states = [] # Previous states for the Steam installer
self.state = ""
Expand Down Expand Up @@ -72,7 +67,7 @@ def install_steam_game(self) -> None:
"""Launch installation of a steam game"""
if self.runner.get_game_path_from_appid(appid=self.appid):
logger.info("Steam game %s is already installed", self.appid)
self.emit("steam-game-installed", self.appid)
self.game_installed.fire(self)
else:
logger.debug("Installing steam game %s", self.appid)
self.runner.config = LutrisConfig(runner_slug=self.runner.name)
Expand All @@ -96,13 +91,13 @@ def _monitor_steam_game_install(self) -> bool:
if states and states != self.prev_states:
self.state = states[-1].split(",")[-1]
logger.debug("Steam installation status: %s", states)
self.emit("steam-state-changed", self.state) # Broadcast new state to listeners
self.game_state_changed.fire(self) # Broadcast new state to listeners

self.prev_states = states
logger.debug(self.state)
logger.debug(states)
if self.state == "Fully Installed":
logger.info("Steam game %s has been installed successfully", self.appid)
self.emit("steam-game-installed", self.appid)
self.game_installed.fire(self)
return False
return True

0 comments on commit cce8ef7

Please sign in to comment.