Move openDeviceMenu to utils

This commit is contained in:
aditya-K2
2023-05-01 14:31:22 +05:30
parent c9ee24807e
commit 9c72ff8c38
3 changed files with 25 additions and 28 deletions

View File

@@ -157,7 +157,7 @@ func NewApplication() *tview.Application {
return nil
}, progressBar),
"choose_device": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
OpenDeviceMenu()
openDeviceMenu()
return nil
}, nil),
"focus_nav": NewAction(func(e *tcell.EventKey) *tcell.EventKey {

View File

@@ -1,27 +0,0 @@
package ui
import "github.com/aditya-K2/gspt/spt"
func OpenDeviceMenu() {
m := NewMenu()
cc := []string{}
// TODO: Better Error Handling
devices, err := spt.UserDevices()
if err != nil {
SendNotification(err.Error())
return
}
for _, v := range devices {
cc = append(cc, v.Name)
}
m.Content(cc)
m.Title("Choose A Device")
m.SetSelectionHandler(func(s int) {
if err := spt.TransferPlayback(devices[s].ID); err != nil {
SendNotification(err.Error())
} else {
RefreshProgress(true)
}
})
root.AddCenteredWidget(m)
}

View File

@@ -32,6 +32,30 @@ func openPlaylistMenu(handler func(playlistId spotify.SimplePlaylist)) {
root.AddCenteredWidget(c)
}
func openDeviceMenu() {
m := NewMenu()
cc := []string{}
// TODO: Better Error Handling
devices, err := spt.UserDevices()
if err != nil {
SendNotification(err.Error())
return
}
for _, v := range devices {
cc = append(cc, v.Name)
}
m.Content(cc)
m.Title("Choose A Device")
m.SetSelectionHandler(func(s int) {
if err := spt.TransferPlayback(devices[s].ID); err != nil {
SendNotification(err.Error())
} else {
RefreshProgress(true)
}
})
root.AddCenteredWidget(m)
}
func addToPlaylist(tracks []spotify.ID) {
openPlaylistMenu(func(sp spotify.SimplePlaylist) {
aerr := spt.AddTracksToPlaylist(sp.ID, tracks...)