Add progress bar + fix race condition
This commit is contained in:
@@ -29,8 +29,6 @@ def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None):
|
|||||||
"cartridges",
|
"cartridges",
|
||||||
"covers",
|
"covers",
|
||||||
)
|
)
|
||||||
if not os.path.exists(covers_dir):
|
|
||||||
os.makedirs(covers_dir)
|
|
||||||
|
|
||||||
if game_id is None:
|
if game_id is None:
|
||||||
game_id = game["game_id"]
|
game_id = game["game_id"]
|
||||||
@@ -41,6 +39,9 @@ def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None):
|
|||||||
def cover_callback(*_unused):
|
def cover_callback(*_unused):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if not os.path.exists(covers_dir):
|
||||||
|
os.makedirs(covers_dir)
|
||||||
|
|
||||||
open_file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".tiff"))
|
open_file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".tiff"))
|
||||||
parent_widget.pixbufs[game_id] = pixbuf
|
parent_widget.pixbufs[game_id] = pixbuf
|
||||||
pixbuf.save_to_streamv_async(
|
pixbuf.save_to_streamv_async(
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ def get_game(task, datatypes, current_time, parent_widget, appmanifest, steam_di
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_games_async(parent_widget, appmanifests, steam_dir, import_dialog):
|
def get_games_async(parent_widget, appmanifests, steam_dir, import_dialog, progressbar):
|
||||||
datatypes = ["appid", "name"]
|
datatypes = ["appid", "name"]
|
||||||
current_time = int(time.time())
|
current_time = int(time.time())
|
||||||
|
|
||||||
@@ -133,9 +133,12 @@ def get_games_async(parent_widget, appmanifests, steam_dir, import_dialog):
|
|||||||
|
|
||||||
def update_games(_task, result, parent_widget):
|
def update_games(_task, result, parent_widget):
|
||||||
nonlocal queue
|
nonlocal queue
|
||||||
|
nonlocal total_queue
|
||||||
nonlocal import_dialog
|
nonlocal import_dialog
|
||||||
|
nonlocal progressbar
|
||||||
|
|
||||||
queue -= 1
|
queue -= 1
|
||||||
|
progressbar.set_fraction(1 - (queue / total_queue))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
final_values = result.propagate_value()[1]
|
final_values = result.propagate_value()[1]
|
||||||
@@ -176,8 +179,10 @@ def get_games_async(parent_widget, appmanifests, steam_dir, import_dialog):
|
|||||||
_(f"Successfully imported {games_no} games."),
|
_(f"Successfully imported {games_no} games."),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
total_queue = 0
|
||||||
for appmanifest in appmanifests:
|
for appmanifest in appmanifests:
|
||||||
queue += 1
|
queue += 1
|
||||||
|
total_queue += 1
|
||||||
|
|
||||||
cancellable = Gio.Cancellable.new()
|
cancellable = Gio.Cancellable.new()
|
||||||
GLib.timeout_add_seconds(5, cancellable.cancel)
|
GLib.timeout_add_seconds(5, cancellable.cancel)
|
||||||
@@ -249,16 +254,18 @@ def steam_parser(parent_widget, action):
|
|||||||
|
|
||||||
steam_dir = os.path.expanduser(schema.get_string("steam-location"))
|
steam_dir = os.path.expanduser(schema.get_string("steam-location"))
|
||||||
|
|
||||||
|
progressbar = Gtk.ProgressBar(margin_start=12, margin_end=12)
|
||||||
import_statuspage = Adw.StatusPage(
|
import_statuspage = Adw.StatusPage(
|
||||||
title=_("Importing Games…"),
|
title=_("Importing Games…"),
|
||||||
description=_("Talking to Steam"),
|
description=_("Talking to Steam"),
|
||||||
|
child=progressbar,
|
||||||
)
|
)
|
||||||
|
|
||||||
import_dialog = Adw.Window(
|
import_dialog = Adw.Window(
|
||||||
content=import_statuspage,
|
content=import_statuspage,
|
||||||
modal=True,
|
modal=True,
|
||||||
default_width=350,
|
default_width=350,
|
||||||
default_height=200,
|
default_height=-1,
|
||||||
transient_for=parent_widget,
|
transient_for=parent_widget,
|
||||||
deletable=False,
|
deletable=False,
|
||||||
)
|
)
|
||||||
@@ -280,4 +287,4 @@ def steam_parser(parent_widget, action):
|
|||||||
if os.path.isfile(path) and "appmanifest" in open_file:
|
if os.path.isfile(path) and "appmanifest" in open_file:
|
||||||
appmanifests.append(path)
|
appmanifests.append(path)
|
||||||
|
|
||||||
get_games_async(parent_widget, appmanifests, directory, import_dialog)
|
get_games_async(parent_widget, appmanifests, directory, import_dialog, progressbar)
|
||||||
|
|||||||
Reference in New Issue
Block a user