Skip to content

Commit

Permalink
fix loading the preferences on startup (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzakhany authored Oct 16, 2024
1 parent 0b4e5f2 commit f4d5ded
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 1 addition & 3 deletions internal/repository/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions ui/app/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f4d5ded

Please sign in to comment.