collections: Filter out removed manually added games

This commit is contained in:
Jamie Gravendeel
2025-12-26 15:46:52 +01:00
parent 34cee68ad9
commit 453eca9122

View File

@@ -7,7 +7,9 @@ from typing import TYPE_CHECKING, Any, cast
from gi.repository import Gio, GLib, GObject from gi.repository import Gio, GLib, GObject
from cartridges import SETTINGS from cartridges import SETTINGS, games
from cartridges.games import Game
from cartridges.sources import imported
if TYPE_CHECKING: if TYPE_CHECKING:
from .application import Application from .application import Application
@@ -34,7 +36,7 @@ class Collection(Gio.SimpleActionGroup):
def __init__(self, **kwargs: Any): def __init__(self, **kwargs: Any):
super().__init__(**kwargs) super().__init__(**kwargs)
self.game_ids = [] self.game_ids = self.game_ids or []
self.bind_property( self.bind_property(
"icon", "icon",
self, self,
@@ -66,18 +68,28 @@ class Collection(Gio.SimpleActionGroup):
def _get_collections() -> Generator[Collection]: def _get_collections() -> Generator[Collection]:
manually_added_game_ids = {
game.game_id
for game in cast(Iterable[Game], games.model)
if game.source.startswith(imported.ID)
}
for data in SETTINGS.get_value("collections").unpack(): for data in SETTINGS.get_value("collections").unpack():
if data.get("removed"): if data.get("removed"):
continue continue
collection = Collection() try:
for prop, value in data.items(): yield Collection(
try: name=data["name"],
collection.set_property(prop, value) icon=data["icon"],
except TypeError: game_ids=[
continue ident
for ident in data["game-ids"]
yield collection if not ident.startswith(imported.ID)
or ident in manually_added_game_ids
],
)
except (KeyError, TypeError):
continue
def load(): def load():