mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
refactor(tracker): get rid of execChan, use broker.ToModel instead
This commit is contained in:
parent
76322bb541
commit
37769fcc9c
@ -133,17 +133,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
CloseFunc: func() {
|
CloseFunc: func() {
|
||||||
t.Exec() <- func() { t.ForceQuit().Do() }
|
broker.ToModel <- tracker.MsgToModel{Data: func() { t.ForceQuit().Do() }}
|
||||||
t.WaitQuitted()
|
t.WaitQuitted()
|
||||||
detector.Close()
|
detector.Close()
|
||||||
},
|
},
|
||||||
GetChunkFunc: func(isPreset bool) []byte {
|
GetChunkFunc: func(isPreset bool) []byte {
|
||||||
retChn := make(chan []byte)
|
retChn := make(chan []byte)
|
||||||
t.Exec() <- func() { retChn <- t.MarshalRecovery() }
|
broker.ToModel <- tracker.MsgToModel{Data: func() { retChn <- t.MarshalRecovery() }}
|
||||||
return <-retChn
|
return <-retChn
|
||||||
},
|
},
|
||||||
SetChunkFunc: func(data []byte, isPreset bool) {
|
SetChunkFunc: func(data []byte, isPreset bool) {
|
||||||
t.Exec() <- func() { t.UnmarshalRecovery(data) }
|
broker.ToModel <- tracker.MsgToModel{Data: func() { t.UnmarshalRecovery(data) }}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,6 @@ func NewTracker(model *tracker.Model) *Tracker {
|
|||||||
Model: model,
|
Model: model,
|
||||||
|
|
||||||
filePathString: model.FilePath().String(),
|
filePathString: model.FilePath().String(),
|
||||||
execChan: make(chan func(), 1024),
|
|
||||||
}
|
}
|
||||||
t.Theme.Shaper = text.NewShaper(text.WithCollection(fontCollection))
|
t.Theme.Shaper = text.NewShaper(text.WithCollection(fontCollection))
|
||||||
t.PopupAlert = NewPopupAlert(model.Alerts(), t.Theme.Shaper)
|
t.PopupAlert = NewPopupAlert(model.Alerts(), t.Theme.Shaper)
|
||||||
@ -155,8 +154,6 @@ func (t *Tracker) Main() {
|
|||||||
}
|
}
|
||||||
case <-recoveryTicker.C:
|
case <-recoveryTicker.C:
|
||||||
t.SaveRecovery()
|
t.SaveRecovery()
|
||||||
case f := <-t.execChan:
|
|
||||||
f()
|
|
||||||
}
|
}
|
||||||
if t.Quitted() {
|
if t.Quitted() {
|
||||||
break
|
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() {
|
func (t *Tracker) WaitQuitted() {
|
||||||
t.quitWG.Wait()
|
t.quitWG.Wait()
|
||||||
}
|
}
|
||||||
@ -261,14 +254,14 @@ func (t *Tracker) explorerChooseFile(success func(io.ReadCloser), extensions ...
|
|||||||
t.Exploring = true
|
t.Exploring = true
|
||||||
go func() {
|
go func() {
|
||||||
file, err := t.Explorer.ChooseFile(extensions...)
|
file, err := t.Explorer.ChooseFile(extensions...)
|
||||||
t.Exec() <- func() {
|
t.Broker().ToModel <- tracker.MsgToModel{Data: func() {
|
||||||
t.Exploring = false
|
t.Exploring = false
|
||||||
if err == nil {
|
if err == nil {
|
||||||
success(file)
|
success(file)
|
||||||
} else {
|
} else {
|
||||||
t.Cancel().Do()
|
t.Cancel().Do()
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,14 +269,14 @@ func (t *Tracker) explorerCreateFile(success func(io.WriteCloser), filename stri
|
|||||||
t.Exploring = true
|
t.Exploring = true
|
||||||
go func() {
|
go func() {
|
||||||
file, err := t.Explorer.CreateFile(filename)
|
file, err := t.Explorer.CreateFile(filename)
|
||||||
t.Exec() <- func() {
|
t.Broker().ToModel <- tracker.MsgToModel{Data: func() {
|
||||||
t.Exploring = false
|
t.Exploring = false
|
||||||
if err == nil {
|
if err == nil {
|
||||||
success(file)
|
success(file)
|
||||||
} else {
|
} else {
|
||||||
t.Cancel().Do()
|
t.Cancel().Do()
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user