forked from Elara6331/itd
Rewrite itgui and add new screenshots
This commit is contained in:
@@ -1,43 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"go.arsenm.dev/itd/api"
|
||||
)
|
||||
|
||||
var onClose []func()
|
||||
|
||||
func main() {
|
||||
// Create new app
|
||||
a := app.New()
|
||||
// Create new window with title "itgui"
|
||||
window := a.NewWindow("itgui")
|
||||
window.SetOnClosed(func() {
|
||||
for _, closeFn := range onClose {
|
||||
closeFn()
|
||||
}
|
||||
})
|
||||
w := a.NewWindow("itgui")
|
||||
|
||||
// Create new context for use with the API client
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
// Connect to ITD API
|
||||
client, err := api.New(api.DefaultAddr)
|
||||
if err != nil {
|
||||
guiErr(err, "Error connecting to itd", true, window)
|
||||
guiErr(err, "Error connecting to ITD", true, w)
|
||||
}
|
||||
onClose = append(onClose, func() {
|
||||
client.Close()
|
||||
})
|
||||
|
||||
// Create new app tabs container
|
||||
// Create channel to signal that the fs tab has been opened
|
||||
fsOpened := make(chan struct{})
|
||||
fsOnce := &sync.Once{}
|
||||
|
||||
// Create app tabs
|
||||
tabs := container.NewAppTabs(
|
||||
container.NewTabItem("Info", infoTab(window, client)),
|
||||
container.NewTabItem("Motion", motionTab(window, client)),
|
||||
container.NewTabItem("Notify", notifyTab(window, client)),
|
||||
container.NewTabItem("Set Time", timeTab(window, client)),
|
||||
container.NewTabItem("Upgrade", upgradeTab(window, client)),
|
||||
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)),
|
||||
)
|
||||
|
||||
// Set tabs as window content
|
||||
window.SetContent(tabs)
|
||||
// Show window and run app
|
||||
window.ShowAndRun()
|
||||
// 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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user