From ae4dacb2ee5d201eabf0b3edc8e06b94b953e215 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 13 Jan 2025 11:30:03 +0000 Subject: [PATCH 1/2] Properly exhaust mobile event queue so it can close Fixes #5401 --- internal/driver/mobile/driver.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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() }() From d6d65dc54c33594fcd1544a3bfbb5ad9e83314d5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 13 Jan 2025 11:34:28 +0000 Subject: [PATCH 2/2] match X11 and close down our app if the simulator window is closed --- internal/driver/mobile/app/darwin_desktop.go | 12 +++++++++++- internal/driver/mobile/app/darwin_desktop.m | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) 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 {