Compare commits

...

1 Commits

Author SHA1 Message Date
kramo
37e24ea8b1 Add an option to import games automatically 2024-10-31 14:11:58 +01:00
5 changed files with 29 additions and 7 deletions

View File

@@ -106,7 +106,6 @@ class Importer(ErrorProducer):
def run(self) -> None:
"""Use several Gio.Task to import games from added sources"""
shared.win.get_application().state = shared.AppState.IMPORT
if self.__class__.summary_toast:
@@ -137,6 +136,7 @@ class Importer(ErrorProducer):
)
self.progress_changed_callback()
GLib.timeout_add(100, self.__watchdog)
def create_dialog(self) -> None:
"""Create the import dialog"""
@@ -281,8 +281,7 @@ class Importer(ErrorProducer):
shared.store.duplicate_game_ids = set()
# Disconnect the close-attempt signal that closes the main window
self.import_dialog.disconnect(self.close_attempt_id)
# Stupid hack because stupid libadwaita is stupid
GLib.timeout_add(50, self.import_dialog.force_close)
self.import_dialog.force_close()
self.__class__.summary_toast = self.create_summary_toast()
self.create_error_dialog()
shared.win.get_application().lookup_action("import").set_enabled(True)
@@ -397,7 +396,13 @@ class Importer(ErrorProducer):
toast.set_title(toast_title)
shared.win.toast_overlay.add_toast(toast)
if not (
self.n_games_added == 0
and removed_length == 0
and shared.schema.get_boolean("auto-import")
):
shared.win.toast_overlay.add_toast(toast)
return toast
def open_preferences(
@@ -423,3 +428,11 @@ class Importer(ErrorProducer):
self.open_preferences(*args).connect("close-request", self.timeout_toast)
else:
self.timeout_toast()
def __watchdog(self) -> bool:
# This can help resolve a race condition where the dialog would stay open
if not self.finished:
return True
self.import_dialog.force_close()
return shared.win.get_visible_dialog() == self.import_dialog

View File

@@ -118,9 +118,6 @@ class CartridgesApplication(Adw.Application):
log_system_info()
# Set fallback icon-name
Gtk.Window.set_default_icon_name(shared.APP_ID)
# Create the main window
win = self.props.active_window # pylint: disable=no-member
if not win:
@@ -196,6 +193,9 @@ class CartridgesApplication(Adw.Application):
shared.win.present()
if shared.schema.get_boolean("auto-import"):
self.on_import_action()
def do_handle_local_options(self, options: GLib.VariantDict) -> int:
if search := options.lookup_value("search"):
self.init_search_term = search.get_string()

View File

@@ -60,6 +60,7 @@ class CartridgesPreferences(Adw.PreferencesDialog):
cover_launches_game_switch: Adw.SwitchRow = Gtk.Template.Child()
high_quality_images_switch: Adw.SwitchRow = Gtk.Template.Child()
auto_import_switch: Adw.SwitchRow = Gtk.Template.Child()
remove_missing_switch: Adw.SwitchRow = Gtk.Template.Child()
steam_expander_row: Adw.ExpanderRow = Gtk.Template.Child()
@@ -237,6 +238,7 @@ class CartridgesPreferences(Adw.PreferencesDialog):
"exit-after-launch",
"cover-launches-game",
"high-quality-images",
"auto-import",
"remove-missing",
"lutris-import-steam",
"lutris-import-flatpak",

View File

@@ -61,6 +61,10 @@ template $CartridgesPreferences: Adw.PreferencesDialog {
Adw.PreferencesGroup import_behavior_group {
title: _("Behavior");
Adw.SwitchRow auto_import_switch {
title: _("Import Games Automatically");
}
Adw.SwitchRow remove_missing_switch {
title: _("Remove Uninstalled Games");
}

View File

@@ -2,6 +2,9 @@
<schemalist gettext-domain="cartridges">
<schema id="@APP_ID@" path="@PREFIX@/">
<key name="auto-import" type="b">
<default>false</default>
</key>
<key name="exit-after-launch" type="b">
<default>false</default>
</key>