From 3a0911e7425b658c522456cb500e00ef1a2be5ef Mon Sep 17 00:00:00 2001 From: GeoffreyCoulaud Date: Sat, 10 Jun 2023 15:31:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20UI=20not=20updating=20on?= =?UTF-8?q?=20some=20game=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/details_window.py | 18 +++++++++++++++--- src/game.py | 3 +++ src/preferences.py | 2 ++ src/window.py | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/details_window.py b/src/details_window.py index 767110e..0aedb44 100644 --- a/src/details_window.py +++ b/src/details_window.py @@ -17,20 +17,21 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +import logging import os import shlex from time import time from gi.repository import Adw, Gio, GLib, Gtk from PIL import Image +from requests.exceptions import HTTPError, SSLError -# TODO use SGDBHelper from src import shared from src.game import Game from src.game_cover import GameCover from src.utils.create_dialog import create_dialog from src.utils.save_cover import resize_cover, save_cover -from src.utils.steamgriddb import SGDBSave +from src.utils.steamgriddb import SGDBError, SGDBHelper @Gtk.Template(resource_path=shared.PREFIX + "/gtk/details_window.ui") @@ -202,9 +203,20 @@ class DetailsWindow(Adw.Window): ) self.game.save() + self.game.update() + # Try to get a cover if none is present + # TODO inform the user + # TODO wrap in a task and mark loading if not self.game_cover.get_pixbuf(): - SGDBSave({self.game}) + print("test 1212") + sgdb = SGDBHelper() + try: + sgdb.conditionaly_update_cover(self.game) + except SGDBError as error: + logging.error("Could not update cover", exc_info=error) + except (HTTPError, SSLError, ConnectionError): + logging.warning("Could not connect to SteamGridDB") self.game_cover.pictures.remove(self.cover) diff --git a/src/game.py b/src/game.py index 1b4aeef..77f0fec 100644 --- a/src/game.py +++ b/src/game.py @@ -174,6 +174,7 @@ class Game(Gtk.Box): def launch(self): self.last_played = int(time()) self.save() + self.update() string = ( self.executable @@ -206,6 +207,7 @@ class Game(Gtk.Box): def toggle_hidden(self, toast=True): self.hidden = not self.hidden self.save() + self.update() if self.win.stack.get_visible_child() == self.win.details_view: self.win.on_go_back_action() @@ -221,6 +223,7 @@ class Game(Gtk.Box): # Add "removed=True" to the game properties so it can be deleted on next init self.removed = True self.save() + self.update() if self.win.stack.get_visible_child() == self.win.details_view: self.win.on_go_back_action() diff --git a/src/preferences.py b/src/preferences.py index 784fab9..9010aee 100644 --- a/src/preferences.py +++ b/src/preferences.py @@ -245,6 +245,7 @@ class PreferencesWindow(Adw.PreferencesWindow): for game in self.removed_games: game.removed = False game.save() + game.update() self.removed_games = set() self.toast.dismiss() @@ -256,6 +257,7 @@ class PreferencesWindow(Adw.PreferencesWindow): game.removed = True game.save() + game.update() if self.win.stack.get_visible_child() == self.win.details_view: self.win.on_go_back_action() diff --git a/src/window.py b/src/window.py index d2b8ddf..0135a24 100644 --- a/src/window.py +++ b/src/window.py @@ -339,6 +339,7 @@ class CartridgesWindow(Adw.ApplicationWindow): elif undo == "remove": game.removed = False game.save() + game.update() self.toasts[(game, undo)].dismiss() self.toasts.pop((game, undo))