Skip to content

Commit

Permalink
Fix database errors with new default sotarge location logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Dec 3, 2024
1 parent 59c7fd5 commit fa75c7a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
9 changes: 4 additions & 5 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion cozy/ui/widgets/book_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions cozy/ui/widgets/welcome_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, _):
Expand Down
3 changes: 0 additions & 3 deletions cozy/view_model/settings_view_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion cozy/view_model/storages_view_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from pathlib import Path
from threading import Thread

import inject
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa75c7a

Please sign in to comment.