Skip to content
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ Configuration is saved automatically to `~/.config/somafm/config.yml`.

```yaml
volume: 70 # Volume level (0-100)
buffer_seconds: 5 # Audio buffer size (0-60 seconds)
last_station: groovesalad # Last played station ID
autostart: false # Auto-play last station on launch (true/false)
favorites: # List of favorite station IDs
Expand Down
8 changes: 1 addition & 7 deletions cmd/somafm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ func main() {
}
}

cfg, err := config.Load()
if err != nil {
log.Warn().Err(err).Msg("Failed to load config, using defaults")
cfg = config.DefaultConfig()
}

if *debugFlag {
if configPath, err := config.GetConfigPath(); err == nil {
log.Debug().Msgf("Config: %s", configPath)
Expand All @@ -97,7 +91,7 @@ func main() {

apiClient := api.NewSomaFMClient()
stationService := service.NewStationService(apiClient)
somaPlayer := player.NewPlayer(cfg.BufferSeconds)
somaPlayer := player.NewPlayer()
somaUi := ui.NewUI(somaPlayer, stationService, *randomFlag)

sigChan := make(chan os.Signal, 1)
Expand Down
40 changes: 14 additions & 26 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ const (
AppDonateURL = "https://somafm.com/donate/"
AppDonateShort = "somafm.com/donate"

ConfigDir = ".config/somafm"
ConfigFileName = "config.yml"
DefaultVolume = 70
MinVolume = 0
MaxVolume = 100
DefaultBufferSecs = 5
MinBufferSecs = 0
MaxBufferSecs = 60
ConfigDir = ".config/somafm"
ConfigFileName = "config.yml"
DefaultVolume = 70
MinVolume = 0
MaxVolume = 100
)

// ClampVolume ensures volume is within the valid range [0, 100].
Expand Down Expand Up @@ -63,12 +60,11 @@ type Theme struct {
}

type Config struct {
Volume int `yaml:"volume"`
BufferSeconds int `yaml:"buffer_seconds"`
LastStation string `yaml:"last_station"`
Autostart bool `yaml:"autostart"`
Favorites []string `yaml:"favorites"`
Theme Theme `yaml:"theme"`
Volume int `yaml:"volume"`
LastStation string `yaml:"last_station"`
Autostart bool `yaml:"autostart"`
Favorites []string `yaml:"favorites"`
Theme Theme `yaml:"theme"`
}

func GetConfigPath() (string, error) {
Expand Down Expand Up @@ -103,13 +99,6 @@ func Load() (*Config, error) {

cfg.Volume = ClampVolume(cfg.Volume)

if cfg.BufferSeconds < MinBufferSecs {
cfg.BufferSeconds = MinBufferSecs
}
if cfg.BufferSeconds > MaxBufferSecs {
cfg.BufferSeconds = MaxBufferSecs
}

return cfg, nil
}

Expand Down Expand Up @@ -161,11 +150,10 @@ func (c *Config) Save() error {

func DefaultConfig() *Config {
return &Config{
Volume: DefaultVolume,
BufferSeconds: DefaultBufferSecs,
LastStation: "",
Autostart: false,
Favorites: []string{},
Volume: DefaultVolume,
LastStation: "",
Autostart: false,
Favorites: []string{},
Theme: Theme{
Background: "#1a1b25",
Foreground: "#a3aacb",
Expand Down
44 changes: 0 additions & 44 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,50 +412,6 @@ func TestGetColor(t *testing.T) {
}
}

func TestBufferSecondsValidation(t *testing.T) {
tests := []struct {
name string
inputBuffer int
expectedBuffer int
}{
{"valid buffer 5", 5, 5},
{"valid buffer 0", 0, 0},
{"valid buffer 60", 60, 60},
{"negative buffer", -10, MinBufferSecs},
{"buffer over 60", 100, MaxBufferSecs},
{"buffer way over max", 1000, MaxBufferSecs},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpDir := t.TempDir()
originalHome := os.Getenv("HOME")
os.Setenv("HOME", tmpDir)
defer os.Setenv("HOME", originalHome)

testCfg := &Config{
Volume: 70,
BufferSeconds: tt.inputBuffer,
Theme: DefaultConfig().Theme,
}

err := testCfg.Save()
if err != nil {
t.Fatalf("Save() error = %v", err)
}

loadedCfg, err := Load()
if err != nil {
t.Fatalf("Load() error = %v", err)
}

if loadedCfg.BufferSeconds != tt.expectedBuffer {
t.Errorf("Load().BufferSeconds = %d, want %d", loadedCfg.BufferSeconds, tt.expectedBuffer)
}
})
}
}

func TestFavoritesPersistence(t *testing.T) {
tmpDir := t.TempDir()
originalHome := os.Getenv("HOME")
Expand Down
Loading