From 3b333aef02d816b51a4040acdcbaa379ed3e0f18 Mon Sep 17 00:00:00 2001 From: FIGBERT Date: Sun, 13 Aug 2023 02:01:15 -0700 Subject: [PATCH] Don't run UI code in HandleMessage when headless --- headless/headless.go | 1 + matrix/matrix.go | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/headless/headless.go b/headless/headless.go index a5ae516..31cf4b6 100644 --- a/headless/headless.go +++ b/headless/headless.go @@ -36,6 +36,7 @@ func Init(conf Config, updates chan fmt.Stringer) error { } gmx := initialize.NewGomuks(ui.NewGomuksUI, configDir, dataDir, cacheDir, downloadDir) + gmx.Matrix().(*matrix.Container).SetHeadless() err = gmx.StartHeadless() if err != nil { return err diff --git a/matrix/matrix.go b/matrix/matrix.go index 9c2987f..39c2ea4 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -53,15 +53,16 @@ import ( // // It is used for all Matrix calls from the UI and Matrix event handlers. type Container struct { - client *mautrix.Client - crypto ifc.Crypto - syncer *GomuksSyncer - gmx ifc.Gomuks - ui ifc.GomuksUI - config *config.Config - history *HistoryManager - running bool - stop chan bool + client *mautrix.Client + crypto ifc.Crypto + syncer *GomuksSyncer + gmx ifc.Gomuks + ui ifc.GomuksUI + config *config.Config + history *HistoryManager + running bool + stop chan bool + headless bool typing int64 } @@ -77,6 +78,10 @@ func NewContainer(gmx ifc.Gomuks) *Container { return c } +func (c *Container) SetHeadless() { + c.headless = true +} + // Client returns the underlying mautrix Client. func (c *Container) Client() *mautrix.Client { return c.client @@ -689,6 +694,10 @@ func (c *Container) HandleMessage(source mautrix.EventSource, mxEvent *event.Eve return } + if c.headless { + return + } + mainView := c.ui.MainView() roomView := mainView.GetRoom(evt.RoomID)