From 3f5ff714caf59db65549bbe98f7c85d67f516e4b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 25 May 2019 01:38:06 -0700 Subject: [PATCH] refix the add account option Signed-off-by: Jeff Carr --- config.go | 7 +++++++ main.go | 22 ++++++++++++++++------ test2/config.go | 36 ++++-------------------------------- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/config.go b/config.go index 5eda4bf..176ba59 100644 --- a/config.go +++ b/config.go @@ -212,6 +212,13 @@ func loadConfigFromFilename(filename string) pb.Config { b, err := ioutil.ReadFile(filename) if err != nil { log.Println("ioutil.ReadFile() ERROR =", err) + // This probably means this is the first time the user is opening this + sets.Errors += 1 + sets.Crash = "err" + sets.Counter = 1 + sets.Width = 500 + sets.Height = 500 + return sets } log.Println("ioutil.ReadFile() b =", b) diff --git a/main.go b/main.go index 6154d82..34290bc 100644 --- a/main.go +++ b/main.go @@ -175,13 +175,23 @@ func mainMouseClick(b *gui.ButtonMap) { log.Println("FINISHED FULL STACK DUMP") } else if (b.Action == "ADD") { log.Println("\tSHOULD ADD ACCOUNT HERE") -/* - if (gui.Data.AccNick != "") { - config.Set("accounts." + gui.Data.AccNick + ".username", gui.Data.AccUser) - config.Set("accounts." + gui.Data.AccNick + ".password", gui.Data.AccPass) - config.Set("accounts." + gui.Data.AccNick + ".hostname", "v000185.testing.com.customers.wprod.wit.com") + if (gui.Data.CurrentTab != nil) { + if (gui.Data.CurrentTab.EntryNick != nil) { + nick := gui.Data.CurrentTab.EntryNick.Text() + username := gui.Data.CurrentTab.EntryUser.Text() + password := gui.Data.CurrentTab.EntryPass.Text() + log.Println("\tEntryNick =", nick) + log.Println("\tEntryName =", username) + log.Println("\tEntryPass =", password) + + acc := new(pb.Config_Account) + acc.Nick = nick + acc.Username = username + acc.Password = password + + config.Accounts = append(config.Accounts, acc) + } } -*/ } else if (b.Action == "LOGIN") { log.Println("\tTRIGGER LOGIN ACCOUNT") gui.Data.State = "SEND LOGIN" diff --git a/test2/config.go b/test2/config.go index 6718bea..c4d48a8 100644 --- a/test2/config.go +++ b/test2/config.go @@ -19,15 +19,10 @@ import pb "git.wit.com/wit/witProtobuf" import "github.com/davecgh/go-spew/spew" -// will load the default config from within the go binary +// TEST UNMARSHAL JSON TO PROTOBUF +// This is known to crash unless done exactly like this +// with strings.NewReader & 'sets' func loadDefaultConfig(a string) pb.Config { - log.Println("TRY TO LOAD DEFAULT CONFIG") - log.Println("a =", a) - log.Println("NEED TO UNMARSHAL THIS HERE") - log.Println("NEED TO UNMARSHAL THIS HERE") - log.Println("NEED TO UNMARSHAL THIS HERE") - var newpb *pb.Config - // var newpb *pb.Config sets := pb.Config{} b, err := ioutil.ReadFile("../resources/protobuf-config.json") @@ -42,31 +37,8 @@ func loadDefaultConfig(a string) pb.Config { } spew.Dump(sets) return sets -// -// err := jsonpb.UnmarshalString(defaultConfig, newpb) - log.Println("ATTEMTED TO UNMARSHAL err =", err) - spew.Dump(newpb) - if (err == nil) { - log.Println("SETTING config to the default config", err) - // TODO: save the protobuf somewhere as the user could loose the tokens - log.Println("THIS IS PROBABLY REALLY BAD", err) - log.Println("THIS IS PROBABLY REALLY BAD", err) - log.Println("THIS IS PROBABLY REALLY BAD", err) - // config = newpb - } - return sets -} - -func unmarshalConfig(a string) *pb.Event { - var newpb *pb.Event - log.Println("ATTEMTED TO UNMARSHAL string =", a) - err := jsonpb.UnmarshalString(a, newpb) - log.Println("ATTEMTED TO UNMARSHAL err =", err) - spew.Dump(newpb) - return newpb } func main() { - blah := "{}" - loadDefaultConfig(blah) + loadDefaultConfig("") }