Skip to content

Commit

Permalink
interface tide up
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkondrashin committed Mar 8, 2024
1 parent c28bb9a commit d3ea3bf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
2 changes: 2 additions & 0 deletions cmd/sandboxer/ddan_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func NewStatsWindow(conf *config.Configuration) *StatsWindow {

func (w *StatsWindow) Content(modal *ModalWindow) fyne.CanvasObject {
w.win = modal.win
topLabel := widget.NewLabel("Deep Discovery Analyzer Statistis")
totalLabel := widget.NewLabel("Average Total Processing Time\n(from the moment of submission,\nincluding queueing)")
totalForm := widget.NewForm(w.AvgTotalProcessingTime.FormItems()...)
vaLabel := widget.NewLabel("Average Analysis Time\n(by sandbox)\n")
Expand All @@ -102,6 +103,7 @@ func (w *StatsWindow) Content(modal *ModalWindow) fyne.CanvasObject {
dataHBox := container.NewHBox(totalVBox, vaVBox)
w.Reset()
return container.NewVBox(
topLabel,
dataHBox,
widget.NewButton("Update", func() {
w.Update()
Expand Down
14 changes: 3 additions & 11 deletions cmd/sandboxer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,9 @@ type TrayApp struct {

type SandboxerApp struct {
TrayApp
// SUBMIT_FILE submitMenuItem *fyne.MenuItem
//submissionsMenuItem *fyne.MenuItem
//quotaMenuItem *fyne.MenuItem
//optionsMenuItem *fyne.MenuItem
//updateMenuItem *fyne.MenuItem
//aboutMenuItem *fyne.MenuItem

submissionsWindow *ModalWindow
//quotaWindow *QuotaWindow
optionsWindow *ModalWindow
updateWindow *ModalWindow
//aboutWindow *AboutWindow
optionsWindow *ModalWindow
updateWindow *ModalWindow
}

func NewSandboxingApp(conf *config.Configuration, channels *task.Channels, list *task.TaskList) *SandboxerApp {
Expand Down Expand Up @@ -92,6 +83,7 @@ func NewSandboxingApp(conf *config.Configuration, channels *task.Channels, list
// SUBMIT_FILE s.submitMenuItem,
submitWindow.MenuItem,
a.submissionsWindow.MenuItem,
fyne.NewMenuItemSeparator(),
quotaWindow.MenuItem,
statsWindow.MenuItem,
a.optionsWindow.MenuItem,
Expand Down
50 changes: 35 additions & 15 deletions pkg/settings/ddan_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package settings
import (
"context"
"errors"
"image/color"
"net/url"
"sandboxer/pkg/config"
"sandboxer/pkg/logging"
"strings"
"time"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"

Expand All @@ -22,7 +23,7 @@ type DDAn struct {
ddanURLEntry *widget.Entry
ddanAPIKeyEntry *widget.Entry
ddanIgnoreTLSCheck *widget.Check
ddanTest *widget.Label
ddanTest *canvas.Text // *widget.Label
cancelTestDDAn context.CancelFunc
}

Expand Down Expand Up @@ -57,28 +58,42 @@ func (s *DDAn) Widget() fyne.CanvasObject {
}
ignoreTLSFormItem := widget.NewFormItem("TLS Errors: ", s.ddanIgnoreTLSCheck)

s.ddanTest = widget.NewLabel("")
s.ddanTest = canvas.NewText("", color.Black)
//s.ddanTest = widget.NewLabel("")
//s.ddanTest.Truncation = fyne.TextTruncateEllipsis

//stateText := canvas.NewText(tsk.GetChannel(), tsk.RiskLevel.Color())
//stateText.TextStyle = fyne.TextStyle{Bold: tsk.Active}

ddanForm := widget.NewForm(urlFormItem, apiKeyFormItem, ignoreTLSFormItem)
return container.NewVBox(ddanForm, s.ddanTest)
return container.NewVBox(ddanForm, container.NewHScroll(s.ddanTest))
}

func (s *DDAn) Update() {
s.TestAnalyzer()
}

/*
const MaxLength = 64
func LimitLength(s string) string {
logging.Errorf("DDAn Connection: %s", s)
if len(s) < MaxLength {
return "Error: " + s
func LimitLength(s string) string {
logging.Errorf("DDAn Connection: %s", s)
if len(s) < MaxLength {
return "Error: " + s
}
return "Error: ..." + s[len(s)-MaxLength+7:]
}
return "Error: ..." + s[len(s)-MaxLength+7:]
*/

func (s *DDAn) SetMessageError(message string) {
s.ddanTest.Text = "Error: " + message
s.ddanTest.Color = color.RGBA{255, 0, 0, 255}
s.ddanTest.Refresh()
}

func (s *DDAn) SetMessageOk(message string) {
s.ddanTest.Text = message
s.ddanTest.Color = color.Black
s.ddanTest.Refresh()
}

func (s *DDAn) TestAnalyzer() {
Expand All @@ -94,10 +109,13 @@ func (s *DDAn) TestAnalyzer() {
}
s.cancelTestDDAn = nil
}()
s.ddanTest.SetText("Checking connection...")
//s.ddanTest.SetText("Checking connection...")
s.SetMessageOk("Checking connection...")

u, err := url.Parse(s.GetDDAnURL())
if err != nil {
s.ddanTest.SetText(LimitLength(err.Error()))
s.SetMessageError(err.Error())
//s.ddanTest.SetText(err.Error()) //LimitLength(err.Error()))
return
}
apiKey := strings.TrimSpace(s.ddanAPIKeyEntry.Text)
Expand All @@ -111,13 +129,15 @@ func (s *DDAn) TestAnalyzer() {
if err != nil {
if !errors.Is(err, context.Canceled) {
if errors.Is(err, context.DeadlineExceeded) {
s.ddanTest.SetText("Connection timed out")
s.SetMessageError("Connection timed out")
//s.ddanTest.SetText("Connection timed out")
} else {
s.ddanTest.SetText(LimitLength(err.Error()))
s.SetMessageError(err.Error())
}
}
} else {
s.ddanTest.SetText("Connection is Ok")
s.SetMessageOk("Connection is Ok")
//s.ddanTest.SetText("Connection is Ok")
}
}()
}
Expand Down

0 comments on commit d3ea3bf

Please sign in to comment.