diff --git a/cartridges/details_dialog.py b/cartridges/details_dialog.py index 8d85586..98c27d5 100644 --- a/cartridges/details_dialog.py +++ b/cartridges/details_dialog.py @@ -240,6 +240,7 @@ class DetailsDialog(Adw.Dialog): save_cover( self.game.game_id, self.game_cover.path, + self.game_cover.pixbuf, ) shared.store.add_game(self.game, {}, run_pipeline=False) @@ -304,17 +305,17 @@ class DetailsDialog(Adw.Dialog): except UnidentifiedImageError: pass - if not new_path: - new_path = convert_cover( + if new_path: + self.game_cover.new_cover(new_path) + else: + self.game_cover.new_cover( pixbuf=shared.store.managers[CoverManager].composite_cover( Path(path) ) ) - if new_path: - self.game_cover.new_cover(new_path) - self.cover_button_delete_revealer.set_reveal_child(True) - self.cover_changed = True + self.cover_button_delete_revealer.set_reveal_child(True) + self.cover_changed = True self.toggle_loading() diff --git a/cartridges/game_cover.py b/cartridges/game_cover.py index 46dd674..c6f3759 100644 --- a/cartridges/game_cover.py +++ b/cartridges/game_cover.py @@ -45,12 +45,22 @@ class GameCover: self.pictures = pictures self.new_cover(path) - def new_cover(self, path: Optional[Path] = None) -> None: + def new_cover( + self, + path: Optional[Path] = None, + pixbuf: Optional[GdkPixbuf.Pixbuf] = None + ) -> None: self.animation = None self.texture = None self.blurred = None self.luminance = None self.path = path + self.pixbuf = pixbuf + + if pixbuf: + self.texture = Gdk.Texture.new_for_pixbuf(pixbuf) + self.set_texture(self.texture) + return if path: if path.suffix == ".gif": diff --git a/cartridges/store/managers/cover_manager.py b/cartridges/store/managers/cover_manager.py index 34a3580..d5cbd19 100644 --- a/cartridges/store/managers/cover_manager.py +++ b/cartridges/store/managers/cover_manager.py @@ -192,7 +192,5 @@ class CoverManager(Manager): save_cover( game.game_id, - convert_cover( - pixbuf=self.composite_cover(image_path, **composite_kwargs) - ), + pixbuf=self.composite_cover(image_path, **composite_kwargs), ) diff --git a/cartridges/utils/save_cover.py b/cartridges/utils/save_cover.py index d5ad44f..38c414b 100644 --- a/cartridges/utils/save_cover.py +++ b/cartridges/utils/save_cover.py @@ -30,7 +30,6 @@ from cartridges import shared def convert_cover( cover_path: Optional[Path] = None, - pixbuf: Optional[GdkPixbuf.Pixbuf] = None, resize: bool = True, ) -> Optional[Path]: if not cover_path and not pixbuf: @@ -44,10 +43,6 @@ def convert_cover( if not resize and cover_path and cover_path.suffix.lower()[1:] in pixbuf_extensions: return cover_path - if pixbuf: - cover_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path()) - pixbuf.savev(str(cover_path), "tiff", ["compression"], ["1"]) - try: with Image.open(cover_path) as image: if getattr(image, "is_animated", False): @@ -88,7 +83,11 @@ def convert_cover( return tmp_path -def save_cover(game_id: str, cover_path: Path) -> None: +def save_cover( + game_id: str, + cover_path: Optional[Path] = None, + pixbuf: Optional[GdkPixbuf.Pixbuf] = None, +) -> None: shared.covers_dir.mkdir(parents=True, exist_ok=True) animated_path = shared.covers_dir / f"{game_id}.gif" @@ -98,7 +97,15 @@ def save_cover(game_id: str, cover_path: Path) -> None: animated_path.unlink(missing_ok=True) static_path.unlink(missing_ok=True) - if not cover_path: + if not cover_path and not pixbuf: + return + + if pixbuf: + pixbuf.savev(str(static_path), "tiff", ["compression"], ["1"]) + + if game_id in shared.win.game_covers: + shared.win.game_covers[game_id].new_cover(static_path) + return copyfile(