From dc8ff3e7d214c6a390f2aa5c794891b17c418640 Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 4 Sep 2023 22:47:31 +0200 Subject: Add xmpp.SessionFrontend.Disconnect() This is the first convenience function implemented inside the xmpp module but for the goroutine of the using application. --- limox.go | 10 +++++----- xmpp/session.go | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/limox.go b/limox.go index 6c83e45..61614e0 100644 --- a/limox.go +++ b/limox.go @@ -25,7 +25,7 @@ type Limox struct { JidEditor widget.Editor PwdEditor widget.Editor MainButton widget.Clickable - frontend xmpp.SessionFrontend + sf xmpp.SessionFrontend State LimoxState Window *app.Window Operations op.Ops @@ -62,7 +62,7 @@ func (l *Limox) run() error { } l.draw(e) } - case data := <-l.frontend.In: + case data := <-l.sf.In: switch data.(type) { case xmpp.SessionDisconnect: l.State = Disconnected @@ -83,13 +83,13 @@ func (l *Limox) buttonCallback() { pwd := l.PwdEditor.Text() setLastJid(jid) setLastPwd(pwd) - l.frontend = xmpp.StartSession(jid, pwd) + l.sf = xmpp.StartSession(jid, pwd) l.State = Connecting case Connecting: - go func() { l.frontend.Out <- xmpp.SessionShouldDisconnect{} }() + l.sf.Disconnect() l.State = Disconnected case Connected: - go func() { l.frontend.Out <- xmpp.SessionShouldDisconnect{} }() + l.sf.Disconnect() l.State = Disconnected } } diff --git a/xmpp/session.go b/xmpp/session.go index ad90c5e..2c9fbb3 100644 --- a/xmpp/session.go +++ b/xmpp/session.go @@ -18,6 +18,10 @@ type SessionFrontend struct { Out chan any } +func (sf *SessionFrontend) Disconnect() { + go func() { sf.Out <- SessionShouldDisconnect{} }() +} + type session struct { jid string pwd string -- cgit v1.2.3-70-g09d2