itd/cmd/itgui/main.go

61 lines
1.4 KiB
Go
Raw Normal View History

2021-08-26 04:18:24 +00:00
package main
import (
2022-05-05 21:00:49 +00:00
"context"
"sync"
2021-08-26 04:18:24 +00:00
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
2021-10-24 20:27:14 +00:00
"go.arsenm.dev/itd/api"
2021-08-26 04:18:24 +00:00
)
func main() {
a := app.New()
2022-05-05 21:00:49 +00:00
w := a.NewWindow("itgui")
// Create new context for use with the API client
ctx, cancel := context.WithCancel(context.Background())
2021-08-26 04:18:24 +00:00
2022-05-05 21:00:49 +00:00
// Connect to ITD API
2021-10-24 20:27:14 +00:00
client, err := api.New(api.DefaultAddr)
2021-08-27 15:47:24 +00:00
if err != nil {
2022-05-05 21:00:49 +00:00
guiErr(err, "Error connecting to ITD", true, w)
2021-08-27 15:47:24 +00:00
}
2022-05-05 21:00:49 +00:00
// Create channel to signal that the fs tab has been opened
fsOpened := make(chan struct{})
fsOnce := &sync.Once{}
// Create app tabs
2021-08-26 04:18:24 +00:00
tabs := container.NewAppTabs(
2022-05-05 21:00:49 +00:00
container.NewTabItem("Info", infoTab(ctx, client, w)),
container.NewTabItem("Motion", motionTab(ctx, client, w)),
container.NewTabItem("Notify", notifyTab(ctx, client, w)),
container.NewTabItem("FS", fsTab(ctx, client, w, fsOpened)),
container.NewTabItem("Time", timeTab(ctx, client, w)),
container.NewTabItem("Firmware", firmwareTab(ctx, client, w)),
2021-08-26 04:18:24 +00:00
)
2022-05-11 06:37:58 +00:00
metricsTab := graphTab(ctx, client, w)
if metricsTab != nil {
tabs.Append(container.NewTabItem("Metrics", metricsTab))
}
2022-05-05 21:00:49 +00:00
// When a tab is selected
tabs.OnSelected = func(ti *container.TabItem) {
// If the tab's name is FS
if ti.Text == "FS" {
// Signal fsOpened only once
fsOnce.Do(func() {
fsOpened <- struct{}{}
})
}
}
// Cancel context on close
w.SetOnClosed(cancel)
// Set content and show window
w.SetContent(tabs)
w.ShowAndRun()
2021-08-26 04:18:24 +00:00
}