From 8fce634716a998721cc5fb4663a7c0379c6df633 Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 18 May 2023 18:40:46 +0200 Subject: Use only xmpp.Event for channel communication --- limox.go | 23 +++++++---------------- xmpp/xmpp.go | 2 +- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/limox.go b/limox.go index 6723745..672396e 100644 --- a/limox.go +++ b/limox.go @@ -2,7 +2,6 @@ package main import ( "log" - "reflect" "gioui.org/app" "gioui.org/font/gofont" @@ -27,7 +26,7 @@ type Limox struct { JidEditor widget.Editor PwdEditor widget.Editor MainButton widget.Clickable - XmppConn chan any + XmppConn chan xmpp.Event State LimoxState Window *app.Window Operations op.Ops @@ -42,7 +41,7 @@ func NewLimox() Limox { ), Operations: op.Ops{}, Theme: material.NewTheme(gofont.Collection()), - XmppConn: make(chan any), + XmppConn: make(chan xmpp.Event), State: Disconnected, } } @@ -61,21 +60,13 @@ func (l *Limox) run() error { l.draw(e) } case ev := <-l.XmppConn: - switch ev.(type) { - case error: - log.Print(ev) + switch ev { + case xmpp.DisconnectEvent: l.State = Disconnected - case xmpp.Event: - switch ev { - case xmpp.DisconnectEvent: - l.State = Disconnected - case xmpp.ConnectEvent: - l.State = Connected - default: - log.Printf("Unknown xmpp.Event '%d'\n", ev) - } + case xmpp.ConnectEvent: + l.State = Connected default: - log.Printf("Unknown event type '%s'.\n", reflect.TypeOf(ev)) + log.Printf("Unknown xmpp.Event '%d'\n", ev) } l.Window.Invalidate() } diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go index 5d5e9a3..69fe48d 100644 --- a/xmpp/xmpp.go +++ b/xmpp/xmpp.go @@ -16,7 +16,7 @@ const ( ShouldDisconnectEvent ) -func Run(ch chan any, jid string, pwd string) { +func Run(ch chan Event, jid string, pwd string) { conn, err := setupConn(jid) if err != nil { log.Print(err) -- cgit v1.2.3-70-g09d2