aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Garrelou <simon.garrelou@gmail.com>2022-12-12 21:44:18 +0100
committerSimon Garrelou <simon.garrelou@gmail.com>2022-12-12 21:44:18 +0100
commit36d3d71d2b0be149bf2de847c08b37dfd55e24f0 (patch)
tree60097bb3ace276e93dc62aa72e0558cd01efc3cf
parentf1df9f6faef276bb20de0bb6a78873082194c0e2 (diff)
downloadtermsonic-36d3d71d2b0be149bf2de847c08b37dfd55e24f0.tar.gz
termsonic-36d3d71d2b0be149bf2de847c08b37dfd55e24f0.zip
Fix multiple crashes due to nil pointer
-rw-r--r--src/app.go8
-rw-r--r--src/keybinds.go11
-rw-r--r--src/page_config.go5
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) {
109 return nil 109 return nil
110 } 110 }
111 111
112 switch event.Rune() {
113 case 'q':
114 a.tv.Stop()
115 }
116
117 return event 112 return event
118 }) 113 })
119 114
@@ -127,6 +122,7 @@ func (a *app) switchToPage(name string) {
127 switch name { 122 switch name {
128 case "artists": 123 case "artists":
129 if a.sub == nil { 124 if a.sub == nil {
125 a.headerSections.Highlight("config")
130 return 126 return
131 } 127 }
132 if !a.artistsLoaded { 128 if !a.artistsLoaded {
@@ -141,6 +137,7 @@ func (a *app) switchToPage(name string) {
141 a.pages.SetBorder(false) 137 a.pages.SetBorder(false)
142 case "playqueue": 138 case "playqueue":
143 if a.sub == nil { 139 if a.sub == nil {
140 a.headerSections.Highlight("config")
144 return 141 return
145 } 142 }
146 a.pages.SwitchToPage("playqueue") 143 a.pages.SwitchToPage("playqueue")
@@ -149,6 +146,7 @@ func (a *app) switchToPage(name string) {
149 a.pages.SetBorder(true) 146 a.pages.SetBorder(true)
150 case "playlists": 147 case "playlists":
151 if a.sub == nil { 148 if a.sub == nil {
149 a.headerSections.Highlight("config")
152 return 150 return
153 } 151 }
154 if !a.playlistsLoaded { 152 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 (
7 7
8func (a *app) setupKeybindings(p *tview.Box) { 8func (a *app) setupKeybindings(p *tview.Box) {
9 p.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { 9 p.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
10 // Next & pause 10 switch event.Rune() {
11 if event.Rune() == 'l' { 11 case 'q':
12 a.tv.Stop()
13 return nil
14 case 'l':
12 a.playQueue.Next() 15 a.playQueue.Next()
13 return nil 16 return nil
14 } 17 case 'p':
15
16 if event.Rune() == 'p' {
17 a.playQueue.TogglePause() 18 a.playQueue.TogglePause()
18 return nil 19 return nil
19 } 20 }
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 {
34 if err != nil { 34 if err != nil {
35 a.alert("Could not auth: %v", err) 35 a.alert("Could not auth: %v", err)
36 } else { 36 } else {
37 a.playQueue.SetClient(a.sub)
37 a.alert("All good!") 38 a.alert("All good!")
38 } 39 }
39 }) 40 })
40 41
41 form.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { 42 form.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
42 if event.Key() == tcell.KeyCtrlR { 43 if event.Key() == tcell.KeyCtrlR {
44 if a.sub == nil {
45 return nil
46 }
47
43 if err := a.refreshArtists(); err != nil { 48 if err := a.refreshArtists(); err != nil {
44 a.alert("Error: %v", err) 49 a.alert("Error: %v", err)
45 return nil 50 return nil