summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-18 18:35:53 +0200
committerxengineering <me@xengineering.eu>2023-05-18 18:35:53 +0200
commit0f96bb37005dfda8c2fe20a638f670f6385d2e8b (patch)
tree616d70cc2127bc0c16235aff4b4fa1c44a20fe69
parentc5cd3e4eafb4fdd10c9bfe0ccac0993beb20f3ee (diff)
downloadlimox-0f96bb37005dfda8c2fe20a638f670f6385d2e8b.tar
limox-0f96bb37005dfda8c2fe20a638f670f6385d2e8b.tar.zst
limox-0f96bb37005dfda8c2fe20a638f670f6385d2e8b.zip
Use one bidirectional channel for communication
-rw-r--r--limox.go12
-rw-r--r--xmpp/xmpp.go8
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