From c27a2911eff2ffaa50977f9365ae0736e3b76b8a Mon Sep 17 00:00:00 2001 From: Simon Garrelou Date: Sun, 11 Dec 2022 20:54:33 +0100 Subject: Add "Refresh" in config page --- src/footer.go | 2 +- src/keybinds.go | 4 ++-- src/page_artists.go | 2 +- src/page_config.go | 20 ++++++++++++++++++++ src/page_playlists.go | 2 +- src/page_queue.go | 2 +- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/footer.go b/src/footer.go index f75f954..77c732a 100644 --- a/src/footer.go +++ b/src/footer.go @@ -17,6 +17,6 @@ func (a *app) updateFooter() { a.footer.SetText("[blue]l:[yellow] Next song [blue]p:[yellow] Toggle pause [blue]e:[yellow] Play song last [blue]n:[yellow] Play song next") } case "config": - a.footer.SetText("[yellow]No shortcuts here") + a.footer.SetText("[blue]R:[yellow] Refresh") } } diff --git a/src/keybinds.go b/src/keybinds.go index e3b80a1..f9d932c 100644 --- a/src/keybinds.go +++ b/src/keybinds.go @@ -5,9 +5,9 @@ import ( "github.com/rivo/tview" ) -func (a *app) setupMusicControlKeys(p *tview.Box) { - // Add 'k' and 'l' key bindings +func (a *app) setupKeybindings(p *tview.Box) { p.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { + // Next & pause if event.Rune() == 'l' { a.playQueue.Next() return nil diff --git a/src/page_artists.go b/src/page_artists.go index e0c13fd..4175f3c 100644 --- a/src/page_artists.go +++ b/src/page_artists.go @@ -62,7 +62,7 @@ func (a *app) artistsPage() tview.Primitive { return event }) - a.setupMusicControlKeys(grid.Box) + a.setupKeybindings(grid.Box) grid.AddItem(a.artistsTree, 0, 1, true) grid.AddItem(a.songsList, 0, 1, false) diff --git a/src/page_config.go b/src/page_config.go index 71662ec..2f8a27b 100644 --- a/src/page_config.go +++ b/src/page_config.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/delucks/go-subsonic" + "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -36,6 +37,25 @@ func (a *app) configPage() *tview.Form { a.alert("All good!") } }) + + form.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { + if event.Rune() == 'R' { + if err := a.refreshArtists(); err != nil { + a.alert("Error: %v", err) + return nil + } + + if err := a.refreshPlaylists(); err != nil { + a.alert("Error: %v", err) + return nil + } + + a.alert("Refreshed successfully") + } + + return nil + }) + return form } diff --git a/src/page_playlists.go b/src/page_playlists.go index 303a9a7..2ec8165 100644 --- a/src/page_playlists.go +++ b/src/page_playlists.go @@ -40,7 +40,7 @@ func (a *app) playlistsPage() tview.Primitive { }) // Setup e & n keybinds - a.setupMusicControlKeys(flex.Box) + a.setupKeybindings(flex.Box) flex.AddItem(a.playlistsList, 0, 1, false) flex.AddItem(a.playlistSongs, 0, 1, false) diff --git a/src/page_queue.go b/src/page_queue.go index fe8910f..5912656 100644 --- a/src/page_queue.go +++ b/src/page_queue.go @@ -11,7 +11,7 @@ func (a *app) queuePage() tview.Primitive { ShowSecondaryText(false). SetHighlightFullLine(true) - a.setupMusicControlKeys(a.playQueueList.Box) + a.setupKeybindings(a.playQueueList.Box) a.updatePageQueue() -- cgit v1.2.3