feat(tracker, gioui): add confirmation dialogs before quit/new/load song

This should avoid accidentally losing all work by destroying window.
This commit is contained in:
vsariola
2021-04-16 22:42:51 +03:00
parent f3cf4a52ce
commit 7893c1d1ed
8 changed files with 181 additions and 23 deletions

View File

@ -36,7 +36,13 @@ func (t *Tracker) Run(w *app.Window) error {
case e := <-w.Events():
switch e := e.(type) {
case system.DestroyEvent:
return e.Err
if !t.TryQuit() {
// TODO: uh oh, there's no way of canceling the destroyevent in gioui? so we create a new window just to show the dialog
w = app.NewWindow(
app.Size(unit.Dp(800), unit.Dp(600)),
app.Title("Sointu Tracker"),
)
}
case key.Event:
if t.KeyEvent(w, e) {
w.Invalidate()
@ -52,6 +58,9 @@ func (t *Tracker) Run(w *app.Window) error {
e.Frame(gtx.Ops)
}
}
if t.quitted {
return nil
}
}
}
@ -61,7 +70,7 @@ func Main(audioContext sointu.AudioContext, synthService sointu.SynthService, sy
app.Size(unit.Dp(800), unit.Dp(600)),
app.Title("Sointu Tracker"),
)
t := New(audioContext, synthService, syncChannel)
t := New(audioContext, synthService, syncChannel, w)
defer t.Close()
if err := t.Run(w); err != nil {
fmt.Println(err)