From 6bab98ae435e981f50772863d14457e334f0f38b Mon Sep 17 00:00:00 2001 From: Mohsen Mirzakhani Date: Wed, 16 Oct 2024 19:26:43 +0200 Subject: [PATCH] fix loading the preferences on startup --- internal/repository/filesystem.go | 4 +--- ui/app/ui.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/repository/filesystem.go b/internal/repository/filesystem.go index fba39f7..8e8088c 100644 --- a/internal/repository/filesystem.go +++ b/internal/repository/filesystem.go @@ -351,9 +351,7 @@ func (f *Filesystem) LoadCollections() ([]*domain.Collection, error) { } out = append(out, col) } - - // Skip further processing since we're only interested in directories here - return filepath.SkipDir + return nil }) return out, err diff --git a/ui/app/ui.go b/ui/app/ui.go index 9b370c4..93206eb 100644 --- a/ui/app/ui.go +++ b/ui/app/ui.go @@ -77,7 +77,7 @@ func New(w *app.Window, serviceVersion string) (*UI, error) { u.repo = repo - preferences, err := u.repo.ReadPreferencesData() + preferences, err := u.ReadPreferencesData() if err != nil { return nil, fmt.Errorf("failed to read preferences, %w", err) } @@ -191,19 +191,28 @@ func (u *UI) onThemeChange(isDark bool) error { return nil } -func (u *UI) load() error { +func (u *UI) ReadPreferencesData() (*domain.Preferences, error) { preferences, err := u.repo.ReadPreferencesData() if err != nil { if errors.Is(err, os.ErrNotExist) { preferences = domain.NewPreferences() if err := u.repo.UpdatePreferences(preferences); err != nil { - return err + return nil, err } } else { - return err + return nil, err } } + return preferences, nil +} + +func (u *UI) load() error { + preferences, err := u.ReadPreferencesData() + if err != nil { + return err + } + config, err := u.repo.GetConfig() if err != nil { return err