diff options
author | Simon Garrelou <simon.garrelou@gmail.com> | 2022-12-08 22:35:17 +0100 |
---|---|---|
committer | Simon Garrelou <simon.garrelou@gmail.com> | 2022-12-08 22:35:17 +0100 |
commit | 7e4333dac70cdb003e71b6805ed4d81f18aa233a (patch) | |
tree | 26190c147141f765d69880d98d891bf50071e891 /src/app.go | |
parent | 96cc5db2b4062ced82faf01ddac24abef04df343 (diff) | |
download | termsonic-7e4333dac70cdb003e71b6805ed4d81f18aa233a.tar.gz termsonic-7e4333dac70cdb003e71b6805ed4d81f18aa233a.zip |
Music playback working
Diffstat (limited to 'src/app.go')
-rw-r--r-- | src/app.go | 45 |
1 files changed, 19 insertions, 26 deletions
@@ -4,6 +4,7 @@ import ( | |||
4 | "fmt" | 4 | "fmt" |
5 | "os" | 5 | "os" |
6 | 6 | ||
7 | "git.sixfoisneuf.fr/termsonic/music" | ||
7 | "github.com/delucks/go-subsonic" | 8 | "github.com/delucks/go-subsonic" |
8 | "github.com/gdamore/tcell/v2" | 9 | "github.com/gdamore/tcell/v2" |
9 | "github.com/rivo/tview" | 10 | "github.com/rivo/tview" |
@@ -11,23 +12,26 @@ import ( | |||
11 | 12 | ||
12 | type app struct { | 13 | type app struct { |
13 | // General GUI | 14 | // General GUI |
14 | tv *tview.Application | 15 | tv *tview.Application |
15 | pages *tview.Pages | 16 | pages *tview.Pages |
16 | header *tview.TextView | 17 | headerSections *tview.TextView |
17 | footer *tview.TextView | 18 | headerNowPlaying *tview.TextView |
18 | cfg *Config | 19 | footer *tview.TextView |
20 | cfg *Config | ||
19 | 21 | ||
20 | // Artists panel | 22 | // Artists panel |
21 | artistsTree *tview.TreeView | 23 | artistsTree *tview.TreeView |
22 | songsList *tview.List | 24 | songsList *tview.List |
23 | 25 | ||
24 | // Subsonic variables | 26 | // Subsonic variables |
25 | sub *subsonic.Client | 27 | sub *subsonic.Client |
28 | playQueue *music.Queue | ||
26 | } | 29 | } |
27 | 30 | ||
28 | func Run(cfg *Config) { | 31 | func Run(cfg *Config) { |
29 | a := &app{ | 32 | a := &app{ |
30 | cfg: cfg, | 33 | cfg: cfg, |
34 | playQueue: music.NewQueue(nil), | ||
31 | } | 35 | } |
32 | 36 | ||
33 | a.tv = tview.NewApplication() | 37 | a.tv = tview.NewApplication() |
@@ -35,28 +39,13 @@ func Run(cfg *Config) { | |||
35 | a.footer = tview.NewTextView(). | 39 | a.footer = tview.NewTextView(). |
36 | SetDynamicColors(true) | 40 | SetDynamicColors(true) |
37 | 41 | ||
38 | a.header = tview.NewTextView(). | ||
39 | SetRegions(true). | ||
40 | SetChangedFunc(func() { | ||
41 | a.tv.Draw() | ||
42 | }). | ||
43 | SetHighlightedFunc(func(added, _, _ []string) { | ||
44 | hl := added[0] | ||
45 | cur, _ := a.pages.GetFrontPage() | ||
46 | |||
47 | if hl != cur { | ||
48 | a.switchToPage(hl) | ||
49 | } | ||
50 | }) | ||
51 | fmt.Fprintf(a.header, `["artists"]F1: Artists[""] | ["playlists"]F2: Playlists[""] | ["config"]F3: Configuration[""]`) | ||
52 | |||
53 | a.pages.SetBorder(true) | 42 | a.pages.SetBorder(true) |
54 | a.pages.AddPage("config", a.configPage(), true, false) | 43 | a.pages.AddPage("config", a.configPage(), true, false) |
55 | a.pages.AddPage("artists", a.artistsPage(), true, false) | 44 | a.pages.AddPage("artists", a.artistsPage(), true, false) |
56 | 45 | ||
57 | mainLayout := tview.NewFlex(). | 46 | mainLayout := tview.NewFlex(). |
58 | SetDirection(tview.FlexRow). | 47 | SetDirection(tview.FlexRow). |
59 | AddItem(a.header, 1, 1, false). | 48 | AddItem(a.buildHeader(), 1, 1, false). |
60 | AddItem(a.pages, 0, 3, true). | 49 | AddItem(a.pages, 0, 3, true). |
61 | AddItem(a.footer, 1, 1, false) | 50 | AddItem(a.footer, 1, 1, false) |
62 | 51 | ||
@@ -64,6 +53,7 @@ func Run(cfg *Config) { | |||
64 | a.switchToPage("config") | 53 | a.switchToPage("config") |
65 | } else { | 54 | } else { |
66 | a.sub, _ = buildSubsonicClient(a.cfg) | 55 | a.sub, _ = buildSubsonicClient(a.cfg) |
56 | a.playQueue.SetClient(a.sub) | ||
67 | err := a.refreshArtists() | 57 | err := a.refreshArtists() |
68 | if err != nil { | 58 | if err != nil { |
69 | a.alert("Could not refresh artists: %v", err) | 59 | a.alert("Could not refresh artists: %v", err) |
@@ -104,14 +94,17 @@ func (a *app) switchToPage(name string) { | |||
104 | switch name { | 94 | switch name { |
105 | case "artists": | 95 | case "artists": |
106 | a.pages.SwitchToPage("artists") | 96 | a.pages.SwitchToPage("artists") |
107 | a.header.Highlight("artists") | 97 | a.headerSections.Highlight("artists") |
108 | a.tv.SetFocus(a.artistsTree) | 98 | a.tv.SetFocus(a.artistsTree) |
99 | a.pages.SetBorder(false) | ||
109 | case "playlists": | 100 | case "playlists": |
110 | a.pages.SwitchToPage("playlists") | 101 | a.pages.SwitchToPage("playlists") |
111 | a.header.Highlight("playlists") | 102 | a.headerSections.Highlight("playlists") |
103 | a.pages.SetBorder(true) | ||
112 | case "config": | 104 | case "config": |
113 | a.pages.SwitchToPage("config") | 105 | a.pages.SwitchToPage("config") |
114 | a.header.Highlight("config") | 106 | a.headerSections.Highlight("config") |
107 | a.pages.SetBorder(true) | ||
115 | } | 108 | } |
116 | 109 | ||
117 | a.updateFooter() | 110 | a.updateFooter() |