diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/main.go b/main.go deleted file mode 100644 index ad0d7c8..0000000 --- a/main.go +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "net/http" | ||
6 | "os" | ||
7 | |||
8 | "github.com/delucks/go-subsonic" | ||
9 | "github.com/rivo/tview" | ||
10 | ) | ||
11 | |||
12 | var ( | ||
13 | url = "" | ||
14 | username = "" | ||
15 | password = "" | ||
16 | |||
17 | sub *subsonic.Client = nil | ||
18 | |||
19 | // GUI | ||
20 | app *tview.Application | ||
21 | pages *tview.Pages | ||
22 | ) | ||
23 | |||
24 | func main() { | ||
25 | loadConfig() | ||
26 | |||
27 | app = tview.NewApplication() | ||
28 | |||
29 | pages = tview.NewPages() | ||
30 | |||
31 | showConfig := sub == nil | ||
32 | pages.AddPage("page-config", configPage(), true, showConfig) | ||
33 | |||
34 | if !showConfig { | ||
35 | pages.AddPage("page-main", mainView(), true, true) | ||
36 | } | ||
37 | |||
38 | if err := app.SetRoot(pages, true).EnableMouse(true).SetFocus(pages).Run(); err != nil { | ||
39 | fmt.Printf("Error running TermSonic: %v", err) | ||
40 | os.Exit(1) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | func configPage() *tview.Form { | ||
45 | form := tview.NewForm(). | ||
46 | AddInputField("Server URL", url, 40, nil, func(txt string) { url = txt }). | ||
47 | AddInputField("Username", username, 20, nil, func(txt string) { username = txt }). | ||
48 | AddPasswordField("Password", password, 20, '*', func(txt string) { password = txt }). | ||
49 | AddButton("Test", func() { | ||
50 | tmpSub := &subsonic.Client{ | ||
51 | Client: http.DefaultClient, | ||
52 | BaseUrl: url, | ||
53 | User: username, | ||
54 | ClientName: "termsonic", | ||
55 | PasswordAuth: true, | ||
56 | } | ||
57 | |||
58 | if err := tmpSub.Authenticate(password); err != nil { | ||
59 | alert("Could not auth: %v", err) | ||
60 | } else { | ||
61 | sub = tmpSub | ||
62 | |||
63 | alert("Success.") | ||
64 | } | ||
65 | }). | ||
66 | AddButton("Save", nil) | ||
67 | return form | ||
68 | } | ||
69 | |||
70 | func mainView() *tview.Grid { | ||
71 | grid := tview.NewGrid(). | ||
72 | SetRows(2, 0). | ||
73 | SetColumns(30, 0). | ||
74 | SetBorders(true) | ||
75 | |||
76 | grid.AddItem(tview.NewTextView().SetText("Artist & Album list"), 1, 0, 1, 1, 0, 0, true) | ||
77 | grid.AddItem(tview.NewTextView().SetText("Song list!"), 1, 1, 1, 2, 0, 0, false) | ||
78 | |||
79 | return grid | ||
80 | } | ||
81 | |||
82 | func alert(format string, params ...interface{}) { | ||
83 | modal := tview.NewModal(). | ||
84 | SetText(fmt.Sprintf(format, params...)). | ||
85 | AddButtons([]string{"OK"}). | ||
86 | SetDoneFunc(func(_ int, _ string) { | ||
87 | pages.RemovePage("alert") | ||
88 | }) | ||
89 | |||
90 | pages.AddPage("alert", modal, true, true) | ||
91 | } | ||
92 | |||
93 | func loadConfig() { | ||
94 | url = "http://music.nuc.local" | ||
95 | username = "admin" | ||
96 | password = "admin" | ||
97 | |||
98 | sub = &subsonic.Client{ | ||
99 | Client: http.DefaultClient, | ||
100 | User: username, | ||
101 | BaseUrl: url, | ||
102 | ClientName: "termsonic", | ||
103 | PasswordAuth: true, | ||
104 | } | ||
105 | |||
106 | if err := sub.Authenticate(password); err != nil { | ||
107 | sub = nil | ||
108 | } | ||
109 | } | ||
110 | |||
111 | func saveConfig() { | ||
112 | } | ||