Handle bogus sources gracefully

This commit is contained in:
kramo
2025-04-28 20:09:11 +02:00
parent cb7aaf1f39
commit 89080c03bc
2 changed files with 14 additions and 6 deletions

View File

@@ -136,9 +136,11 @@ class Importer(ErrorProducer):
task = Gio.Task.new(None, None, self.source_callback, (source,)) task = Gio.Task.new(None, None, self.source_callback, (source,))
self.n_source_tasks_created += 1 self.n_source_tasks_created += 1
task.run_in_thread( task.run_in_thread(
lambda _task, _obj, _data, _cancellable, src=source: self.source_task_thread_func( lambda _task,
(src,) _obj,
) _data,
_cancellable,
src=source: self.source_task_thread_func((src,))
) )
# Workaround: Adw bug: Dialog won't close if closed too soon after opening # Workaround: Adw bug: Dialog won't close if closed too soon after opening
@@ -150,7 +152,6 @@ class Importer(ErrorProducer):
self.import_dialog.force_close() self.import_dialog.force_close()
return shared.win.get_visible_dialog() == self.import_dialog return shared.win.get_visible_dialog() == self.import_dialog
def monitor_import(self) -> bool: def monitor_import(self) -> bool:
"""Monitor import progress to update dialog and to trigger import cleanup """Monitor import progress to update dialog and to trigger import cleanup
once the work has finished""" once the work has finished"""
@@ -185,12 +186,16 @@ class Importer(ErrorProducer):
if not shared.schema.get_boolean("remove-missing"): if not shared.schema.get_boolean("remove-missing"):
return return
keys = shared.schema.list_keys()
for game in shared.store: for game in shared.store:
if game.removed: if game.removed:
continue continue
if game.source == "imported": if game.source == "imported":
continue continue
if not shared.schema.get_boolean(game.base_source): if (game.base_source in keys) and (
not shared.schema.get_boolean(game.base_source)
):
continue continue
if game.game_id in shared.store.duplicate_game_ids: if game.game_id in shared.store.duplicate_game_ids:
continue continue

View File

@@ -250,7 +250,10 @@ class CartridgesApplication(Adw.Application):
elif source_id == "imported": elif source_id == "imported":
name = _("Added") name = _("Added")
else: else:
name = globals()[f'{source_id.split("_")[0].title()}Source'].name try:
name = globals()[f"{source_id.split('_')[0].title()}Source"].name
except KeyError:
return source_id
return name return name
def on_about_action(self, *_args: Any) -> None: def on_about_action(self, *_args: Any) -> None: