mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-08 05:23:51 -05:00
Move openDeviceMenu to utils
This commit is contained in:
@@ -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 {
|
||||
|
||||
27
ui/device.go
27
ui/device.go
@@ -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)
|
||||
}
|
||||
24
ui/utils.go
24
ui/utils.go
@@ -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...)
|
||||
|
||||
Reference in New Issue
Block a user