refactor(tracker): get rid of execChan, use broker.ToModel instead

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-11-02 23:44:52 +02:00
parent 76322bb541
commit 37769fcc9c
2 changed files with 7 additions and 14 deletions

View File

@ -133,17 +133,17 @@ func init() {
}
},
CloseFunc: func() {
t.Exec() <- func() { t.ForceQuit().Do() }
broker.ToModel <- tracker.MsgToModel{Data: func() { t.ForceQuit().Do() }}
t.WaitQuitted()
detector.Close()
},
GetChunkFunc: func(isPreset bool) []byte {
retChn := make(chan []byte)
t.Exec() <- func() { retChn <- t.MarshalRecovery() }
broker.ToModel <- tracker.MsgToModel{Data: func() { retChn <- t.MarshalRecovery() }}
return <-retChn
},
SetChunkFunc: func(data []byte, isPreset bool) {
t.Exec() <- func() { t.UnmarshalRecovery(data) }
broker.ToModel <- tracker.MsgToModel{Data: func() { t.UnmarshalRecovery(data) }}
},
}

View File

@ -89,7 +89,6 @@ func NewTracker(model *tracker.Model) *Tracker {
Model: model,
filePathString: model.FilePath().String(),
execChan: make(chan func(), 1024),
}
t.Theme.Shaper = text.NewShaper(text.WithCollection(fontCollection))
t.PopupAlert = NewPopupAlert(model.Alerts(), t.Theme.Shaper)
@ -155,8 +154,6 @@ func (t *Tracker) Main() {
}
case <-recoveryTicker.C:
t.SaveRecovery()
case f := <-t.execChan:
f()
}
if t.Quitted() {
break
@ -181,10 +178,6 @@ func eventLoop(w *app.Window, events chan<- event.Event, acks <-chan struct{}) {
}
}
func (t *Tracker) Exec() chan<- func() {
return t.execChan
}
func (t *Tracker) WaitQuitted() {
t.quitWG.Wait()
}
@ -261,14 +254,14 @@ func (t *Tracker) explorerChooseFile(success func(io.ReadCloser), extensions ...
t.Exploring = true
go func() {
file, err := t.Explorer.ChooseFile(extensions...)
t.Exec() <- func() {
t.Broker().ToModel <- tracker.MsgToModel{Data: func() {
t.Exploring = false
if err == nil {
success(file)
} else {
t.Cancel().Do()
}
}
}}
}()
}
@ -276,14 +269,14 @@ func (t *Tracker) explorerCreateFile(success func(io.WriteCloser), filename stri
t.Exploring = true
go func() {
file, err := t.Explorer.CreateFile(filename)
t.Exec() <- func() {
t.Broker().ToModel <- tracker.MsgToModel{Data: func() {
t.Exploring = false
if err == nil {
success(file)
} else {
t.Cancel().Do()
}
}
}}
}()
}