diff --git a/cozy/ui/main_view.py b/cozy/ui/main_view.py index 271c6b91..87bb92eb 100644 --- a/cozy/ui/main_view.py +++ b/cozy/ui/main_view.py @@ -241,13 +241,13 @@ def check_for_tracks(self): if books().count() < 1: self.block_ui_buttons(True) - def scan(self, _, __): + def scan(self, *_): thread = Thread(target=self._importer.scan, name="ScanMediaThread") thread.start() def auto_import(self): if self.application_settings.autoscan: - self.scan(None, None) + self.scan() def __on_hide_offline(self, action, value): """ @@ -271,13 +271,12 @@ def _on_drag_data_received(self, widget, value, *_): thread.start() return True - def _set_audiobook_path(self, path: str | None) -> None: + def _set_audiobook_path(self, path: str | None, default: bool = True) -> None: if path is None: return self.main_stack.set_visible_child_name("import") - self._storages_view_model.add_storage_location(path, default=True) - self.scan(None, None) + self._storages_view_model.add_storage_location(path, default=default) self.fs_monitor.init_offline_mode() def on_close(self, widget, data=None): diff --git a/cozy/ui/widgets/book_card.py b/cozy/ui/widgets/book_card.py index 92fc0438..5d56f343 100644 --- a/cozy/ui/widgets/book_card.py +++ b/cozy/ui/widgets/book_card.py @@ -112,7 +112,8 @@ def set_playing(self, is_playing): self.play_button.set_playing(is_playing) def update_progress(self): - self.play_button.progress = self.book.progress / self.book.duration + if self.book.duration: + self.play_button.progress = self.book.progress / self.book.duration def reset(self) -> None: self.book.last_played = 0 diff --git a/cozy/ui/widgets/welcome_dialog.py b/cozy/ui/widgets/welcome_dialog.py index 842dbf86..83b921dc 100644 --- a/cozy/ui/widgets/welcome_dialog.py +++ b/cozy/ui/widgets/welcome_dialog.py @@ -38,15 +38,17 @@ def accept_reporting(self, _): self.advance() @Gtk.Template.Callback() - def done(self, obj): + def done(self, _): self.close() - inject.instance("MainWindow")._set_audiobook_path(self._path) - if self.create_directory_switch.props.active: audiobooks_dir = Path.home() / _("Audiobooks") audiobooks_dir.mkdir(exist_ok=True) - self._storages_view_model.add_storage_location(str(audiobooks_dir)) + self._storages_view_model.add_storage_location(str(audiobooks_dir), default=True) + + inject.instance("MainWindow")._set_audiobook_path(self._path, default=False) + else: + inject.instance("MainWindow")._set_audiobook_path(self._path) @Gtk.Template.Callback() def choose_directory(self, _): diff --git a/cozy/view_model/settings_view_model.py b/cozy/view_model/settings_view_model.py index 4a8e9a93..f1066d60 100644 --- a/cozy/view_model/settings_view_model.py +++ b/cozy/view_model/settings_view_model.py @@ -22,9 +22,6 @@ def __init__(self): self._lock_ui: bool = False - if self._model.first_start: - self._importer.scan() - @property def lock_ui(self) -> bool: return self._lock_ui diff --git a/cozy/view_model/storages_view_model.py b/cozy/view_model/storages_view_model.py index 7f38581d..9c25fade 100644 --- a/cozy/view_model/storages_view_model.py +++ b/cozy/view_model/storages_view_model.py @@ -1,4 +1,5 @@ import logging +from pathlib import Path from threading import Thread import inject @@ -55,7 +56,9 @@ def add_storage_location(self, path: str | None, default: bool = False) -> None: self._model.invalidate() self._notify("storage_locations") - self._scan_new_storage(model) + if any(Path(path).iterdir()): + # Do this check here, because importer has an entirely different mechanism + self._scan_new_storage(model) def change_storage_location(self, model: Storage, new_path: str) -> None: old_path = model.path