-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
77 lines (59 loc) · 1.84 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"os"
"time"
"github.com/aditya-K2/gomp/cache"
"github.com/aditya-K2/gomp/client"
"github.com/aditya-K2/gomp/config"
"github.com/aditya-K2/gomp/ui"
"github.com/aditya-K2/gomp/watchers"
"github.com/aditya-K2/utils"
"github.com/fhs/gompd/v2/mpd"
)
func main() {
config.ParseFlags()
config.ReadConfig()
var mcerr error
client.Conn, mcerr = mpd.Dial(
utils.GetNetwork(config.Config.NetworkType,
config.Config.Port,
config.Config.NetworkAddress))
if mcerr != nil {
utils.Print("RED", "There was a Problem Connecting to the MPD Server\nTry Checking:\n")
utils.Print("GREEN", "- if MPD Server is up and running.\n")
utils.Print("GREEN", "- if you have provided correct port in the config.yml\n")
os.Exit(-1)
}
Conn := client.Conn
defer Conn.Close()
cache.SetCacheDir(config.Config.CacheDir)
watchers.Init()
ui.Ui = ui.NewApplication()
ui.Ui.ProgressBar.SetProgressFunc(watchers.ProgressFunction)
// Generating the Directory Tree for File Navigation.
if fileMap, err := Conn.ListAllInfo("/"); err != nil {
utils.Print("RED", "Could Not Generate the File Map\n")
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
panic(err)
} else {
client.DirTree = client.GenerateDirectoryTree(fileMap)
}
client.GetContent()
ui.InitNotifier()
watchers.StartPlaylistWatcher()
watchers.StartRectWatcher()
ui.SetCurrentView(&ui.PView)
// Generating the Key Map Based on the Function Map Here Basically the Values will be flipped
// In the config if togglePlayBack is mapped to [ T , P, SPACE ] then here Basically we will receive a map
// for each event T, P, SPACE mapped to the same function togglePlayBack
config.GenerateKeyMap(ui.FuncMap)
go func() {
for {
ui.Ui.App.Draw()
time.Sleep(time.Second)
}
}()
if err := ui.Ui.App.Run(); err != nil {
panic(err)
}
}