diff --git a/apps/gophers/main.go b/apps/gophers/main.go index bb6f5ff2..2117844b 100644 --- a/apps/gophers/main.go +++ b/apps/gophers/main.go @@ -185,7 +185,7 @@ func (a *App) run() error { a.w.Profiling = *stats ops := new(ui.Ops) var lastMallocs uint64 - for a.w.IsAlive() { + for { select { case users := <-a.updateUsers: a.users = users @@ -219,6 +219,9 @@ func (a *App) run() error { a.ctxCancel = nil } } + if e.Stage == app.StageDead { + return a.w.Err() + } case *app.CommandEvent: switch e.Type { case app.CommandBack: @@ -253,7 +256,6 @@ func (a *App) run() error { } } } - return a.w.Err() } func newApp(w *app.Window) *App { diff --git a/apps/hello/hello.go b/apps/hello/hello.go index cfd59389..656632e9 100644 --- a/apps/hello/hello.go +++ b/apps/hello/hello.go @@ -32,12 +32,16 @@ func main() { func init() { go func() { for w := range app.Windows() { - go loop(w) + go func() { + if err := loop(w); err != nil { + log.Fatal(err) + } + }() } }() } -func loop(w *app.Window) { +func loop(w *app.Window) error { regular, err := sfnt.Parse(goregular.TTF) if err != nil { panic("failed to load font") @@ -48,9 +52,13 @@ func loop(w *app.Window) { face := faces.For(regular, ui.Sp(72)) message := "Hello, Gio" ops := new(ui.Ops) - for w.IsAlive() { + for { e := <-w.Events() switch e := e.(type) { + case app.StageEvent: + if e.Stage == app.StageDead { + return w.Err() + } case app.DrawEvent: cfg = e.Config cs := layout.ExactConstraints(w.Size()) @@ -63,7 +71,4 @@ func loop(w *app.Window) { faces.Frame() } } - if err := w.Err(); err != nil { - log.Fatal(err) - } }