FlexDXCluster/app.go
2024-11-17 21:08:10 +07:00

104 lines
3.3 KiB
Go

package main
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
type Application struct {
App fyne.App
MainWindow fyne.Window
StatusTCPClientChan chan bool
StatusFlexChan chan bool
SpotChan chan TelnetSpot
}
func NewApp() *Application {
a := app.New()
w := a.NewWindow("FlexDXCluster")
w.CenterOnScreen()
w.Resize(fyne.NewSize(700, 400))
servicesLabel := canvas.NewText("Connected Services", color.Black)
servicesLabel.TextStyle = fyne.TextStyle{Bold: true}
TCPClientLabel := canvas.NewText("DX Cluster: ", color.Black)
TCPClientStatusLabel := canvas.NewText("Disconnected", color.RGBA{255, 0, 0, 255})
TCPClientStatusLabel.TextStyle = fyne.TextStyle{Bold: true}
TCPClientAll := container.NewHBox(TCPClientLabel, TCPClientStatusLabel)
FlexRadioLabel := canvas.NewText("FlexRadio: ", color.Black)
FlexRadioStatusLabel := canvas.NewText("Disconnected", color.RGBA{255, 0, 0, 255})
FlexRadioStatusLabel.TextStyle = fyne.TextStyle{Bold: true}
FlexRadioAll := container.NewHBox(FlexRadioLabel, FlexRadioStatusLabel)
Sep := widget.NewSeparator()
SpotLabelDX := canvas.NewText("DX: ", color.Black)
SpotLabelFreqMhz := canvas.NewText("Freq: ", color.Black)
SpotLabelBand := canvas.NewText("Band: ", color.Black)
Spot := container.NewHBox(SpotLabelDX, SpotLabelFreqMhz, SpotLabelBand)
content := container.NewVBox(servicesLabel, Sep, TCPClientAll, FlexRadioAll, Sep, Spot)
w.SetContent(content)
app := &Application{
App: a,
MainWindow: w,
StatusTCPClientChan: make(chan bool, 1),
StatusFlexChan: make(chan bool, 1),
SpotChan: make(chan TelnetSpot, 100),
}
go app.updateStatusTCPClient(TCPClientStatusLabel)
go app.updateStatusFlex(FlexRadioStatusLabel)
go app.updateDXSpot(SpotLabelDX, SpotLabelFreqMhz, SpotLabelBand)
return app
}
func (a *Application) Start() {
a.MainWindow.ShowAndRun()
}
func (a *Application) updateStatusTCPClient(TCPClientLabelStatus *canvas.Text) {
for status := range a.StatusTCPClientChan {
if status {
TCPClientLabelStatus.Text = "Connected"
TCPClientLabelStatus.Color = color.Color(color.RGBA{0, 94, 27, 255})
TCPClientLabelStatus.TextStyle = fyne.TextStyle{Bold: true}
} else {
TCPClientLabelStatus.Text = "Disconnected"
TCPClientLabelStatus.Color = color.Color(color.RGBA{255, 0, 0, 255})
TCPClientLabelStatus.TextStyle = fyne.TextStyle{Bold: true}
}
}
}
func (a *Application) updateStatusFlex(FlexRadioStatusLabel *canvas.Text) {
for status := range a.StatusFlexChan {
if status {
FlexRadioStatusLabel.Text = "Connected"
FlexRadioStatusLabel.Color = color.Color(color.RGBA{0, 94, 27, 255})
FlexRadioStatusLabel.TextStyle = fyne.TextStyle{Bold: true}
} else {
FlexRadioStatusLabel.Text = "Disconnected"
FlexRadioStatusLabel.Color = color.Color(color.RGBA{255, 0, 0, 255})
FlexRadioStatusLabel.TextStyle = fyne.TextStyle{Bold: true}
}
}
}
func (a *Application) updateDXSpot(SpotLabelDX *canvas.Text, SpotLabelFreqMhz *canvas.Text, SpotLabelBand *canvas.Text) {
for spot := range a.SpotChan {
SpotLabelDX.Text = "DX: " + spot.DX
SpotLabelFreqMhz.Text = "- Freq: " + spot.Frequency
SpotLabelBand.Text = "- Band: " + spot.Band
}
}