mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-09 13:58:05 -05:00
Add toggle_playback mapping
This commit is contained in:
@@ -95,6 +95,7 @@ func GenerateMappings() map[string]map[Key]string {
|
||||
{R: '2'}: "focus_playlists",
|
||||
{R: '3'}: "focus_main_view",
|
||||
{R: '?'}: "focus_search",
|
||||
{R: ' '}: "toggle_playback",
|
||||
},
|
||||
"playlist_nav": {
|
||||
{K: tcell.KeyEnter}: "open_entry",
|
||||
|
||||
@@ -72,6 +72,11 @@ var (
|
||||
"pause": tcell.KeyPause,
|
||||
"backtab": tcell.KeyBacktab,
|
||||
}
|
||||
runeMap = map[rune]bool{
|
||||
'?': true,
|
||||
'!': true,
|
||||
' ': true,
|
||||
}
|
||||
)
|
||||
|
||||
func (k *Key) Rune() rune {
|
||||
@@ -88,7 +93,7 @@ func NewKey(s string) Key {
|
||||
if (a[0] >= 'A' && a[0] <= 'Z') ||
|
||||
(a[0] >= 'a' && a[0] <= 'z') ||
|
||||
(a[0] >= '0' && a[0] <= '9') ||
|
||||
(a[0] == '?' || a[0] == '!') {
|
||||
(runeMap[a[0]]) {
|
||||
return Key{R: a[0]}
|
||||
}
|
||||
}
|
||||
|
||||
17
spt/play.go
17
spt/play.go
@@ -33,3 +33,20 @@ func PlayContext(context *spotify.URI) error {
|
||||
PlaybackContext: context,
|
||||
})
|
||||
}
|
||||
|
||||
func TogglePlayback() error {
|
||||
p, err := Client.PlayerCurrentlyPlaying(ctx())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if p.Playing {
|
||||
if err := Client.Pause(ctx()); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := Client.Play(ctx()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/aditya-K2/gspt/config"
|
||||
"github.com/aditya-K2/gspt/spt"
|
||||
"github.com/aditya-K2/utils"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
@@ -116,6 +117,12 @@ func NewApplication() *Application {
|
||||
Ui.App.SetFocus(searchbar)
|
||||
return nil
|
||||
}, nil),
|
||||
"toggle_playback": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
if err := spt.TogglePlayback(); err != nil {
|
||||
SendNotification(err.Error())
|
||||
}
|
||||
return nil
|
||||
}, pBar),
|
||||
"choose_device": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
OpenDeviceMenu()
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user