diff --git a/debug.go b/debug.go new file mode 100644 index 0000000..ee4f7eb --- /dev/null +++ b/debug.go @@ -0,0 +1,88 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +// An app to submit patches for the 30 GO GUI repos + +import ( + "fmt" + "time" + + "go.wit.com/gui" + "go.wit.com/lib/debugger" + "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func init() { + if debugger.ArgDebug() { + log.Info("cmd line --debugger == true") + go func() { + log.Sleep(2) + debugger.DebugWindow() + }() + } +} + +func debug() { + defer func() { + if r := recover(); r != nil { + gui.Crash(r, "forge debug()") + } + }() + time.Sleep(2 * time.Second) + for { + now := time.Now() + + if me.repoAllB != nil { + tmp := fmt.Sprintf("All (%d)", me.forge.Repos.Len()) + me.repoAllB.SetLabel(tmp) + } + + if me.repoDevelMergeB != nil { + found := findMergeToDevel() + tmp := fmt.Sprintf("needs merge to devel (%d)", found.Len()) + me.repoDevelMergeB.SetLabel(tmp) + } + + if me.repoWritableB != nil { + found := gitpb.NewRepos() + for repo := range me.forge.Repos.IterByFullPath() { + if me.forge.Config.IsReadOnly(repo.GetGoPath()) { + continue + } + + found.AppendByFullPath(repo) + + } + tmp := fmt.Sprintf("writable (%d)", found.Len()) + me.repoWritableB.SetLabel(tmp) + } + + dirty := me.forge.CheckDirty() + + if me.repoDirtyB != nil { + tmp := fmt.Sprintf("dirty (%d)", dirty.Len()) + me.repoDirtyB.SetLabel(tmp) + } + + if me.reposWinB != nil { + tmp := fmt.Sprintf("Repos (%d)", me.forge.Repos.Len()) + if dirty.Len() > 0 { + tmp = fmt.Sprintf("Repos (%d) (%d dirty)", me.forge.Repos.Len(), dirty.Len()) + } + me.reposWinB.SetLabel(tmp) + } + + // check for new patches + log.Info("should check for packages here") + // if err := me.forge.ListPatches(); err != nil { + // log.Info("List Patchsets Failed", err) + // } + + log.Printf("finished a forge scan here in (%s)\n", shell.FormatDuration(time.Since(now))) + time.Sleep(90 * time.Second) + } +} diff --git a/doGui.go b/doGui.go index 39bd657..a55a6c4 100644 --- a/doGui.go +++ b/doGui.go @@ -11,7 +11,6 @@ import ( "time" "go.wit.com/gui" - "go.wit.com/lib/fhelp" "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" @@ -19,100 +18,13 @@ import ( "go.wit.com/log" ) -func debug() { - defer func() { - if r := recover(); r != nil { - gui.Crash(r, "forge debug()") - } - }() - time.Sleep(2 * time.Second) - for { - now := time.Now() - - if me.repoAllB != nil { - tmp := fmt.Sprintf("All (%d)", me.forge.Repos.Len()) - me.repoAllB.SetLabel(tmp) - } - - if me.repoDevelMergeB != nil { - found := findMergeToDevel() - tmp := fmt.Sprintf("needs merge to devel (%d)", found.Len()) - me.repoDevelMergeB.SetLabel(tmp) - } - - if me.repoWritableB != nil { - found := gitpb.NewRepos() - for repo := range me.forge.Repos.IterByFullPath() { - if me.forge.Config.IsReadOnly(repo.GetGoPath()) { - continue - } - - found.AppendByFullPath(repo) - - } - tmp := fmt.Sprintf("writable (%d)", found.Len()) - me.repoWritableB.SetLabel(tmp) - } - - dirty := me.forge.CheckDirty() - - if me.repoDirtyB != nil { - tmp := fmt.Sprintf("dirty (%d)", dirty.Len()) - me.repoDirtyB.SetLabel(tmp) - } - - if me.reposWinB != nil { - tmp := fmt.Sprintf("Repos (%d)", me.forge.Repos.Len()) - if dirty.Len() > 0 { - tmp = fmt.Sprintf("Repos (%d) (%d dirty)", me.forge.Repos.Len(), dirty.Len()) - } - me.reposWinB.SetLabel(tmp) - } - - // check for new patches - log.Info("should check for packages here") - // if err := me.forge.ListPatches(); err != nil { - // log.Info("List Patchsets Failed", err) - // } - - log.Printf("finished a forge scan here in (%s)\n", shell.FormatDuration(time.Since(now))) - time.Sleep(90 * time.Second) - } -} - func doGui() { - if me.forge.Config.GetDefaultGui() == "" { - me.forge.Config.DefaultGui = "gocui" - me.forge.ConfigSave() - } - me.myGui = gui.New() - me.myGui.InitEmbed(resources) - me.myGui.SetAppDefaultPlugin(me.forge.Config.DefaultGui) // sets the default GUI plugin to use - if pname, err := me.myGui.Default(); err != nil { - if !fhelp.BuildPlugin("gocui") { - log.Info("You can't run the forge GUI since the plugins did not build", pname) - okExit("") - } else { - if err := me.myGui.LoadToolkitNew("gocui"); err != nil { - log.Info("The plugins built, but still failed to load", pname) - badExit(err) - } - log.Info("The plugins built and loaded!", pname) - } - } - - mainWindow := gadgets.NewGenericWindow("Forge: A federated git development tool by WIT.COM", "Current Settings") - mainWindow.Custom = func() { + win := gadgets.NewGenericWindow("Forge: A federated git development tool by WIT.COM", "Current Settings") + win.Custom = func() { log.Warn("MAIN WINDOW CLOSE") okExit("") } - drawWindow(mainWindow) - // sits here forever - debug() -} - -func drawWindow(win *gadgets.GenericWindow) { grid := win.Group.RawGrid() if me.forge.Config.GetPathLock() { me.goSrcPwd = gadgets.NewOneLiner(grid, "Working Directory") diff --git a/main.go b/main.go index df41311..8074c38 100644 --- a/main.go +++ b/main.go @@ -249,7 +249,13 @@ func main() { if argv.Gui != nil { // if opening the GUI, always check git for dirty repos me.forge.CheckDirty() - doGui() + + me.myGui.Start() // loads the GUI toolkit + + doGui() // start making our forge GUI + + // sits here forever + debug() } // got to the end with nothing to do (?) if dumpWorkRepos() { diff --git a/structs.go b/structs.go index 6a25fc1..15f04ea 100644 --- a/structs.go +++ b/structs.go @@ -7,6 +7,7 @@ import ( "go.wit.com/dev/alexflint/arg" "go.wit.com/gui" "go.wit.com/lib/gadgets" + "go.wit.com/lib/gui/prep" "go.wit.com/lib/protobuf/forgepb" ) @@ -29,7 +30,7 @@ func myServer() string { type mainType struct { pp *arg.Parser // for parsing the command line args. Yay to alexf lint! forge *forgepb.Forge // for holding the forge protobuf files - myGui *gui.Node // the gui toolkit handle + myGui *prep.GuiPrep // for initializing the GUI toolkits foundPaths []string // stores gopaths to act on (when doing go-clone) configSave bool // if the config file should be saved after finishing urlbase string // base URL