fix(tracker/gioui): make VSTI close event wait that gioui actually quit

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2023-10-01 12:42:12 +03:00
parent e3c7d2cba4
commit 12f15d1066
4 changed files with 22 additions and 9 deletions

View File

@ -97,6 +97,7 @@ func init() {
}, },
CloseFunc: func() { CloseFunc: func() {
tracker.Quit(true) tracker.Quit(true)
tracker.WaitQuitted()
}, },
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"sync"
"time" "time"
"gioui.org/app" "gioui.org/app"
@ -57,7 +58,8 @@ type Tracker struct {
lastVolume tracker.Volume lastVolume tracker.Volume
wavFilePath string wavFilePath string
refresh chan struct{} quitChannel chan struct{}
quitWG sync.WaitGroup
errorChannel chan error errorChannel chan error
quitted bool quitted bool
synthService sointu.SynthService synthService sointu.SynthService
@ -126,7 +128,7 @@ func NewTracker(model *tracker.Model, synthService sointu.SynthService) *Tracker
TrackHexCheckBox: new(widget.Bool), TrackHexCheckBox: new(widget.Bool),
Menus: make([]Menu, 2), Menus: make([]Menu, 2),
MenuBar: make([]widget.Clickable, 2), MenuBar: make([]widget.Clickable, 2),
refresh: make(chan struct{}, 1), // use non-blocking sends; no need to queue extra ticks if one is queued already quitChannel: make(chan struct{}, 1), // use non-blocking sends; no need to queue extra ticks if one is queued already
TopHorizontalSplit: &Split{Ratio: -.6}, TopHorizontalSplit: &Split{Ratio: -.6},
BottomHorizontalSplit: &Split{Ratio: -.6}, BottomHorizontalSplit: &Split{Ratio: -.6},
@ -148,6 +150,7 @@ func NewTracker(model *tracker.Model, synthService sointu.SynthService) *Tracker
t.TrackEditor.Focus() t.TrackEditor.Focus()
t.SetOctave(4) t.SetOctave(4)
t.ResetSong() t.ResetSong()
t.quitWG.Add(1)
return t return t
} }
@ -176,8 +179,8 @@ mainloop:
} }
} }
select { select {
case <-t.refresh: case <-t.quitChannel:
w.Invalidate() break mainloop
case e := <-t.errorChannel: case e := <-t.errorChannel:
t.Alert.Update(e.Error(), Error, time.Second*5) t.Alert.Update(e.Error(), Error, time.Second*5)
w.Invalidate() w.Invalidate()
@ -209,9 +212,18 @@ mainloop:
e.Frame(gtx.Ops) e.Frame(gtx.Ops)
} }
} }
if t.quitted {
break mainloop
}
} }
w.Perform(system.ActionClose) w.Perform(system.ActionClose)
t.quitWG.Done()
}
func (t *Tracker) sendQuit() {
select {
case t.quitChannel <- struct{}{}:
default:
}
}
func (t *Tracker) WaitQuitted() {
t.quitWG.Wait()
} }

View File

@ -10,6 +10,6 @@ func (t *Tracker) Quit(forced bool) bool {
t.ConfirmSongDialog.Visible = true t.ConfirmSongDialog.Visible = true
return false return false
} }
t.quitted = true t.sendQuit()
return true return true
} }

View File

@ -5,6 +5,6 @@ package gioui
const CAN_QUIT = false const CAN_QUIT = false
func (t *Tracker) Quit(forced bool) bool { func (t *Tracker) Quit(forced bool) bool {
t.quitted = forced t.sendQuit()
return forced return forced
} }