active device check
This commit is contained in:
parent
66518295a9
commit
0d1de1349b
@ -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")
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user