diff options
-rw-r--r-- | gui.go | 6 | ||||
-rw-r--r-- | limox.go | 18 | ||||
-rw-r--r-- | xmpp/xmpp.go (renamed from xmpp.go) | 19 |
3 files changed, 20 insertions, 23 deletions
@@ -10,12 +10,6 @@ import ( "gioui.org/widget/material" ) -type GuiEvent uint8 - -const ( - Disconnect GuiEvent = iota -) - func (l *Limox) draw(e system.FrameEvent) { gtx := layout.NewContext(&l.Operations, e) @@ -11,6 +11,8 @@ import ( "gioui.org/unit" "gioui.org/widget" "gioui.org/widget/material" + + "xengineering.eu/limox/xmpp" ) type LimoxState uint8 @@ -26,7 +28,7 @@ type Limox struct { PwdEditor widget.Editor MainButton widget.Clickable XmppEvents chan any - GuiEvents chan GuiEvent + GuiEvents chan xmpp.Event State LimoxState Window *app.Window Operations op.Ops @@ -42,7 +44,7 @@ func NewLimox() Limox { Operations: op.Ops{}, Theme: material.NewTheme(gofont.Collection()), XmppEvents: make(chan any), - GuiEvents: make(chan GuiEvent), + GuiEvents: make(chan xmpp.Event), State: Disconnected, } } @@ -65,14 +67,14 @@ func (l *Limox) run() error { case error: log.Print(ev) l.State = Disconnected - case XmppEvent: + case xmpp.Event: switch ev { - case XmppDisconnect: + case xmpp.DisconnectEvent: l.State = Disconnected - case XmppConnect: + case xmpp.ConnectEvent: l.State = Connected default: - log.Printf("Unknown XmppEvent '%d'\n", ev) + log.Printf("Unknown xmpp.Event '%d'\n", ev) } default: log.Printf("Unknown event type '%s'.\n", reflect.TypeOf(ev)) @@ -86,14 +88,14 @@ func (l *Limox) buttonCallback() { switch l.State { case Disconnected: log.Println("Starting connection establishment ...") - go xmpp(l.GuiEvents, l.XmppEvents, l.JidEditor.Text(), l.PwdEditor.Text()) + go xmpp.Run(l.GuiEvents, l.XmppEvents, 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 <- Disconnect + l.GuiEvents <- xmpp.ShouldDisconnectEvent l.State = Disconnected } } @@ -1,4 +1,4 @@ -package main +package xmpp import ( "crypto/tls" @@ -8,14 +8,15 @@ import ( "os" ) -type XmppEvent uint8 +type Event uint8 const ( - XmppDisconnect XmppEvent = iota - XmppConnect + DisconnectEvent Event = iota + ConnectEvent + ShouldDisconnectEvent ) -func xmpp(rxChan chan GuiEvent, txChan chan any, jid string, pwd string) { +func Run(rxChan chan Event, txChan chan any, jid string, pwd string) { conn, err := setupConn(jid) if err != nil { log.Print(err) @@ -35,17 +36,17 @@ func xmpp(rxChan chan GuiEvent, txChan chan any, jid string, pwd string) { end := sendStreamStart(enc, dbg, jid) defer sendStreamEnd(enc, dbg, end) - txChan <- XmppConnect - defer func() { txChan <- XmppDisconnect }() + txChan <- ConnectEvent + defer func() { txChan <- DisconnectEvent }() for { select { case ev := <-rxChan: switch ev { - case Disconnect: + case ShouldDisconnectEvent: return default: - log.Printf("Unknown GuiEvent '%d'!\n", ev) + log.Printf("Unknown Event '%d'!\n", ev) } case rx := <-receiver.data: dbg.Indent("S: ", " ") |