Removing Globals

Globals are no longer needed instead I am connecting each part with (
what were previously ) globals. Also Renaming SetRenderer to
ConnectRenderer which describes the name more precisely
This commit is contained in:
aditya-K2 2021-12-23 20:20:27 +05:30
parent b587f5acfd
commit f56eb1cf1f
2 changed files with 16 additions and 25 deletions

36
main.go
View File

@ -1,10 +1,11 @@
package main
import (
"github.com/aditya-K2/gomp/ui/notify"
"strconv"
"time"
"github.com/aditya-K2/gomp/ui/notify"
"github.com/aditya-K2/gomp/render"
"github.com/aditya-K2/gomp/ui"
@ -19,22 +20,11 @@ import (
"github.com/spf13/viper"
)
var (
CONN *mpd.Client
UI *ui.Application
Notify *notify.NotificationServer
RENDERER *render.Renderer
Volume int64
Random bool
Repeat bool
ArtistTree map[string]map[string]map[string]string
)
func main() {
config.ReadConfig()
// Connect to MPD server
var mpdConnectionError error
CONN, mpdConnectionError = mpd.Dial("tcp", "localhost:"+viper.GetString("MPD_PORT"))
CONN, mpdConnectionError := mpd.Dial("tcp", "localhost:"+viper.GetString("MPD_PORT"))
if mpdConnectionError != nil {
panic(mpdConnectionError)
}
@ -47,16 +37,16 @@ func main() {
render.SetConnection(CONN)
cache.SetCacheDir(viper.GetString("CACHE_DIR"))
RENDERER = render.NewRenderer()
ui.SetRenderer(RENDERER)
Renderer := render.NewRenderer()
ui.ConnectRenderer(Renderer)
c, _ := CONN.CurrentSong()
if len(c) != 0 {
RENDERER.Start(c["file"])
Renderer.Start(c["file"])
} else {
RENDERER.Start("stop")
Renderer.Start("stop")
}
UI = ui.NewApplication()
UI := ui.NewApplication()
notify.ConnectUI(UI)
fileMap, err := CONN.GetFiles()
@ -65,13 +55,13 @@ func main() {
client.UpdatePlaylist(UI.ExpandedView)
_v, _ := CONN.Status()
Volume, _ = strconv.ParseInt(_v["volume"], 10, 64)
Random, _ = strconv.ParseBool(_v["random"])
Repeat, _ = strconv.ParseBool(_v["repeat"])
Volume, _ := strconv.ParseInt(_v["volume"], 10, 64)
Random, _ := strconv.ParseBool(_v["random"])
Repeat, _ := strconv.ParseBool(_v["repeat"])
ArtistTree, err = client.GenerateArtistTree()
ArtistTree, err := client.GenerateArtistTree()
ArtistTreeContent := utils.ConvertToArray(ArtistTree)
Notify = notify.NewNotificationServer()
Notify := notify.NewNotificationServer()
Notify.Start()
client.SetNotificationServer(Notify)
render.SetNotificationServer(Notify)

View File

@ -2,9 +2,10 @@ package ui
import (
"fmt"
"github.com/fhs/gompd/mpd"
"strconv"
"github.com/fhs/gompd/mpd"
"github.com/aditya-K2/gomp/utils"
"github.com/aditya-K2/tview"
@ -21,7 +22,7 @@ func SetConnection(c *mpd.Client) {
CONN = c
}
func SetRenderer(r interface{ Send(string) }) {
func ConnectRenderer(r interface{ Send(string) }) {
RENDERER = r
}