more code restructuring
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
9a2b03fc96
commit
289c319ea9
17
gorilla.go
17
gorilla.go
|
@ -41,30 +41,29 @@ func gorillaReadProtobuf(conn *websocket.Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func gorillaSendProtobuf(msg *pb.Event) {
|
func websocketSendProtobuf(msg *pb.Event) {
|
||||||
log.Println("gorillaSendProtobuf() Event_Type =", msg.Type, "Event.Account.Nick =", msg.Account)
|
log.Println("websocketSendProtobuf() Event_Type =", msg.Type, "Event.Account.Nick =", msg.Account)
|
||||||
|
|
||||||
if (gorillaConn == nil) {
|
if (gorillaConn == nil) {
|
||||||
log.Println("gorillaSendProtobuf() CAN NOT SEND (socket connection isn't open)")
|
log.Println("websocketSendProtobuf() CAN NOT SEND (socket connection isn't open)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
test, err := proto.Marshal(msg)
|
test, err := proto.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("gorillaConn.WriteMessage() Marshal failed SERIOUS ERROR", err)
|
log.Println("websocketSendProtobuf() Marshal failed SERIOUS ERROR", err)
|
||||||
log.Println("gorillaConn.WriteMessage() Marshal failed SERIOUS ERROR", err)
|
log.Println("websocketSendProtobuf() Marshal failed SERIOUS ERROR", err)
|
||||||
log.Println("gorillaConn.WriteMessage() Marshal failed SERIOUS ERROR", err)
|
log.Println("websocketSendProtobuf() Marshal failed SERIOUS ERROR", err)
|
||||||
// TODO: return here?
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, test)
|
err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, test)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
log.Println("gorillaConn.WriteMessage() failed write:", err2)
|
log.Println("websocketSendProtobuf() WriteMessage() failed write:", err2)
|
||||||
gorillaConn = nil
|
gorillaConn = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println("gorillaSendProtobuf() END OK", time.Now())
|
log.Println("websocketSendProtobuf() END OK", time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
func closeGorillaConn() {
|
func closeGorillaConn() {
|
||||||
|
|
|
@ -61,7 +61,7 @@ func mainMouseClick(b *gui.GuiButton) {
|
||||||
event.Account = b.Account
|
event.Account = b.Account
|
||||||
log.Println("\tTRIGGERING CREATE event=", event)
|
log.Println("\tTRIGGERING CREATE event=", event)
|
||||||
log.Println("\tTRIGGERING CREATE event.Account=", event.Account)
|
log.Println("\tTRIGGERING CREATE event.Account=", event.Account)
|
||||||
prepareAndSend(event)
|
websocketSendProtobuf(event)
|
||||||
} else if (b.Action == "CONFIG") {
|
} else if (b.Action == "CONFIG") {
|
||||||
newConfig := loadDefaultConfig()
|
newConfig := loadDefaultConfig()
|
||||||
config.Accounts = newConfig.Accounts
|
config.Accounts = newConfig.Accounts
|
||||||
|
@ -89,7 +89,7 @@ func mainMouseClick(b *gui.GuiButton) {
|
||||||
|
|
||||||
event := pb.MakeGetEvent()
|
event := pb.MakeGetEvent()
|
||||||
event.Account = b.Account
|
event.Account = b.Account
|
||||||
prepareAndSend(event)
|
websocketSendProtobuf(event)
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
for {
|
for {
|
|
@ -61,6 +61,19 @@ func getNEWTEXT() *ui.AttributedString {
|
||||||
return aText
|
return aText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func splashClick(b *gui.GuiButton) {
|
||||||
|
gw := b.Box.Window
|
||||||
|
// if there is already an account, skip straight to the main screen
|
||||||
|
for key, _ := range config.Accounts {
|
||||||
|
log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Account = ", config.Accounts[key])
|
||||||
|
makeCloudInfoBox(gw)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// if there is not an account, then go to 'make account'
|
||||||
|
gw.MakeWindow = addSubdomainQuestionBox
|
||||||
|
gw = gui.ShowTab(gw, "Box2", "New Account?")
|
||||||
|
}
|
||||||
|
|
||||||
func addSubdomainQuestionBox(gw *gui.GuiWindow) *gui.GuiBox {
|
func addSubdomainQuestionBox(gw *gui.GuiWindow) *gui.GuiBox {
|
||||||
log.Println("addSubdomainQuestionBox() START")
|
log.Println("addSubdomainQuestionBox() START")
|
||||||
box := gui.AddGenericBox(gw)
|
box := gui.AddGenericBox(gw)
|
7
login.go
7
login.go
|
@ -9,14 +9,19 @@ import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
|
// This sends a login protocol buffer and waits for a response
|
||||||
|
|
||||||
func login(b *gui.GuiButton) {
|
func login(b *gui.GuiButton) {
|
||||||
log.Println("login() START")
|
log.Println("login() START")
|
||||||
gui.Data.State = "SEND LOGIN"
|
gui.Data.State = "SEND LOGIN"
|
||||||
|
|
||||||
// TODO: move this into a seperate goroutine
|
// TODO: move this into a seperate goroutine
|
||||||
|
// note: this may never be possible because of cross platform
|
||||||
|
// andlabs/ui requirements. windows and macos seem to freak out
|
||||||
|
// when you try to trigger the UI in seperate threads
|
||||||
event := pb.MakeLoginEvent()
|
event := pb.MakeLoginEvent()
|
||||||
event.Account = b.Account
|
event.Account = b.Account
|
||||||
prepareAndSend(event)
|
websocketSendProtobuf(event)
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
for {
|
for {
|
||||||
|
|
78
main.go
78
main.go
|
@ -4,13 +4,13 @@ import "log"
|
||||||
import "os"
|
import "os"
|
||||||
import "time"
|
import "time"
|
||||||
import "os/user"
|
import "os/user"
|
||||||
import "reflect"
|
// import "reflect"
|
||||||
|
|
||||||
// this is the king of dns libraries
|
// this is the king of dns libraries
|
||||||
import "github.com/miekg/dns"
|
import "github.com/miekg/dns"
|
||||||
|
|
||||||
import "git.wit.com/wit/gui"
|
import "git.wit.com/wit/gui"
|
||||||
import pb "git.wit.com/wit/witProtobuf"
|
// import pb "git.wit.com/wit/witProtobuf"
|
||||||
import "git.wit.com/jcarr/dnssecsocket"
|
import "git.wit.com/jcarr/dnssecsocket"
|
||||||
|
|
||||||
import "github.com/gobuffalo/packr"
|
import "github.com/gobuffalo/packr"
|
||||||
|
@ -154,77 +154,3 @@ func r() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareAndSend(event *pb.Event) {
|
|
||||||
if (event.Account == nil) {
|
|
||||||
log.Println("\tmain.prepareAndSend() ERROR event.Token = nil")
|
|
||||||
log.Println("\tmain.prepareAndSend() ERROR event.Token = nil")
|
|
||||||
log.Println("\tmain.prepareAndSend() ERROR event.Token = nil")
|
|
||||||
} else {
|
|
||||||
s := event.Account.Token
|
|
||||||
log.Println("\tmain.prepareAndSend() event.Token =", s) // s[len(s)-24:]) // this can panic because strings.() is stupid
|
|
||||||
}
|
|
||||||
gorillaSendProtobuf(event)
|
|
||||||
gui.Data.State = "READ PROTOBUF"
|
|
||||||
}
|
|
||||||
|
|
||||||
func splashClick(b *gui.GuiButton) {
|
|
||||||
gw := b.Box.Window
|
|
||||||
// if there is already an account, skip straight to the main screen
|
|
||||||
for key, _ := range config.Accounts {
|
|
||||||
log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Account = ", config.Accounts[key])
|
|
||||||
makeCloudInfoBox(gw)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// if there is not an account, then go to 'make account'
|
|
||||||
gw.MakeWindow = addSubdomainQuestionBox
|
|
||||||
gw = gui.ShowTab(gw, "Box2", "New Account?")
|
|
||||||
}
|
|
||||||
|
|
||||||
// this watches the GUI primarily to process protobuf's
|
|
||||||
// maybe this is pointless or wrong
|
|
||||||
func watchGUI() {
|
|
||||||
count := 0
|
|
||||||
|
|
||||||
for {
|
|
||||||
if (count > 10) {
|
|
||||||
log.Println("Sleep() in watchGUI() gui.Data.State =", gui.Data.State)
|
|
||||||
for i, window := range gui.Data.Windows {
|
|
||||||
log.Println("watchGUI() gui.Data.Windows i =", i, "Action =", window.Action)
|
|
||||||
for name, abox := range window.BoxMap {
|
|
||||||
log.Println("\twatchGUI() BOX name =", name)
|
|
||||||
if (name == "SplashArea3") {
|
|
||||||
log.Println("\twatchGUI() BOX abox =", reflect.TypeOf(abox))
|
|
||||||
win := abox.Window
|
|
||||||
log.Println("\twatchGUI() BOX win =", reflect.TypeOf(win))
|
|
||||||
area := win.Area
|
|
||||||
log.Println("\twatchGUI() BOX area =", reflect.TypeOf(area))
|
|
||||||
spew.Dump(area.UiArea)
|
|
||||||
area.UiArea.Show()
|
|
||||||
time.Sleep(20000 * time.Millisecond)
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0
|
|
||||||
}
|
|
||||||
count += 1
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
|
||||||
|
|
||||||
if (gui.Data.State == "kill") {
|
|
||||||
log.Println("gui.State = kill")
|
|
||||||
log.Println("gui.State = kill")
|
|
||||||
log.Println("gui.State = kill")
|
|
||||||
onExit(nil)
|
|
||||||
} else if (gui.Data.State == "HIDE") {
|
|
||||||
time.Sleep(20 * time.Millisecond) // maybe required for macos & windows refresh to work?
|
|
||||||
// gui.Data.Windows[0].Box1.Show()
|
|
||||||
// gui.Data.Windows[0].Box2.Show()
|
|
||||||
for key, element := range gui.Data.Windows {
|
|
||||||
log.Println("watchGUI() gui.Data.Windows =", key, element.Action)
|
|
||||||
element.UiTab.Show()
|
|
||||||
}
|
|
||||||
gui.Data.State = "done"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue