diff --git a/internal/driver/mobile/app/darwin_desktop.go b/internal/driver/mobile/app/darwin_desktop.go index 2a7801bbc7..42a6f507df 100644 --- a/internal/driver/mobile/app/darwin_desktop.go +++ b/internal/driver/mobile/app/darwin_desktop.go @@ -160,8 +160,18 @@ func eventMouseDragged(x, y float32) { sendTouch(touch.TypeMove, x, y) } //export eventMouseEnd func eventMouseEnd(x, y float32) { sendTouch(touch.TypeEnd, x, y) } +var stopped = false + //export lifecycleDead -func lifecycleDead() { theApp.sendLifecycle(lifecycle.StageDead) } +func lifecycleDead() { + if stopped { + return + } + stopped = true + + theApp.sendLifecycle(lifecycle.StageDead) + theApp.events.Close() +} //export eventKey func eventKey(runeVal int32, direction uint8, code uint16, flags uint32) { diff --git a/internal/driver/mobile/app/darwin_desktop.m b/internal/driver/mobile/app/darwin_desktop.m index b1b5c2bd36..ab97f108c0 100644 --- a/internal/driver/mobile/app/darwin_desktop.m +++ b/internal/driver/mobile/app/darwin_desktop.m @@ -136,7 +136,7 @@ - (void)applicationWillUnhide:(NSNotification *)notification { } - (void)windowWillClose:(NSNotification *)notification { - lifecycleAlive(); + lifecycleDead(); } - (BOOL)acceptsFirstResponder { diff --git a/internal/driver/mobile/driver.go b/internal/driver/mobile/driver.go index 9f6235f846..235a3ef0c2 100644 --- a/internal/driver/mobile/driver.go +++ b/internal/driver/mobile/driver.go @@ -165,7 +165,16 @@ func (d *driver) Run() { draw := time.NewTicker(time.Second / 60) defer func() { l := fyne.CurrentApp().Lifecycle().(*intapp.Lifecycle) - l.WaitForEvents() + + // exhaust the event queue + go func() { + l.WaitForEvents() + d.queuedFuncs.Close() + }() + for fn := range d.queuedFuncs.Out() { + fn() + } + l.DestroyEventQueue() }()