common gui code

This commit is contained in:
Jeff Carr 2025-09-09 04:37:50 -05:00
parent c0ec2f359a
commit 860290fc26
4 changed files with 99 additions and 92 deletions

88
debug.go Normal file
View File

@ -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)
}
}

View File

@ -11,7 +11,6 @@ import (
"time" "time"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
@ -19,100 +18,13 @@ import (
"go.wit.com/log" "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() { func doGui() {
if me.forge.Config.GetDefaultGui() == "" { win := gadgets.NewGenericWindow("Forge: A federated git development tool by WIT.COM", "Current Settings")
me.forge.Config.DefaultGui = "gocui" win.Custom = func() {
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() {
log.Warn("MAIN WINDOW CLOSE") log.Warn("MAIN WINDOW CLOSE")
okExit("") okExit("")
} }
drawWindow(mainWindow)
// sits here forever
debug()
}
func drawWindow(win *gadgets.GenericWindow) {
grid := win.Group.RawGrid() grid := win.Group.RawGrid()
if me.forge.Config.GetPathLock() { if me.forge.Config.GetPathLock() {
me.goSrcPwd = gadgets.NewOneLiner(grid, "Working Directory") me.goSrcPwd = gadgets.NewOneLiner(grid, "Working Directory")

View File

@ -249,7 +249,13 @@ func main() {
if argv.Gui != nil { if argv.Gui != nil {
// if opening the GUI, always check git for dirty repos // if opening the GUI, always check git for dirty repos
me.forge.CheckDirty() 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 (?) // got to the end with nothing to do (?)
if dumpWorkRepos() { if dumpWorkRepos() {

View File

@ -7,6 +7,7 @@ import (
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
) )
@ -29,7 +30,7 @@ func myServer() string {
type mainType struct { type mainType struct {
pp *arg.Parser // for parsing the command line args. Yay to alexf lint! pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
forge *forgepb.Forge // for holding the forge protobuf files 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) foundPaths []string // stores gopaths to act on (when doing go-clone)
configSave bool // if the config file should be saved after finishing configSave bool // if the config file should be saved after finishing
urlbase string // base URL urlbase string // base URL