From ae6392094ea31af1452e4ccef2980c76305bb79c Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Wed, 17 May 2023 02:39:49 +0530 Subject: [PATCH] Add repeat and shuffle --- config/key.go | 2 ++ spt/play.go | 25 +++++++++++++++++++++++++ ui/app.go | 12 ++++++++++++ 3 files changed, 39 insertions(+) diff --git a/config/key.go b/config/key.go index caffc29..4377684 100644 --- a/config/key.go +++ b/config/key.go @@ -47,6 +47,8 @@ var ( {R: 'K'}: "decrease_image_height", {R: 'L'}: "increase_image_width", {K: tcell.KeyCtrlS}: "save_config", + {R: 'z'}: "shuffle", + {R: 'r'}: "repeat", }, }, "playlist_nav": { diff --git a/spt/play.go b/spt/play.go index 51521aa..230a9a6 100644 --- a/spt/play.go +++ b/spt/play.go @@ -69,3 +69,28 @@ func Next() error { func Previous() error { return Client.Previous(ctx()) } + +func Shuffle() error { + s, err := GetPlayerState() + + if err != nil { + return err + } + + return Client.Shuffle(ctx(), !s.ShuffleState) +} + +func Repeat() error { + s, err := GetPlayerState() + next := map[string]string{ + "context": "track", + "track": "off", + "off": "context", + } + + if err != nil { + return err + } + + return Client.Repeat(ctx(), next[s.RepeatState]) +} diff --git a/ui/app.go b/ui/app.go index e9091c7..51f19ae 100644 --- a/ui/app.go +++ b/ui/app.go @@ -128,6 +128,18 @@ func NewApplication() *tview.Application { // Define Actions globalActions := map[string]*Action{ + "shuffle": NewAction(func(e *tcell.EventKey) *tcell.EventKey { + if err := spt.Shuffle(); err != nil { + SendNotification(err.Error()) + } + return nil + }, progressBar), + "repeat": NewAction(func(e *tcell.EventKey) *tcell.EventKey { + if err := spt.Repeat(); err != nil { + SendNotification(err.Error()) + } + return nil + }, progressBar), "save_config": NewAction(func(e *tcell.EventKey) *tcell.EventKey { msg := "Config Saved Successfully!" if err := config.WriteConfig(); err != nil {