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
This commit is contained in:
@@ -184,7 +184,9 @@ func (c *Config) applyDefaults() {
|
|||||||
c.TrackList.ApplyDefaults()
|
c.TrackList.ApplyDefaults()
|
||||||
|
|
||||||
if c.Favorites == nil {
|
if c.Favorites == nil {
|
||||||
c.Favorites = &favorites.Config{}
|
c.Favorites = &favorites.Config{
|
||||||
|
PinDefault: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Favorites.ApplyDefaults()
|
c.Favorites.ApplyDefaults()
|
||||||
@@ -527,6 +529,42 @@ func (c *Config) SetFavoritesIconStyle(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPinDefaultPlaylist returns whether the default playlist
|
||||||
|
// is pinned to the top of the playlist view.
|
||||||
|
func (c *Config) GetPinDefaultPlaylist() bool {
|
||||||
|
if c.Favorites == nil {
|
||||||
|
return true // default: pinned
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Favorites.PinDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPinDefaultPlaylist saves whether the default playlist
|
||||||
|
// should be pinned to the top of the playlist view.
|
||||||
|
func (c *Config) SetPinDefaultPlaylist(pin bool) error {
|
||||||
|
if c.Favorites == nil {
|
||||||
|
c.Favorites = &favorites.Config{}
|
||||||
|
c.Favorites.ApplyDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Favorites.PinDefault = pin
|
||||||
|
|
||||||
|
if err := c.Save(); err != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"could not save config: %w", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.emitFavoritesChanged()
|
||||||
|
|
||||||
|
c.logger.Info(
|
||||||
|
"pin default playlist updated",
|
||||||
|
"pin", pin,
|
||||||
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// emitFavoritesChanged sends the FavoritesConfigChanged event
|
// emitFavoritesChanged sends the FavoritesConfigChanged event
|
||||||
// to the frontend.
|
// to the frontend.
|
||||||
func (c *Config) emitFavoritesChanged() {
|
func (c *Config) emitFavoritesChanged() {
|
||||||
@@ -540,6 +578,7 @@ func (c *Config) emitFavoritesChanged() {
|
|||||||
map[string]any{
|
map[string]any{
|
||||||
"PlaylistID": c.Favorites.PlaylistID,
|
"PlaylistID": c.Favorites.PlaylistID,
|
||||||
"IconStyle": string(c.Favorites.IconStyle),
|
"IconStyle": string(c.Favorites.IconStyle),
|
||||||
|
"PinDefault": c.Favorites.PinDefault,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const DefaultPlaylistName = "Favorites"
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
PlaylistID int64 `toml:"PlaylistID"`
|
PlaylistID int64 `toml:"PlaylistID"`
|
||||||
IconStyle IconStyle `toml:"IconStyle"`
|
IconStyle IconStyle `toml:"IconStyle"`
|
||||||
|
PinDefault bool `toml:"PinDefault"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyDefaults fills zero-value fields with sensible defaults.
|
// ApplyDefaults fills zero-value fields with sensible defaults.
|
||||||
|
|||||||
Reference in New Issue
Block a user