From 12f15d106675ab2d651df1c74e9ce27c4814b51a Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sun, 1 Oct 2023 12:42:12 +0300 Subject: [PATCH] fix(tracker/gioui): make VSTI close event wait that gioui actually quit --- cmd/sointu-vsti/main.go | 1 + tracker/gioui/tracker.go | 26 +++++++++++++++++++------- tracker/gioui/tracker_not_plugin.go | 2 +- tracker/gioui/tracker_plugin.go | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/cmd/sointu-vsti/main.go b/cmd/sointu-vsti/main.go index 018999e..c688802 100644 --- a/cmd/sointu-vsti/main.go +++ b/cmd/sointu-vsti/main.go @@ -97,6 +97,7 @@ func init() { }, CloseFunc: func() { tracker.Quit(true) + tracker.WaitQuitted() }, } diff --git a/tracker/gioui/tracker.go b/tracker/gioui/tracker.go index b527818..713b82e 100644 --- a/tracker/gioui/tracker.go +++ b/tracker/gioui/tracker.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "sync" "time" "gioui.org/app" @@ -57,7 +58,8 @@ type Tracker struct { lastVolume tracker.Volume wavFilePath string - refresh chan struct{} + quitChannel chan struct{} + quitWG sync.WaitGroup errorChannel chan error quitted bool synthService sointu.SynthService @@ -126,7 +128,7 @@ func NewTracker(model *tracker.Model, synthService sointu.SynthService) *Tracker TrackHexCheckBox: new(widget.Bool), Menus: make([]Menu, 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}, BottomHorizontalSplit: &Split{Ratio: -.6}, @@ -148,6 +150,7 @@ func NewTracker(model *tracker.Model, synthService sointu.SynthService) *Tracker t.TrackEditor.Focus() t.SetOctave(4) t.ResetSong() + t.quitWG.Add(1) return t } @@ -176,8 +179,8 @@ mainloop: } } select { - case <-t.refresh: - w.Invalidate() + case <-t.quitChannel: + break mainloop case e := <-t.errorChannel: t.Alert.Update(e.Error(), Error, time.Second*5) w.Invalidate() @@ -209,9 +212,18 @@ mainloop: e.Frame(gtx.Ops) } } - if t.quitted { - break mainloop - } } w.Perform(system.ActionClose) + t.quitWG.Done() +} + +func (t *Tracker) sendQuit() { + select { + case t.quitChannel <- struct{}{}: + default: + } +} + +func (t *Tracker) WaitQuitted() { + t.quitWG.Wait() } diff --git a/tracker/gioui/tracker_not_plugin.go b/tracker/gioui/tracker_not_plugin.go index c3cd670..067f8e0 100644 --- a/tracker/gioui/tracker_not_plugin.go +++ b/tracker/gioui/tracker_not_plugin.go @@ -10,6 +10,6 @@ func (t *Tracker) Quit(forced bool) bool { t.ConfirmSongDialog.Visible = true return false } - t.quitted = true + t.sendQuit() return true } diff --git a/tracker/gioui/tracker_plugin.go b/tracker/gioui/tracker_plugin.go index 3b71828..1a50ec4 100644 --- a/tracker/gioui/tracker_plugin.go +++ b/tracker/gioui/tracker_plugin.go @@ -5,6 +5,6 @@ package gioui const CAN_QUIT = false func (t *Tracker) Quit(forced bool) bool { - t.quitted = forced + t.sendQuit() return forced }