Add repeat and shuffle

This commit is contained in:
aditya-K2
2023-05-17 02:39:49 +05:30
parent ae64e023ed
commit ae6392094e
3 changed files with 39 additions and 0 deletions

View File

@@ -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": {

View File

@@ -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])
}

View File

@@ -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 {