2019-02-01 07:28:17 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "log"
|
2019-05-06 20:57:59 -05:00
|
|
|
import "os"
|
2019-05-06 19:42:59 -05:00
|
|
|
import "time"
|
2019-05-10 03:27:28 -05:00
|
|
|
// import "fmt"
|
2019-02-01 07:28:17 -06:00
|
|
|
|
|
|
|
import "github.com/gookit/config"
|
|
|
|
|
2019-05-13 01:02:10 -05:00
|
|
|
import "git.wit.com/wit/gui"
|
2019-05-08 15:09:44 -05:00
|
|
|
|
2019-05-23 02:11:49 -05:00
|
|
|
var GITCOMMIT string // this is passed in as an ldflag
|
|
|
|
var GOVERSION string // this is passed in as an ldflag
|
|
|
|
|
2019-05-07 07:02:39 -05:00
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
2019-02-01 07:28:17 -06:00
|
|
|
|
|
|
|
// reminder to use this for JSON
|
|
|
|
// https://github.com/tidwall/gjson
|
|
|
|
// value := gjson.Get(json, "name.last")
|
|
|
|
// println(value.String())
|
|
|
|
// value := gjson.Get(json, friends.#[last=="Murphy"].first)
|
|
|
|
|
|
|
|
// use mergo to merge structs
|
|
|
|
// import "github.com/imdario/mergo"
|
|
|
|
// mergo.Merge(&dest, src)
|
|
|
|
|
|
|
|
// always sorted slice (new project)
|
|
|
|
// https://github.com/yaa110/sslice
|
|
|
|
|
2019-05-12 08:18:06 -05:00
|
|
|
// several smart slice functions (new project. April 2019)
|
|
|
|
// https://github.com/elliotchance/pie
|
|
|
|
|
2019-05-12 01:21:57 -05:00
|
|
|
// Exit and write out the config
|
|
|
|
// (in yaml and json I guess.)
|
|
|
|
// switch to json once it can be made human readable
|
|
|
|
func onExit() {
|
|
|
|
log.Println("Sleep for 1 second")
|
|
|
|
time.Sleep(1 * 1000 * 1000 * 1000)
|
|
|
|
|
|
|
|
f, err := os.Create("/tmp/cloud-control-panel.yaml")
|
|
|
|
if err == nil {
|
|
|
|
config.DumpTo(f, "yaml")
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err = os.Create("/tmp/cloud-control-panel.json")
|
|
|
|
if err == nil {
|
|
|
|
config.DumpTo(f, "json")
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2019-05-10 03:21:32 -05:00
|
|
|
func main() {
|
|
|
|
parseConfig()
|
2019-05-08 17:29:06 -05:00
|
|
|
|
2019-05-10 03:21:32 -05:00
|
|
|
// only test the socket code if no GUI
|
|
|
|
if (config.String("nogui") == "true") {
|
2019-05-12 20:36:31 -05:00
|
|
|
log.Println("Need to re-implement this")
|
2019-05-10 03:21:32 -05:00
|
|
|
onExit()
|
|
|
|
}
|
2019-05-08 16:03:10 -05:00
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
initChannel()
|
|
|
|
go processEvents()
|
|
|
|
|
2019-05-12 08:18:06 -05:00
|
|
|
go gorillaDial("v000185.testing.com.customers.wprod.wit.com:9000")
|
2019-05-23 00:33:16 -05:00
|
|
|
go watchGUI()
|
2019-05-07 16:54:08 -05:00
|
|
|
|
2019-05-23 02:11:49 -05:00
|
|
|
gui.Data.Width = config.Int("width")
|
|
|
|
gui.Data.Height = config.Int("height")
|
|
|
|
gui.Data.Version = "v0.4 "
|
|
|
|
gui.Data.GitCommit = GITCOMMIT
|
|
|
|
gui.Data.GoVersion = GOVERSION
|
2019-05-23 00:33:16 -05:00
|
|
|
gui.Data.ButtonClickNew = buttonClickNew
|
|
|
|
|
2019-05-10 03:21:32 -05:00
|
|
|
// make this the main loop in an attempt to figure out the crashes
|
|
|
|
// do not change this until the GUI is stable
|
2019-05-23 00:33:16 -05:00
|
|
|
gui.GoMainWindow()
|
|
|
|
}
|
2019-05-10 03:21:32 -05:00
|
|
|
|
2019-05-23 00:33:16 -05:00
|
|
|
func buttonClickNew(b *gui.ButtonMap) {
|
|
|
|
log.Println("buttonClickNew() b =", b)
|
|
|
|
log.Println("\tb.Name", b.Name)
|
|
|
|
log.Println("\tb.Note", b.Note)
|
2019-05-09 08:52:51 -05:00
|
|
|
|
2019-05-23 00:33:16 -05:00
|
|
|
if (b.Note == "BACK") {
|
|
|
|
gui.Data.State = "splash"
|
|
|
|
}
|
|
|
|
if (b.Note == "BMATH") {
|
|
|
|
log.Println("\tTRIGGER BMATH HERE")
|
|
|
|
log.Println("\tTRIGGER BMATH HERE")
|
|
|
|
log.Println("\tTRIGGER BMATH HERE")
|
|
|
|
gui.Data.State = "bmath"
|
|
|
|
for {
|
|
|
|
log.Println("Sleep() in buttonClickNew() gui.Data.State =", gui.Data.State)
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
if (gui.Data.State == "bmath done") {
|
|
|
|
count := countVMS(currentMessage)
|
|
|
|
mh := gui.AddVmsTab(count)
|
|
|
|
ReadReceivedData(currentMessage, mh)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gui.Data.State == "splash") {
|
|
|
|
gui.ShowAccountQuestionTab()
|
|
|
|
gui.Data.State = "account1"
|
|
|
|
return
|
|
|
|
} else if (gui.Data.State == "account1") {
|
|
|
|
gui.ShowAccountTab()
|
|
|
|
gui.Data.State = "main"
|
|
|
|
} else if (gui.Data.State == "main") {
|
|
|
|
gui.ShowMainTab()
|
|
|
|
gui.Data.State = "done"
|
|
|
|
}
|
|
|
|
}
|
2019-05-09 08:52:51 -05:00
|
|
|
|
2019-05-23 00:33:16 -05:00
|
|
|
func watchGUI() {
|
|
|
|
log.Println("Sleep(2000)")
|
|
|
|
time.Sleep(2000 * time.Millisecond)
|
|
|
|
|
|
|
|
for {
|
|
|
|
log.Println("Sleep() in watchGUI() gui.Data.State =", gui.Data.State)
|
|
|
|
time.Sleep(2000 * time.Millisecond)
|
|
|
|
|
|
|
|
if (gui.Data.State == "bmath") {
|
|
|
|
log.Println("\tTRIGGERING BMATH HERE")
|
|
|
|
log.Println("\tTRIGGERING BMATH HERE")
|
|
|
|
log.Println("\tTRIGGERING BMATH HERE")
|
|
|
|
gorillaSendProtobuf()
|
|
|
|
}
|
|
|
|
if (gui.Data.State == "kill") {
|
|
|
|
log.Println("gui.State = kill")
|
|
|
|
log.Println("gui.State = kill")
|
|
|
|
log.Println("gui.State = kill")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2019-05-07 16:54:08 -05:00
|
|
|
}
|
2019-05-07 07:02:39 -05:00
|
|
|
}
|