Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loading the preferences on startup #97

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading