This commit is contained in:
parent
052bf1cef6
commit
78ab7fe95d
@ -2,6 +2,8 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gospt/internal/commands"
|
||||
"gospt/internal/gctx"
|
||||
@ -12,9 +14,15 @@ import (
|
||||
|
||||
func Run(ctx *gctx.Context, client *spotify.Client, args []string) error {
|
||||
if len(args) == 0 {
|
||||
configDir, _ := os.UserConfigDir()
|
||||
if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil {
|
||||
return tui.DisplayDevices(ctx, client)
|
||||
}
|
||||
return tui.DisplayMain(ctx, client)
|
||||
}
|
||||
switch args[0] {
|
||||
case "help", "--help":
|
||||
return commands.PrintHelp(ctx)
|
||||
case "play":
|
||||
return commands.Play(ctx, client)
|
||||
case "pause":
|
||||
|
@ -16,6 +16,14 @@ import (
|
||||
"github.com/zmb3/spotify/v2"
|
||||
)
|
||||
|
||||
func PrintHelp(ctx *gctx.Context) error {
|
||||
fmt.Println("Usage: gospt [command]")
|
||||
fmt.Println("if no command is provided then TUI will open")
|
||||
fmt.Println("\ncurrently available commands:")
|
||||
fmt.Println("help, play, pause, toggleplay, \nnext, previous, playurl, like, unlike, shuffle, \nrepeat, radio, clearradio, refillradio, tracks, \nclearradio, playlists, status, devices, nowplaying, setdevice")
|
||||
return nil
|
||||
}
|
||||
|
||||
func Play(ctx *gctx.Context, client *spotify.Client) error {
|
||||
err := client.Play(ctx)
|
||||
if err != nil {
|
||||
|
@ -43,14 +43,16 @@ func (m deviceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, tea.Quit
|
||||
}
|
||||
if msg.String() == "enter" {
|
||||
fmt.Println("SELECTING")
|
||||
device := m.list.SelectedItem()
|
||||
var err error
|
||||
err = commands.SetDevice(m.ctx, m.client, device.(deviceItem).PlayerDevice)
|
||||
if err != nil {
|
||||
m.ctx.Printf(err.Error())
|
||||
}
|
||||
fmt.Println("DEVICE SET")
|
||||
err = DisplayMain(m.ctx, m.client)
|
||||
if err != nil {
|
||||
return m, tea.Quit
|
||||
}
|
||||
return m, tea.Quit
|
||||
}
|
||||
case tea.MouseMsg:
|
||||
|
@ -118,7 +118,7 @@ func DisplayMain(ctx *gctx.Context, client *spotify.Client) error {
|
||||
ctx: ctx,
|
||||
client: client,
|
||||
}
|
||||
m.list.Title = "Saved Tracks"
|
||||
m.list.Title = "GOSPT"
|
||||
|
||||
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())
|
||||
|
||||
|
@ -134,7 +134,7 @@ func PlaylistTracks(ctx *gctx.Context, client *spotify.Client, playlist spotify.
|
||||
client: client,
|
||||
playlist: playlist,
|
||||
}
|
||||
m.list.Title = "Saved Tracks"
|
||||
m.list.Title = playlist.Name
|
||||
|
||||
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user