diff options
Diffstat (limited to 'src/app.go')
-rw-r--r-- | src/app.go | 52 |
1 files changed, 44 insertions, 8 deletions
@@ -20,13 +20,21 @@ type app struct { | |||
20 | cfg *Config | 20 | cfg *Config |
21 | 21 | ||
22 | // Artists page | 22 | // Artists page |
23 | artistsTree *tview.TreeView | 23 | artistsLoaded bool |
24 | songsList *tview.List | 24 | artistsTree *tview.TreeView |
25 | currentSongs []*subsonic.Child | 25 | songsList *tview.List |
26 | currentSongs []*subsonic.Child | ||
26 | 27 | ||
27 | // Play queue page | 28 | // Play queue page |
28 | playQueueList *tview.List | 29 | playQueueList *tview.List |
29 | 30 | ||
31 | // Playlist page | ||
32 | playlistsLoaded bool | ||
33 | playlistsList *tview.List | ||
34 | playlistSongs *tview.List | ||
35 | allPlaylists []*subsonic.Playlist | ||
36 | currentPlaylist *subsonic.Playlist | ||
37 | |||
30 | // Subsonic variables | 38 | // Subsonic variables |
31 | sub *subsonic.Client | 39 | sub *subsonic.Client |
32 | playQueue *music.Queue | 40 | playQueue *music.Queue |
@@ -47,6 +55,7 @@ func Run(cfg *Config) { | |||
47 | a.pages.AddPage("config", a.configPage(), true, false) | 55 | a.pages.AddPage("config", a.configPage(), true, false) |
48 | a.pages.AddPage("artists", a.artistsPage(), true, false) | 56 | a.pages.AddPage("artists", a.artistsPage(), true, false) |
49 | a.pages.AddPage("playqueue", a.queuePage(), true, false) | 57 | a.pages.AddPage("playqueue", a.queuePage(), true, false) |
58 | a.pages.AddPage("playlists", a.playlistsPage(), true, false) | ||
50 | 59 | ||
51 | mainLayout := tview.NewFlex(). | 60 | mainLayout := tview.NewFlex(). |
52 | SetDirection(tview.FlexRow). | 61 | SetDirection(tview.FlexRow). |
@@ -59,12 +68,26 @@ func Run(cfg *Config) { | |||
59 | } else { | 68 | } else { |
60 | a.sub, _ = buildSubsonicClient(a.cfg) | 69 | a.sub, _ = buildSubsonicClient(a.cfg) |
61 | a.playQueue.SetClient(a.sub) | 70 | a.playQueue.SetClient(a.sub) |
62 | err := a.refreshArtists() | 71 | |
63 | if err != nil { | 72 | fmt.Printf("Loading artists...") |
64 | a.alert("Could not refresh artists: %v", err) | 73 | if err := a.refreshArtists(); err != nil { |
74 | fmt.Println("ERR") | ||
75 | a.alert("Loading artists: %v", err) | ||
65 | } else { | 76 | } else { |
66 | a.switchToPage("artists") | 77 | fmt.Println("OK") |
78 | a.artistsLoaded = true | ||
79 | } | ||
80 | |||
81 | fmt.Printf("Loading playlists...") | ||
82 | if err := a.refreshPlaylists(); err != nil { | ||
83 | fmt.Println("ERR") | ||
84 | a.alert("Loading playlists: %v", err) | ||
85 | } else { | ||
86 | fmt.Println("OK") | ||
87 | a.playlistsLoaded = true | ||
67 | } | 88 | } |
89 | |||
90 | a.switchToPage("artists") | ||
68 | } | 91 | } |
69 | 92 | ||
70 | // Keyboard shortcuts | 93 | // Keyboard shortcuts |
@@ -101,6 +124,12 @@ func Run(cfg *Config) { | |||
101 | func (a *app) switchToPage(name string) { | 124 | func (a *app) switchToPage(name string) { |
102 | switch name { | 125 | switch name { |
103 | case "artists": | 126 | case "artists": |
127 | if !a.artistsLoaded { | ||
128 | if err := a.refreshArtists(); err != nil { | ||
129 | a.alert("Error: %v", err) | ||
130 | } | ||
131 | a.artistsLoaded = true | ||
132 | } | ||
104 | a.pages.SwitchToPage("artists") | 133 | a.pages.SwitchToPage("artists") |
105 | a.headerSections.Highlight("artists") | 134 | a.headerSections.Highlight("artists") |
106 | a.tv.SetFocus(a.artistsTree) | 135 | a.tv.SetFocus(a.artistsTree) |
@@ -111,9 +140,16 @@ func (a *app) switchToPage(name string) { | |||
111 | a.tv.SetFocus(a.playQueueList) | 140 | a.tv.SetFocus(a.playQueueList) |
112 | a.pages.SetBorder(true) | 141 | a.pages.SetBorder(true) |
113 | case "playlists": | 142 | case "playlists": |
143 | if !a.playlistsLoaded { | ||
144 | if err := a.refreshPlaylists(); err != nil { | ||
145 | a.alert("Error: %v", err) | ||
146 | } | ||
147 | a.playlistsLoaded = true | ||
148 | } | ||
114 | a.pages.SwitchToPage("playlists") | 149 | a.pages.SwitchToPage("playlists") |
115 | a.headerSections.Highlight("playlists") | 150 | a.headerSections.Highlight("playlists") |
116 | a.pages.SetBorder(true) | 151 | a.tv.SetFocus(a.playlistsList) |
152 | a.pages.SetBorder(false) | ||
117 | case "config": | 153 | case "config": |
118 | a.pages.SwitchToPage("config") | 154 | a.pages.SwitchToPage("config") |
119 | a.headerSections.Highlight("config") | 155 | a.headerSections.Highlight("config") |