diff options
author | xengineering <me@xengineering.eu> | 2023-06-03 20:52:45 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-03 20:52:45 +0200 |
commit | e313bce92afea09b2da657b5a4f7de2c958c0100 (patch) | |
tree | 8975cb4432d2ed5195b3902c80cd5e702ea40cc0 /limox.go | |
parent | 30d99c706e3a75948c49289fc6b0317258957819 (diff) | |
download | limox-e313bce92afea09b2da657b5a4f7de2c958c0100.tar limox-e313bce92afea09b2da657b5a4f7de2c958c0100.tar.zst limox-e313bce92afea09b2da657b5a4f7de2c958c0100.zip |
Introduce new communication pattern
Diffstat (limited to 'limox.go')
-rw-r--r-- | limox.go | 24 |
1 files changed, 11 insertions, 13 deletions
@@ -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 } } |