// 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" "os" "strings" "time" "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/virtpb" "go.wit.com/log" ) func debug() { for { time.Sleep(10 * time.Second) log.Info("TODO: use this debug loop for something?") } } // adds a new drive to the dropdown menu and protobuf func addDrive(devname string, displayDesc string) *Block { if blkpb := me.pb.FindByName(devname); blkpb != nil { return blkpb } s := log.Sprintf("%-12s %-8s", devname, displayDesc) log.Info(s) me.dd.AddText(s) blkpb := me.pb.InsertByName(devname) return blkpb } func switchDrive(blk *Block) { me.currentDev = blk me.parted.SetText("Partition " + blk.Name) log.Info("check if", me.currentDev.Name, "is in use") result, err := shell.RunVerbose([]string{"parted", me.currentDev.Name, "print"}) log.Info("result =", result.Stdout, "err =", err) out := strings.Join(result.Stdout, "\n") if err != nil { out += fmt.Sprintf("err = %v", err) } me.driveInfoBox.SetText(out) } func doGui() { me.myGui = gui.New() me.myGui.InitEmbed(resources) me.myGui.Default() mainWindow := gadgets.NewGenericWindow("RiscV Imager", "Show Drives") mainWindow.Custom = func() { log.Warn("Main window close") os.Exit(0) } drawWindow(mainWindow) // sits here forever debug() } func drawWindow(win *gadgets.GenericWindow) { grid := win.Group.RawGrid() me.dd = grid.NewDropdown() // me.dd.AddText("/dev/blah") me.dd.Custom = func() { fields := strings.Fields(me.dd.String()) log.Info("changed to", fields) if len(fields) < 1 { return } if blkpb := me.pb.FindByName(fields[0]); blkpb != nil { switchDrive(blkpb) } else { log.Info("couldn't find in protobuf:", fields) } } grid.NextRow() // a button to format or blank a drive me.parted = grid.NewButton("select drive", func() { if me.currentDev == nil { log.Info("You must select a drive first") return } log.Info("TODO: figure out if the drive is in use") }) grid.NextRow() grid.NewButton("doDrives()", func() { doDrives() }) grid.NewButton("show blkpb", func() { for blk := range me.pb.IterAll() { log.Printf("found %-12s %s\n", blk.Name, virtpb.HumanFormatBytes(int64(blk.SizeBytes))) } }) grid.NextRow() grid = win.Middle.RawGrid() me.driveInfoBox = grid.NewLabel("") doDrives2() doDrives() }