🎨 Improved internal manager storage
- Stored pipeline managers in a set - Renamed store method to enable_manager_in_pipeline - Simplified a bit the ugly code™ in details_window
This commit is contained in:
@@ -205,35 +205,26 @@ class DetailsWindow(Adw.Window):
|
|||||||
self.game.save()
|
self.game.save()
|
||||||
self.game.update()
|
self.game.update()
|
||||||
|
|
||||||
# TODO: this is fucked up
|
# TODO: this is fucked up (less than before)
|
||||||
# Get a cover from SGDB if none is present
|
# Get a cover from SGDB if none is present
|
||||||
if not self.game_cover.get_pixbuf():
|
if not self.game_cover.get_pixbuf():
|
||||||
self.game.set_loading(1)
|
self.game.set_loading(1)
|
||||||
sgdb_manager: SGDBManager = shared.store.managers[SGDBManager][0]
|
sgdb_manager: SGDBManager = shared.store.managers[SGDBManager]
|
||||||
sgdb_manager.reset_cancellable()
|
sgdb_manager.reset_cancellable()
|
||||||
pipeline = Pipeline(self.game, {}, (sgdb_manager,))
|
sgdb_manager.process_game(self.game, {}, self.update_cover_callback)
|
||||||
pipeline.connect("advanced", self.update_cover_callback)
|
|
||||||
pipeline.advance()
|
|
||||||
|
|
||||||
self.game_cover.pictures.remove(self.cover)
|
self.game_cover.pictures.remove(self.cover)
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
self.win.show_details_view(self.game)
|
self.win.show_details_view(self.game)
|
||||||
|
|
||||||
def update_cover_callback(self, pipeline: Pipeline):
|
def update_cover_callback(self, manager: SGDBManager):
|
||||||
# Check that managers are done
|
|
||||||
if not pipeline.is_done:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Set the game as not loading
|
# Set the game as not loading
|
||||||
self.game.set_loading(-1)
|
self.game.set_loading(-1)
|
||||||
self.game.update()
|
self.game.update()
|
||||||
|
|
||||||
# Handle errors that occured
|
# Handle errors that occured
|
||||||
errors = []
|
for error in manager.collect_errors():
|
||||||
for manager in pipeline.done:
|
|
||||||
errors.extend(manager.collect_errors())
|
|
||||||
for error in errors:
|
|
||||||
# On auth error, inform the user
|
# On auth error, inform the user
|
||||||
if isinstance(error, SGDBAuthError):
|
if isinstance(error, SGDBAuthError):
|
||||||
create_dialog(
|
create_dialog(
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ class CartridgesApplication(Adw.Application):
|
|||||||
shared.store.add_manager(SteamAPIManager())
|
shared.store.add_manager(SteamAPIManager())
|
||||||
shared.store.add_manager(OnlineCoverManager())
|
shared.store.add_manager(OnlineCoverManager())
|
||||||
shared.store.add_manager(SGDBManager())
|
shared.store.add_manager(SGDBManager())
|
||||||
|
shared.store.enable_manager_in_pipelines(FileManager)
|
||||||
shared.store.manager_to_pipeline(FileManager)
|
|
||||||
|
|
||||||
# Create actions
|
# Create actions
|
||||||
self.create_actions(
|
self.create_actions(
|
||||||
|
|||||||
@@ -10,20 +10,26 @@ class Store:
|
|||||||
"""Class in charge of handling games being added to the app."""
|
"""Class in charge of handling games being added to the app."""
|
||||||
|
|
||||||
managers: dict[type[Manager], Manager]
|
managers: dict[type[Manager], Manager]
|
||||||
|
pipeline_managers: set[Manager]
|
||||||
pipelines: dict[str, Pipeline]
|
pipelines: dict[str, Pipeline]
|
||||||
games: dict[str, Game]
|
games: dict[str, Game]
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.managers = {}
|
self.managers = {}
|
||||||
self.games = {}
|
self.pipeline_managers = set()
|
||||||
self.pipelines = {}
|
self.pipelines = {}
|
||||||
|
self.games = {}
|
||||||
|
|
||||||
def add_manager(self, manager: Manager, in_pipeline=True):
|
def add_manager(self, manager: Manager, in_pipeline=True):
|
||||||
"""Add a manager that will run when games are added"""
|
"""Add a manager to the store"""
|
||||||
self.managers[type(manager)] = [manager, in_pipeline]
|
manager_type = type(manager)
|
||||||
|
self.managers[manager_type] = manager
|
||||||
|
if in_pipeline:
|
||||||
|
self.enable_manager_in_pipelines(manager_type)
|
||||||
|
|
||||||
def manager_to_pipeline(self, manager_type: type[Manager]):
|
def enable_manager_in_pipelines(self, manager_type: type[Manager]):
|
||||||
self.managers[manager_type][1] = True
|
"""Make a manager run in new pipelines"""
|
||||||
|
self.pipeline_managers.add(self.managers[manager_type])
|
||||||
|
|
||||||
def cleanup_game(self, game: Game) -> None:
|
def cleanup_game(self, game: Game) -> None:
|
||||||
"""Remove a game's files"""
|
"""Remove a game's files"""
|
||||||
@@ -65,16 +71,12 @@ class Store:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Connect signals
|
# Connect signals
|
||||||
for manager, _in_pipeline in self.managers.values():
|
for manager in self.managers.values():
|
||||||
for signal in manager.signals:
|
for signal in manager.signals:
|
||||||
game.connect(signal, manager.execute_resilient_manager_logic)
|
game.connect(signal, manager.execute_resilient_manager_logic)
|
||||||
|
|
||||||
# Run the pipeline for the game
|
# Run the pipeline for the game
|
||||||
pipeline = Pipeline(
|
pipeline = Pipeline(game, additional_data, self.pipeline_managers)
|
||||||
game,
|
|
||||||
additional_data,
|
|
||||||
(manager[0] for manager in self.managers.values() if manager[1]),
|
|
||||||
)
|
|
||||||
self.games[game.game_id] = game
|
self.games[game.game_id] = game
|
||||||
self.pipelines[game.game_id] = pipeline
|
self.pipelines[game.game_id] = pipeline
|
||||||
pipeline.advance()
|
pipeline.advance()
|
||||||
|
|||||||
Reference in New Issue
Block a user