diff --git a/cartridges/importer/importer.py b/cartridges/importer/importer.py index 96b10f0..79df4ce 100644 --- a/cartridges/importer/importer.py +++ b/cartridges/importer/importer.py @@ -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 diff --git a/cartridges/main.py b/cartridges/main.py index fac4549..43469a0 100644 --- a/cartridges/main.py +++ b/cartridges/main.py @@ -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() diff --git a/cartridges/preferences.py b/cartridges/preferences.py index 3b23521..508f6ff 100644 --- a/cartridges/preferences.py +++ b/cartridges/preferences.py @@ -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", diff --git a/data/gtk/preferences.blp b/data/gtk/preferences.blp index ebc8309..b3f0de5 100644 --- a/data/gtk/preferences.blp +++ b/data/gtk/preferences.blp @@ -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"); } diff --git a/data/page.kramo.Cartridges.gschema.xml.in b/data/page.kramo.Cartridges.gschema.xml.in index 6ad2151..bf6f7ba 100644 --- a/data/page.kramo.Cartridges.gschema.xml.in +++ b/data/page.kramo.Cartridges.gschema.xml.in @@ -2,6 +2,9 @@ + + false + false