Remove debug print and add error handling (itgui)
This commit is contained in:
parent
76875db7ea
commit
9d58ea0ae7
@ -1,18 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"go.arsenm.dev/itd/api"
|
"go.arsenm.dev/itd/api"
|
||||||
"go.arsenm.dev/itd/internal/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
||||||
@ -24,15 +20,17 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
// Create label for heart rate
|
// Create label for heart rate
|
||||||
heartRateLbl := newText("0 BPM", 24)
|
heartRateLbl := newText("0 BPM", 24)
|
||||||
// Creae container to store heart rate section
|
// Creae container to store heart rate section
|
||||||
heartRate := container.NewVBox(
|
heartRateSect := container.NewVBox(
|
||||||
newText("Heart Rate", 12),
|
newText("Heart Rate", 12),
|
||||||
heartRateLbl,
|
heartRateLbl,
|
||||||
canvas.NewLine(theme.ShadowColor()),
|
canvas.NewLine(theme.ShadowColor()),
|
||||||
)
|
)
|
||||||
infoLayout.Add(heartRate)
|
infoLayout.Add(heartRateSect)
|
||||||
|
|
||||||
fmt.Println(3)
|
|
||||||
heartRateCh, cancel, err := client.WatchHeartRate()
|
heartRateCh, cancel, err := client.WatchHeartRate()
|
||||||
|
if err != nil {
|
||||||
|
guiErr(err, "Error getting heart rate channel", true, parent)
|
||||||
|
}
|
||||||
onClose = append(onClose, cancel)
|
onClose = append(onClose, cancel)
|
||||||
go func() {
|
go func() {
|
||||||
for heartRate := range heartRateCh {
|
for heartRate := range heartRateCh {
|
||||||
@ -42,7 +40,30 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
heartRateLbl.Refresh()
|
heartRateLbl.Refresh()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
fmt.Println(4)
|
|
||||||
|
// Create label for heart rate
|
||||||
|
stepCountLbl := newText("0 Steps", 24)
|
||||||
|
// Creae container to store heart rate section
|
||||||
|
stepCountSect := container.NewVBox(
|
||||||
|
newText("Step Count", 12),
|
||||||
|
stepCountLbl,
|
||||||
|
canvas.NewLine(theme.ShadowColor()),
|
||||||
|
)
|
||||||
|
infoLayout.Add(stepCountSect)
|
||||||
|
|
||||||
|
stepCountCh, cancel, err := client.WatchStepCount()
|
||||||
|
if err != nil {
|
||||||
|
guiErr(err, "Error getting step count channel", true, parent)
|
||||||
|
}
|
||||||
|
onClose = append(onClose, cancel)
|
||||||
|
go func() {
|
||||||
|
for stepCount := range stepCountCh {
|
||||||
|
// Change text of heart rate label
|
||||||
|
stepCountLbl.Text = fmt.Sprintf("%d Steps", stepCount)
|
||||||
|
// Refresh label
|
||||||
|
stepCountLbl.Refresh()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Create label for battery level
|
// Create label for battery level
|
||||||
battLevelLbl := newText("0%", 24)
|
battLevelLbl := newText("0%", 24)
|
||||||
@ -54,8 +75,10 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
)
|
)
|
||||||
infoLayout.Add(battLevel)
|
infoLayout.Add(battLevel)
|
||||||
|
|
||||||
fmt.Println(5)
|
|
||||||
battLevelCh, cancel, err := client.WatchBatteryLevel()
|
battLevelCh, cancel, err := client.WatchBatteryLevel()
|
||||||
|
if err != nil {
|
||||||
|
guiErr(err, "Error getting battery level channel", true, parent)
|
||||||
|
}
|
||||||
onClose = append(onClose, cancel)
|
onClose = append(onClose, cancel)
|
||||||
go func() {
|
go func() {
|
||||||
for battLevel := range battLevelCh {
|
for battLevel := range battLevelCh {
|
||||||
@ -65,14 +88,11 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
battLevelLbl.Refresh()
|
battLevelLbl.Refresh()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
fmt.Println(6)
|
|
||||||
|
|
||||||
fmt.Println(7)
|
|
||||||
fwVerString, err := client.Version()
|
fwVerString, err := client.Version()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error getting firmware string", true, parent)
|
guiErr(err, "Error getting firmware string", true, parent)
|
||||||
}
|
}
|
||||||
fmt.Println(8)
|
|
||||||
|
|
||||||
fwVer := container.NewVBox(
|
fwVer := container.NewVBox(
|
||||||
newText("Firmware Version", 12),
|
newText("Firmware Version", 12),
|
||||||
@ -81,12 +101,10 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
)
|
)
|
||||||
infoLayout.Add(fwVer)
|
infoLayout.Add(fwVer)
|
||||||
|
|
||||||
fmt.Println(9)
|
|
||||||
btAddrString, err := client.Address()
|
btAddrString, err := client.Address()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println(10)
|
|
||||||
|
|
||||||
btAddr := container.NewVBox(
|
btAddr := container.NewVBox(
|
||||||
newText("Bluetooth Address", 12),
|
newText("Bluetooth Address", 12),
|
||||||
@ -98,18 +116,6 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
return infoLayout
|
return infoLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResp(line []byte) (*types.Response, error) {
|
|
||||||
var res types.Response
|
|
||||||
err := json.Unmarshal(line, &res)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if res.Error {
|
|
||||||
return nil, errors.New(res.Message)
|
|
||||||
}
|
|
||||||
return &res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newText(t string, size float32) *canvas.Text {
|
func newText(t string, size float32) *canvas.Text {
|
||||||
text := canvas.NewText(t, theme.ForegroundColor())
|
text := canvas.NewText(t, theme.ForegroundColor())
|
||||||
text.TextSize = size
|
text.TextSize = size
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"go.arsenm.dev/itd/api"
|
"go.arsenm.dev/itd/api"
|
||||||
@ -21,7 +19,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Println(1)
|
|
||||||
client, err := api.New(api.DefaultAddr)
|
client, err := api.New(api.DefaultAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error connecting to itd", true, window)
|
guiErr(err, "Error connecting to itd", true, window)
|
||||||
@ -29,7 +26,6 @@ func main() {
|
|||||||
onClose = append(onClose, func() {
|
onClose = append(onClose, func() {
|
||||||
client.Close()
|
client.Close()
|
||||||
})
|
})
|
||||||
fmt.Println(2)
|
|
||||||
|
|
||||||
// Create new app tabs container
|
// Create new app tabs container
|
||||||
tabs := container.NewAppTabs(
|
tabs := container.NewAppTabs(
|
||||||
|
Loading…
Reference in New Issue
Block a user