Files
yellowjacket/backend/favorites/config.go
T
yonlu 6e123bd47f feat(quick-7): add PinDefault config field with backend getter/setter
- Add PinDefault bool to favorites.Config struct with TOML tag
- Add GetPinDefaultPlaylist() and SetPinDefaultPlaylist() methods
- Include PinDefault in emitFavoritesChanged event payload
- Default to true (pinned) for new config installations
2026-03-01 10:05:22 -05:00

63 lines
1.3 KiB
Go

// Package favorites manages the default playlist configuration.
package favorites
import (
"errors"
"fmt"
)
var errUnknownIconStyle = errors.New(
"unknown favorites icon style",
)
// IconStyle controls the icon used to indicate favourited tracks.
type IconStyle string
// Valid IconStyle values.
const (
// IconHeart uses a heart icon.
IconHeart IconStyle = "heart"
// IconStar uses a star icon.
IconStar IconStyle = "star"
)
// DefaultIconStyle is applied when no value has been set.
const DefaultIconStyle = IconHeart
// DefaultPlaylistName is the name given to the auto-created
// default playlist.
const DefaultPlaylistName = "Favorites"
// Config holds favourites preferences.
type Config struct {
PlaylistID int64 `toml:"PlaylistID"`
IconStyle IconStyle `toml:"IconStyle"`
PinDefault bool `toml:"PinDefault"`
}
// ApplyDefaults fills zero-value fields with sensible defaults.
func (c *Config) ApplyDefaults() {
if c.IconStyle == "" {
c.IconStyle = DefaultIconStyle
}
}
// Validate checks that all values are well-formed.
func (c *Config) Validate() error {
c.ApplyDefaults()
switch c.IconStyle {
case IconHeart, IconStar:
// Valid.
default:
return fmt.Errorf(
"%w: %q",
errUnknownIconStyle,
c.IconStyle,
)
}
return nil
}