1
0
Fork 0
forked from Mirrors/gomuks

Don't run UI code in HandleMessage when headless

This commit is contained in:
FIGBERT 2023-08-13 02:01:15 -07:00
parent fb10f59801
commit 3b333aef02
No known key found for this signature in database
GPG key ID: 67F1598D607A844B
2 changed files with 19 additions and 9 deletions

View file

@ -36,6 +36,7 @@ func Init(conf Config, updates chan fmt.Stringer) error {
} }
gmx := initialize.NewGomuks(ui.NewGomuksUI, configDir, dataDir, cacheDir, downloadDir) gmx := initialize.NewGomuks(ui.NewGomuksUI, configDir, dataDir, cacheDir, downloadDir)
gmx.Matrix().(*matrix.Container).SetHeadless()
err = gmx.StartHeadless() err = gmx.StartHeadless()
if err != nil { if err != nil {
return err return err

View file

@ -53,15 +53,16 @@ import (
// //
// It is used for all Matrix calls from the UI and Matrix event handlers. // It is used for all Matrix calls from the UI and Matrix event handlers.
type Container struct { type Container struct {
client *mautrix.Client client *mautrix.Client
crypto ifc.Crypto crypto ifc.Crypto
syncer *GomuksSyncer syncer *GomuksSyncer
gmx ifc.Gomuks gmx ifc.Gomuks
ui ifc.GomuksUI ui ifc.GomuksUI
config *config.Config config *config.Config
history *HistoryManager history *HistoryManager
running bool running bool
stop chan bool stop chan bool
headless bool
typing int64 typing int64
} }
@ -77,6 +78,10 @@ func NewContainer(gmx ifc.Gomuks) *Container {
return c return c
} }
func (c *Container) SetHeadless() {
c.headless = true
}
// Client returns the underlying mautrix Client. // Client returns the underlying mautrix Client.
func (c *Container) Client() *mautrix.Client { func (c *Container) Client() *mautrix.Client {
return c.client return c.client
@ -689,6 +694,10 @@ func (c *Container) HandleMessage(source mautrix.EventSource, mxEvent *event.Eve
return return
} }
if c.headless {
return
}
mainView := c.ui.MainView() mainView := c.ui.MainView()
roomView := mainView.GetRoom(evt.RoomID) roomView := mainView.GetRoom(evt.RoomID)