mirror of
https://github.com/wisplite/parchment.git
synced 2026-06-27 21:57:08 -05:00
fixed some ui state issues
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
func MonitorDevice(ctx context.Context, app *tview.Application, frame **tview.Frame, device *Device) {
|
||||
func MonitorDevice(ctx context.Context, app *tview.Application, frame **tview.Frame, state *UIState, device *Device) {
|
||||
ticker := time.NewTicker(100 * time.Millisecond) // Check every 100ms
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
@@ -24,19 +24,19 @@ func MonitorDevice(ctx context.Context, app *tview.Application, frame **tview.Fr
|
||||
if err != nil {
|
||||
if device.Connected {
|
||||
device.Close()
|
||||
UpdateDeviceStatus(app, *frame, "Cardputer disconnected", tcell.ColorRed)
|
||||
UpdateDeviceStatus(app, *frame, state, "Cardputer disconnected", tcell.ColorRed)
|
||||
}
|
||||
} else {
|
||||
if !device.Connected {
|
||||
UpdateDeviceStatus(app, *frame, "Cardputer found: "+port, tcell.ColorWhite)
|
||||
UpdateDeviceStatus(app, *frame, state, "Cardputer found: "+port, tcell.ColorWhite)
|
||||
err = device.Connect()
|
||||
if err != nil {
|
||||
UpdateDeviceStatus(app, *frame, "Error connecting to cardputer: "+err.Error(), tcell.ColorRed)
|
||||
UpdateDeviceStatus(app, *frame, state, "Error connecting to cardputer: "+err.Error(), tcell.ColorRed)
|
||||
} else {
|
||||
UpdateDeviceStatus(app, *frame, "Connected to cardputer: "+port, tcell.ColorGreen)
|
||||
UpdateDeviceStatus(app, *frame, state, "Connected to cardputer: "+port, tcell.ColorGreen)
|
||||
}
|
||||
} else {
|
||||
UpdateDeviceStatus(app, *frame, "Connected to cardputer: "+port, tcell.ColorGreen)
|
||||
UpdateDeviceStatus(app, *frame, state, "Connected to cardputer: "+port, tcell.ColorGreen)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,10 @@ func main() {
|
||||
|
||||
app := tview.NewApplication()
|
||||
var currentFrame *tview.Frame
|
||||
frame := AppUI(app, ¤tFrame)
|
||||
state := &UIState{
|
||||
Page: "home",
|
||||
}
|
||||
frame := AppUI(app, ¤tFrame, state)
|
||||
currentFrame = frame
|
||||
app.SetRoot(frame, true)
|
||||
|
||||
@@ -76,7 +79,7 @@ func main() {
|
||||
app.Stop()
|
||||
}()
|
||||
|
||||
go MonitorDevice(ctx, app, ¤tFrame, device)
|
||||
go MonitorDevice(ctx, app, ¤tFrame, state, device)
|
||||
|
||||
if err := app.Run(); err != nil {
|
||||
log.Fatal("Error running program:", err)
|
||||
|
||||
Reference in New Issue
Block a user