Async image saving

This commit is contained in:
kramo
2023-03-13 23:09:51 +01:00
parent 3af1e42548
commit 35185205e3
2 changed files with 12 additions and 4 deletions

View File

@@ -18,7 +18,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None): def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None):
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf, Gio
import os import os
covers_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers") covers_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers")
@@ -28,9 +28,13 @@ def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None):
if game_id == None: if game_id == None:
game_id = game["game_id"] game_id = game["game_id"]
cover_path = os.path.join(covers_dir, game_id + ".png")
if pixbuf == None: if pixbuf == None:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(file_path, 400, 600, False) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(file_path, 400, 600, False)
pixbuf.savev(cover_path, "png") def cover_callback(*args):
parent_widget.busy_games.remove(game_id)
parent_widget.update_games([game_id])
file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".png"))
parent_widget.busy_games.append(game_id)
pixbuf.save_to_streamv_async(file.replace(None, False, Gio.FileCreateFlags.NONE), "png", None, None, None, cover_callback)

View File

@@ -74,6 +74,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.hidden_filtered = {} self.hidden_filtered = {}
self.previous_page = self.library_view self.previous_page = self.library_view
self.toasts = {} self.toasts = {}
self.busy_games = []
self.overview.set_measure_overlay(self.overview_box, True) self.overview.set_measure_overlay(self.overview_box, True)
self.overview.set_clip_overlay(self.overview_box, False) self.overview.set_clip_overlay(self.overview_box, False)
@@ -107,6 +108,9 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.games = get_games() self.games = get_games()
for game_id in games: for game_id in games:
if game_id in self.busy_games:
continue
if game_id in self.visible_widgets: if game_id in self.visible_widgets:
self.library.remove(self.visible_widgets[game_id]) self.library.remove(self.visible_widgets[game_id])
self.filtered.pop(self.visible_widgets[game_id]) self.filtered.pop(self.visible_widgets[game_id])