From e313bce92afea09b2da657b5a4f7de2c958c0100 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 3 Jun 2023 20:52:45 +0200 Subject: Introduce new communication pattern --- limox.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'limox.go') diff --git a/limox.go b/limox.go index 320765f..6588b3d 100644 --- a/limox.go +++ b/limox.go @@ -26,8 +26,8 @@ type Limox struct { JidEditor widget.Editor PwdEditor widget.Editor MainButton widget.Clickable - session *xmpp.Session - XmppConn chan xmpp.Event + sessionOut chan any + sessionIn chan any State LimoxState Window *app.Window Operations op.Ops @@ -42,7 +42,7 @@ func NewLimox() Limox { ), Operations: op.Ops{}, Theme: material.NewTheme(gofont.Collection()), - XmppConn: make(chan xmpp.Event), + sessionIn: make(chan any), State: Disconnected, } @@ -65,14 +65,14 @@ func (l *Limox) run() error { } l.draw(e) } - case ev := <-l.XmppConn: - switch ev { - case xmpp.DisconnectEvent: + case data := <-l.sessionIn: + switch data.(type) { + case xmpp.SessionDisconnect: l.State = Disconnected - case xmpp.ConnectEvent: + case xmpp.SessionConnect: l.State = Connected default: - log.Printf("Unknown xmpp.Event '%d'\n", ev) + log.Printf("Unknown XMPP data '%d'\n", data) } l.Window.Invalidate() } @@ -86,15 +86,13 @@ func (l *Limox) buttonCallback() { pwd := l.PwdEditor.Text() setLastJid(jid) setLastPwd(pwd) - l.session = xmpp.NewSession(jid, pwd) - l.XmppConn = l.session.Out - go l.session.Run() + l.sessionOut = xmpp.StartSession(l.sessionIn, jid, pwd) l.State = Connecting case Connecting: - l.session.Close() + go func() { l.sessionOut <- xmpp.SessionShouldDisconnect{} }() l.State = Disconnected case Connected: - l.session.Close() + go func() { l.sessionOut <- xmpp.SessionShouldDisconnect{} }() l.State = Disconnected } } -- cgit v1.2.3-70-g09d2