3
0
mirror of https://github.com/britzl/monarch.git synced 2025-09-27 18:12:22 +02:00

Make sure focus_lost messages is received

Fixes #42
This commit is contained in:
Björn Ritzl
2019-03-17 21:50:01 +01:00
parent b57609f061
commit 05f91dd763
8 changed files with 278 additions and 1 deletions

View File

@@ -67,6 +67,16 @@ local function pcallfn(fn, ...)
if not ok then print(err) end
end
end
local function cowait(delay)
local co = coroutine.running()
assert(co, "You must run this form within a coroutine")
timer.delay(delay, false, function()
coroutine.resume(co)
end)
coroutine.yield()
end
local function notify_transition_listeners(message_id, message)
log("notify_transition_listeners()", message_id)
for _,url in pairs(transition_listeners) do
@@ -364,6 +374,11 @@ local function focus_lost(screen, next_screen)
log("focus_lost()", screen.id)
if screen.focus_url then
msg.post(screen.focus_url, M.FOCUS.LOST, { id = next_screen and next_screen.id })
-- if there's no transition on the screen losing focus and it gets
-- unloaded this will happen before the focus_lost message reaches
-- the focus_url
-- we add a delay to ensure the message queue has time to be processed
cowait(0)
else
log("focus_lost() no focus url - ignoring")
end