diff --git a/cmd/tracks.go b/cmd/tracks.go index 3456b0e..8acd4fe 100644 --- a/cmd/tracks.go +++ b/cmd/tracks.go @@ -4,6 +4,7 @@ import ( "os" "path/filepath" + "gospt/internal/commands" "gospt/internal/tui" "github.com/spf13/cobra" @@ -19,6 +20,9 @@ var tracksCmd = &cobra.Command{ Long: `Uses TUI to open a list of saved tracks`, RunE: func(cmd *cobra.Command, args []string) error { configDir, _ := os.UserConfigDir() + if commands.DeviceActive(ctx, client) { + return tui.StartTea(ctx, client, "tracks") + } if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil { return tui.StartTea(ctx, client, "devices") } diff --git a/cmd/tui.go b/cmd/tui.go index a3edbbe..1b301cf 100644 --- a/cmd/tui.go +++ b/cmd/tui.go @@ -4,6 +4,7 @@ import ( "os" "path/filepath" + "gospt/internal/commands" "gospt/internal/tui" "github.com/spf13/cobra" @@ -19,6 +20,9 @@ var tuiCmd = &cobra.Command{ Long: `Default command. this is what will run if no other commands are present. Shows the main menu.`, RunE: func(cmd *cobra.Command, args []string) error { configDir, _ := os.UserConfigDir() + if commands.DeviceActive(ctx, client) { + return tui.StartTea(ctx, client, "main") + } if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil { return tui.StartTea(ctx, client, "devices") } diff --git a/internal/commands/commands.go b/internal/commands/commands.go index 35b8d37..7c78e66 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -35,6 +35,19 @@ func Play(ctx *gctx.Context, client *spotify.Client) error { return nil } +func DeviceActive(ctx *gctx.Context, client *spotify.Client) bool { + current, err := client.PlayerDevices(ctx) + if err != nil { + return false + } + for _, dev := range current { + if dev.Active { + return true + } + } + return false +} + func PlayUrl(ctx *gctx.Context, client *spotify.Client, args []string) error { url, err := url.Parse(args[0]) if err != nil {