aboutsummaryrefslogtreecommitdiff
path: root/src/page_config.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/page_config.go')
-rw-r--r--src/page_config.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/page_config.go b/src/page_config.go
new file mode 100644
index 0000000..bb8afca
--- /dev/null
+++ b/src/page_config.go
@@ -0,0 +1,51 @@
1package src
2
3import (
4 "net/http"
5
6 "github.com/delucks/go-subsonic"
7 "github.com/rivo/tview"
8)
9
10func configPage(a *app) *tview.Form {
11 form := tview.NewForm().
12 AddInputField("Server URL", a.cfg.BaseURL, 40, nil, func(txt string) { a.cfg.BaseURL = txt }).
13 AddInputField("Username", a.cfg.Username, 20, nil, func(txt string) { a.cfg.Username = txt }).
14 AddPasswordField("Password", a.cfg.Password, 20, '*', func(txt string) { a.cfg.Password = txt }).
15 AddButton("Test", func() {
16 tmpSub := &subsonic.Client{
17 Client: http.DefaultClient,
18 BaseUrl: a.cfg.BaseURL,
19 User: a.cfg.Username,
20 ClientName: "termsonic",
21 PasswordAuth: true,
22 }
23
24 if err := tmpSub.Authenticate(a.cfg.Password); err != nil {
25 alert(a, "Could not auth: %v", err)
26 } else {
27 alert(a, "Success.")
28 }
29 }).
30 AddButton("Save", func() {
31 err := a.cfg.Save()
32 if err != nil {
33 alert(a, "Error saving: %v", err)
34 return
35 }
36
37 a.sub = &subsonic.Client{
38 Client: http.DefaultClient,
39 BaseUrl: a.cfg.BaseURL,
40 User: a.cfg.Username,
41 ClientName: "termsonic",
42 PasswordAuth: true,
43 }
44 if err := a.sub.Authenticate(a.cfg.Password); err != nil {
45 alert(a, "Could not auth: %v", err)
46 } else {
47 alert(a, "All good!")
48 }
49 })
50 return form
51}