From 36d3d71d2b0be149bf2de847c08b37dfd55e24f0 Mon Sep 17 00:00:00 2001 From: Simon Garrelou Date: Mon, 12 Dec 2022 21:44:18 +0100 Subject: Fix multiple crashes due to nil pointer --- src/app.go | 8 +++----- src/keybinds.go | 11 ++++++----- src/page_config.go | 5 +++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/app.go b/src/app.go index 173132c..4a15cc1 100644 --- a/src/app.go +++ b/src/app.go @@ -109,11 +109,6 @@ func Run(cfg *Config) { return nil } - switch event.Rune() { - case 'q': - a.tv.Stop() - } - return event }) @@ -127,6 +122,7 @@ func (a *app) switchToPage(name string) { switch name { case "artists": if a.sub == nil { + a.headerSections.Highlight("config") return } if !a.artistsLoaded { @@ -141,6 +137,7 @@ func (a *app) switchToPage(name string) { a.pages.SetBorder(false) case "playqueue": if a.sub == nil { + a.headerSections.Highlight("config") return } a.pages.SwitchToPage("playqueue") @@ -149,6 +146,7 @@ func (a *app) switchToPage(name string) { a.pages.SetBorder(true) case "playlists": if a.sub == nil { + a.headerSections.Highlight("config") return } if !a.playlistsLoaded { diff --git a/src/keybinds.go b/src/keybinds.go index f9d932c..64e895b 100644 --- a/src/keybinds.go +++ b/src/keybinds.go @@ -7,13 +7,14 @@ import ( func (a *app) setupKeybindings(p *tview.Box) { p.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { - // Next & pause - if event.Rune() == 'l' { + switch event.Rune() { + case 'q': + a.tv.Stop() + return nil + case 'l': a.playQueue.Next() return nil - } - - if event.Rune() == 'p' { + case 'p': a.playQueue.TogglePause() return nil } diff --git a/src/page_config.go b/src/page_config.go index ed64f58..31e93e4 100644 --- a/src/page_config.go +++ b/src/page_config.go @@ -34,12 +34,17 @@ func (a *app) configPage() *tview.Form { if err != nil { a.alert("Could not auth: %v", err) } else { + a.playQueue.SetClient(a.sub) a.alert("All good!") } }) form.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyCtrlR { + if a.sub == nil { + return nil + } + if err := a.refreshArtists(); err != nil { a.alert("Error: %v", err) return nil -- cgit v1.2.3