From 0f96bb37005dfda8c2fe20a638f670f6385d2e8b Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 18 May 2023 18:35:53 +0200 Subject: Use one bidirectional channel for communication --- limox.go | 12 +++++------- xmpp/xmpp.go | 8 ++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/limox.go b/limox.go index 2dee767..6723745 100644 --- a/limox.go +++ b/limox.go @@ -27,8 +27,7 @@ type Limox struct { JidEditor widget.Editor PwdEditor widget.Editor MainButton widget.Clickable - XmppEvents chan any - GuiEvents chan xmpp.Event + XmppConn chan any State LimoxState Window *app.Window Operations op.Ops @@ -43,8 +42,7 @@ func NewLimox() Limox { ), Operations: op.Ops{}, Theme: material.NewTheme(gofont.Collection()), - XmppEvents: make(chan any), - GuiEvents: make(chan xmpp.Event), + XmppConn: make(chan any), State: Disconnected, } } @@ -62,7 +60,7 @@ func (l *Limox) run() error { } l.draw(e) } - case ev := <-l.XmppEvents: + case ev := <-l.XmppConn: switch ev.(type) { case error: log.Print(ev) @@ -88,14 +86,14 @@ func (l *Limox) buttonCallback() { switch l.State { case Disconnected: log.Println("Starting connection establishment ...") - go xmpp.Run(l.GuiEvents, l.XmppEvents, l.JidEditor.Text(), l.PwdEditor.Text()) + go xmpp.Run(l.XmppConn, l.JidEditor.Text(), l.PwdEditor.Text()) l.State = Connecting case Connecting: log.Println("Aborted connection establishment") l.State = Disconnected case Connected: log.Println("Disconnecting ...") - l.GuiEvents <- xmpp.ShouldDisconnectEvent + l.XmppConn <- xmpp.ShouldDisconnectEvent l.State = Disconnected } } diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go index 5be12c4..5d5e9a3 100644 --- a/xmpp/xmpp.go +++ b/xmpp/xmpp.go @@ -16,7 +16,7 @@ const ( ShouldDisconnectEvent ) -func Run(rxChan chan Event, txChan chan any, jid string, pwd string) { +func Run(ch chan any, jid string, pwd string) { conn, err := setupConn(jid) if err != nil { log.Print(err) @@ -36,12 +36,12 @@ func Run(rxChan chan Event, txChan chan any, jid string, pwd string) { end := sendStreamStart(enc, dbg, jid) defer sendStreamEnd(enc, dbg, end) - txChan <- ConnectEvent - defer func() { txChan <- DisconnectEvent }() + ch <- ConnectEvent + defer func() { ch <- DisconnectEvent }() for { select { - case ev := <-rxChan: + case ev := <-ch: switch ev { case ShouldDisconnectEvent: return -- cgit v1.2.3-70-g09d2