Merge pull request #125 from kra-mo/remove-allow-side-effects

Various cleanups
This commit is contained in:
Geoffrey Coulaud
2023-07-01 03:12:08 +02:00
committed by GitHub
14 changed files with 19 additions and 28 deletions

View File

@@ -233,7 +233,7 @@ template $PreferencesWindow : Adw.PreferencesWindow {
Adw.ActionRow flatpak_data_action_row { Adw.ActionRow flatpak_data_action_row {
title: _("Install Location"); title: _("Install Location");
Button flatpak_config_file_chooser_button { Button flatpak_data_file_chooser_button {
icon-name: "folder-symbolic"; icon-name: "folder-symbolic";
valign: center; valign: center;
} }

View File

@@ -169,8 +169,7 @@ class DetailsWindow(Adw.Window):
"hidden": False, "hidden": False,
"source": "imported", "source": "imported",
"added": int(time()), "added": int(time()),
}, }
allow_side_effects=False,
) )
else: else:

View File

@@ -61,7 +61,7 @@ class Game(Gtk.Box):
game_cover = None game_cover = None
version = 0 version = 0
def __init__(self, data, allow_side_effects=True, **kwargs): def __init__(self, data, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.win = shared.win self.win = shared.win
@@ -70,9 +70,6 @@ class Game(Gtk.Box):
self.update_values(data) self.update_values(data)
if allow_side_effects:
self.win.games[self.game_id] = self
self.set_play_icon() self.set_play_icon()
self.event_contoller_motion = Gtk.EventControllerMotion.new() self.event_contoller_motion = Gtk.EventControllerMotion.new()

View File

@@ -54,7 +54,7 @@ class BottlesSourceIterator(SourceIterator):
bottle_name=entry["bottle"]["name"], game_name=entry["name"] bottle_name=entry["bottle"]["name"], game_name=entry["name"]
), ),
} }
game = Game(values, allow_side_effects=False) game = Game(values)
# Get official cover path # Get official cover path
try: try:

View File

@@ -100,7 +100,7 @@ class FlatpakSourceIterator(SourceIterator):
flatpak_id=flatpak_id flatpak_id=flatpak_id
), ),
} }
game = Game(values, allow_side_effects=False) game = Game(values)
additional_data = {} additional_data = {}
if icon_name := desktop_values["Icon"]: if icon_name := desktop_values["Icon"]:

View File

@@ -90,7 +90,7 @@ class HeroicSourceIterator(SourceIterator):
), ),
"executable": self.source.executable_format.format(app_name=app_name), "executable": self.source.executable_format.format(app_name=app_name),
} }
game = Game(values, allow_side_effects=False) game = Game(values)
# Get the image path from the heroic cache # Get the image path from the heroic cache
# Filenames are derived from the URL that heroic used to get the file # Filenames are derived from the URL that heroic used to get the file

View File

@@ -71,7 +71,7 @@ class ItchSourceIterator(SourceIterator):
"executable": self.source.executable_format.format(cave_id=row[4]), "executable": self.source.executable_format.format(cave_id=row[4]),
} }
additional_data = {"online_cover_url": row[3] or row[2]} additional_data = {"online_cover_url": row[3] or row[2]}
game = Game(values, allow_side_effects=False) game = Game(values)
yield (game, additional_data) yield (game, additional_data)
# Cleanup # Cleanup

View File

@@ -62,7 +62,7 @@ class LegendarySourceIterator(SourceIterator):
except (JSONDecodeError, OSError, KeyError): except (JSONDecodeError, OSError, KeyError):
pass pass
game = Game(values, allow_side_effects=False) game = Game(values)
return (game, data) return (game, data)
def generator_builder(self) -> Generator[SourceIterationResult, None, None]: def generator_builder(self) -> Generator[SourceIterationResult, None, None]:

View File

@@ -74,7 +74,7 @@ class LutrisSourceIterator(SourceIterator):
), ),
"executable": self.source.executable_format.format(game_id=row[2]), "executable": self.source.executable_format.format(game_id=row[2]),
} }
game = Game(values, allow_side_effects=False) game = Game(values)
# Get official image path # Get official image path
image_path = self.source.cache_location["coverart"] / f"{row[2]}.jpg" image_path = self.source.cache_location["coverart"] / f"{row[2]}.jpg"

View File

@@ -96,7 +96,7 @@ class SteamSourceIterator(SourceIterator):
"game_id": self.source.game_id_format.format(game_id=appid), "game_id": self.source.game_id_format.format(game_id=appid),
"executable": self.source.executable_format.format(game_id=appid), "executable": self.source.executable_format.format(game_id=appid),
} }
game = Game(values, allow_side_effects=False) game = Game(values)
# Add official cover image # Add official cover image
image_path = ( image_path = (

View File

@@ -56,6 +56,7 @@ class CartridgesApplication(Adw.Application):
win = None win = None
def __init__(self): def __init__(self):
shared.store = Store()
super().__init__( super().__init__(
application_id=shared.APP_ID, flags=Gio.ApplicationFlags.FLAGS_NONE application_id=shared.APP_ID, flags=Gio.ApplicationFlags.FLAGS_NONE
) )
@@ -82,12 +83,9 @@ class CartridgesApplication(Adw.Application):
"is-maximized", self.win, "maximized", Gio.SettingsBindFlags.DEFAULT "is-maximized", self.win, "maximized", Gio.SettingsBindFlags.DEFAULT
) )
# Create the games store ready to load games from disk # Load games from disk
if not shared.store: shared.store.add_manager(FileManager(), False)
shared.store = Store() shared.store.add_manager(DisplayManager())
shared.store.add_manager(FileManager(), False)
shared.store.add_manager(DisplayManager())
self.load_games_from_disk() self.load_games_from_disk()
# Add rest of the managers for game imports # Add rest of the managers for game imports
@@ -140,7 +138,7 @@ class CartridgesApplication(Adw.Application):
if shared.games_dir.is_dir(): if shared.games_dir.is_dir():
for game_file in shared.games_dir.iterdir(): for game_file in shared.games_dir.iterdir():
data = json.load(game_file.open()) data = json.load(game_file.open())
game = Game(data, allow_side_effects=False) game = Game(data)
shared.store.add_game(game, {"skip_save": True}) shared.store.add_game(game, {"skip_save": True})
def on_about_action(self, *_args): def on_about_action(self, *_args):

View File

@@ -83,7 +83,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
flatpak_expander_row = Gtk.Template.Child() flatpak_expander_row = Gtk.Template.Child()
flatpak_data_action_row = Gtk.Template.Child() flatpak_data_action_row = Gtk.Template.Child()
flatpak_config_file_chooser_button = Gtk.Template.Child() flatpak_data_file_chooser_button = Gtk.Template.Child()
flatpak_import_launchers_switch = Gtk.Template.Child() flatpak_import_launchers_switch = Gtk.Template.Child()
sgdb_key_group = Gtk.Template.Child() sgdb_key_group = Gtk.Template.Child()
@@ -212,7 +212,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
self.toast.dismiss() self.toast.dismiss()
def remove_all_games(self, *_args): def remove_all_games(self, *_args):
for game in self.win.games.values(): for game in shared.store.games.values():
if not game.removed: if not game.removed:
self.removed_games.add(game) self.removed_games.add(game)
@@ -225,7 +225,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
self.add_toast(self.toast) self.add_toast(self.toast)
def reset_app(*_args): def reset_app(self, *_args):
rmtree(shared.data_dir / "cartridges", True) rmtree(shared.data_dir / "cartridges", True)
rmtree(shared.config_dir / "cartridges", True) rmtree(shared.config_dir / "cartridges", True)
rmtree(shared.cache_dir / "cartridges", True) rmtree(shared.cache_dir / "cartridges", True)

View File

@@ -17,7 +17,6 @@
# #
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from src import shared
from src.game import Game from src.game import Game
from src.game_cover import GameCover from src.game_cover import GameCover
from src.store.managers.manager import Manager from src.store.managers.manager import Manager
@@ -32,7 +31,6 @@ class DisplayManager(Manager):
signals = {"update-ready"} signals = {"update-ready"}
def manager_logic(self, game: Game, _additional_data: dict) -> None: def manager_logic(self, game: Game, _additional_data: dict) -> None:
shared.win.games[game.game_id] = game
if game.get_parent(): if game.get_parent():
game.get_parent().get_parent().remove(game) game.get_parent().get_parent().remove(game)
if game.get_parent(): if game.get_parent():

View File

@@ -64,7 +64,6 @@ class CartridgesWindow(Adw.ApplicationWindow):
hidden_search_entry = Gtk.Template.Child() hidden_search_entry = Gtk.Template.Child()
hidden_search_button = Gtk.Template.Child() hidden_search_button = Gtk.Template.Child()
games = {}
game_covers = {} game_covers = {}
toasts = {} toasts = {}
active_game = None active_game = None
@@ -118,7 +117,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
def set_library_child(self): def set_library_child(self):
child, hidden_child = self.notice_empty, self.hidden_notice_empty child, hidden_child = self.notice_empty, self.hidden_notice_empty
for game in self.games.values(): for game in shared.store.games.values():
if game.removed or game.blacklisted: if game.removed or game.blacklisted:
continue continue
if game.hidden: if game.hidden: