diff --git a/app.go b/app.go index c0d2d61..19037cc 100644 --- a/app.go +++ b/app.go @@ -73,7 +73,7 @@ func (app *App) loadCustomSources() error { if newss, ok := sources.LoadableSources[csrc.Source]; !ok { return fmt.Errorf("Unable to load source #%d: %q: no such source registered", id, csrc.Source) } else { - src, err := newss.LoadSource(csrc.KV) + src, err := newss(csrc.KV) if err != nil { return fmt.Errorf("Unable to load source #%d (%s): %w", id, csrc.Source, err) } diff --git a/settings/settings.go b/settings/settings.go index 4088f75..d8d96bb 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -9,8 +9,8 @@ import ( ) type CustomSource struct { - Source string `json:"src"` - KV map[string]interface{} `json:"kv"` + Source string `json:"src"` + KV map[string]string `json:"kv"` } type Settings struct { diff --git a/sources/interfaces.go b/sources/interfaces.go index 52b0fce..9ec5b2d 100644 --- a/sources/interfaces.go +++ b/sources/interfaces.go @@ -1,8 +1,6 @@ package sources -import ( - "encoding/json" -) +import () var ( LoadableSources = map[string]LoadaleSource{} @@ -21,17 +19,4 @@ type PlayingSource interface { CurrentlyPlaying() string } -type LoadaleSource struct { - LoadSource func(map[string]interface{}) (SoundSource, error) - Description string - SourceDefinition interface{} -} - -func Unmarshal(in map[string]interface{}, out interface{}) error { - jin, err := json.Marshal(in) - if err != nil { - return err - } - - return json.Unmarshal(jin, out) -} +type LoadaleSource func(map[string]string) (SoundSource, error) diff --git a/sources/mpv/source.go b/sources/mpv/source.go index c1826f3..38f4834 100644 --- a/sources/mpv/source.go +++ b/sources/mpv/source.go @@ -1,12 +1,12 @@ package mpv import ( - "errors" "fmt" "log" "os" "os/exec" "path" + "strings" "time" "github.com/DexterLB/mpvipc" @@ -17,23 +17,31 @@ import ( type MPVSource struct { process *exec.Cmd ipcSocketDir string - Name string `json:"name"` - Options []string `json:"opts"` - File string `json:"file"` + Name string + Options []string + File string } func init() { - sources.LoadableSources["mpv"] = sources.LoadaleSource{ - LoadSource: NewMPVSource, - Description: "Play any file, stream or URL through mpv", - SourceDefinition: &MPVSource{}, - } + sources.LoadableSources["mpv"] = NewMPVSource } -func NewMPVSource(kv map[string]interface{}) (sources.SoundSource, error) { +func NewMPVSource(kv map[string]string) (sources.SoundSource, error) { var s MPVSource - err := sources.Unmarshal(kv, &s) - return &s, err + + if name, ok := kv["name"]; ok { + s.Name = name + } + + if opts, ok := kv["opts"]; ok { + s.Options = strings.Split(opts, " ") + } + + if file, ok := kv["file"]; ok { + s.File = file + } + + return &s, nil } func (s *MPVSource) GetName() string { @@ -67,23 +75,13 @@ func (s *MPVSource) Enable() (err error) { s.process = exec.Command("mpv", opts...) if err = s.process.Start(); err != nil { - log.Println("Unable to launch mpv:", err.Error()) return } go func() { err := s.process.Wait() if err != nil { - var exiterr *exec.ExitError - if errors.As(err, &exiterr) { - if exiterr.ExitCode() > 0 { - log.Printf("mpv exited with error code = %d", exiterr.ExitCode()) - } else { - log.Print("mpv exited successfully") - } - } else { - s.process.Process.Kill() - } + s.process.Process.Kill() } if s.ipcSocketDir != "" { @@ -108,7 +106,6 @@ func (s *MPVSource) Enable() (err error) { err = conn.Open() } if err != nil { - log.Println("Unable to connect to mpv socket:", err.Error()) return err } defer conn.Close() @@ -123,23 +120,24 @@ func (s *MPVSource) Enable() (err error) { err = conn.Set("pause", false) if err != nil { - log.Println("Unable to unpause:", err.Error()) return err } var pfc interface{} pfc, err = conn.Get("core-idle") - for err == nil && pfc.(bool) { - time.Sleep(250 * time.Millisecond) - pfc, err = conn.Get("core-idle") - } + if err == nil && pfc.(bool) { + go func() { + for err == nil && pfc.(bool) { + time.Sleep(250 * time.Millisecond) + pfc, err = conn.Get("core-idle") + } - if err != nil { - log.Println("Unable to retrieve core-idle status:", err.Error()) + s.FadeIn(conn, 3, 50) + }() + } else { + s.FadeIn(conn, 3, 50) } - - s.FadeIn(conn, 3, 50) } return diff --git a/ui/src/routes/+layout.svelte b/ui/src/routes/+layout.svelte index fda31dd..7a51938 100644 --- a/ui/src/routes/+layout.svelte +++ b/ui/src/routes/+layout.svelte @@ -1,17 +1,15 @@ @@ -20,50 +18,7 @@