diff --git a/main.go b/main.go index 2bcf212..e940d12 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( + "fmt" "time" "fyne.io/fyne/v2" @@ -17,6 +18,7 @@ func main() { var timer time.Duration var ticking bool = false var status string = "WORK TIME" + var laps int = 0 // TODO: GET DEFAULT WORK AND BREAK TIMES FROM FILESYSTEM var defaultWorkTime string = "25m" @@ -35,9 +37,12 @@ func main() { breakEntry := widget.NewEntry() breakEntry.SetText(defaultBreakTime) breakEntry.TextStyle.Monospace = true - breakEntry.Refresh() + lapsLabel := widget.NewLabel("0 laps") + lapsLabel.TextStyle.Bold = true + lapsLabel.Alignment = fyne.TextAlignCenter + var beginButton *widget.Button beginButton = widget.NewButtonWithIcon("Start", theme.Icon(theme.IconNameMediaPlay), func() { go func() { @@ -79,11 +84,15 @@ func main() { for ticking { cur := time.Since(timeStarted) if status == "WORK TIME" { - workEntry.Disable() - workEntry.SetText((cur.Round(time.Second) - timer.Round(time.Second)).Abs().String()) + fyne.Do(func() { + workEntry.Disable() + workEntry.SetText((cur.Round(time.Second) - timer.Round(time.Second)).Abs().String()) + }) } else { - breakEntry.Disable() - breakEntry.SetText((cur.Round(time.Second) - timer.Round(time.Second)).Abs().String()) + fyne.Do(func() { + breakEntry.Disable() + breakEntry.SetText((cur.Round(time.Second) - timer.Round(time.Second)).Abs().String()) + }) } if cur >= timer { @@ -107,6 +116,8 @@ func main() { } timer = timer + cur w.SetTitle(status) + laps++ + lapsLabel.SetText(fmt.Sprintf("%d laps", laps)) } } else { time.Sleep(time.Second * 1) @@ -130,14 +141,20 @@ func main() { beginButton.Importance = widget.HighImportance - w.SetContent(container.NewGridWithColumns(3, workEntry, breakEntry, container.NewVBox(beginButton, widget.NewButtonWithIcon("Skip", theme.Icon(theme.IconNameMediaSkipNext), func() { - if status == "WORK TIME" { - status = "BREAK TIME" - } else { - status = "WORK TIME" + + w.SetContent(container.NewVBox(container.NewGridWithColumns(3, workEntry, breakEntry, container.NewVBox(beginButton, widget.NewButtonWithIcon("Skip", theme.Icon(theme.IconNameMediaSkipNext), func() { + if !ticking { + if status == "WORK TIME" { + status = "BREAK TIME" + } else { + status = "WORK TIME" + laps++ + lapsLabel.SetText(fmt.Sprintf("%d laps", laps)) + lapsLabel.Refresh() + } + w.SetTitle(status) } - w.SetTitle(status) - })))) + }))), lapsLabel)) menu := fyne.NewMainMenu(fyne.NewMenu("root"), fyne.NewMenu("help", fyne.NewMenuItem("valid time arguments", func() { neww := fyne.CurrentApp().NewWindow("Help") neww.Resize(fyne.NewSize(500, 500))