mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-08 21:37:58 -05:00
Add Device Menu
This commit is contained in:
13
spt/get.go
13
spt/get.go
@@ -297,3 +297,16 @@ func Search(s string) (*spotify.SearchResult, error) {
|
||||
spotify.SearchTypeTrack|
|
||||
spotify.SearchTypeArtist)
|
||||
}
|
||||
|
||||
func UserDevices() ([]spotify.PlayerDevice, error) {
|
||||
return Client.PlayerDevices(ctx())
|
||||
}
|
||||
|
||||
func TransferPlayback(deviceId spotify.ID) error {
|
||||
s, err := GetPlayerState()
|
||||
if err != nil {
|
||||
return errors.New("Unable to get Current Player State!")
|
||||
}
|
||||
err = Client.PauseOpt(ctx(), &spotify.PlayOptions{DeviceID: &s.Device.ID})
|
||||
return Client.TransferPlayback(ctx(), deviceId, true)
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ func NewApplication() *Application {
|
||||
for {
|
||||
_ImgX, _ImgY, _ImgW, _ImgH := Ui.CoverArt.GetRect()
|
||||
if start {
|
||||
RefreshProgress()
|
||||
RefreshProgress(false)
|
||||
start = false
|
||||
}
|
||||
if _ImgX != ImgX || _ImgY != ImgY ||
|
||||
@@ -285,6 +285,10 @@ func NewApplication() *Application {
|
||||
Ui.App.SetFocus(Main.Table)
|
||||
return nil
|
||||
}
|
||||
if e.Rune() == 'd' {
|
||||
OpenDeviceMenu()
|
||||
return nil
|
||||
}
|
||||
return e
|
||||
})
|
||||
Ui = &Application{
|
||||
|
||||
27
ui/device.go
Normal file
27
ui/device.go
Normal file
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
Ui.Root.AddCenteredWidget(m)
|
||||
}
|
||||
Reference in New Issue
Block a user