Widgets: Unschedule timeouts on early close (#11126)

Affects Notification, InfoMessage & QRMessage

Includes a drive-by fix for Trapper interactions that have been broken for... a long while ;).
This commit is contained in:
NiLuJe
2023-11-22 18:58:31 +01:00
committed by GitHub
parent bc7ea8602e
commit bba48fc1bf
4 changed files with 53 additions and 27 deletions

View File

@@ -57,6 +57,7 @@ local Notification = InputContainer:extend{
margin = Size.margin.default,
padding = Size.padding.default,
timeout = 2, -- default to 2 seconds
_timeout_func = nil,
toast = true, -- closed on any event, and let the event propagate to next top widget
_shown_list = {}, -- actual static class member, array of stacked notifications (value is show (well, init) time or false).
@@ -200,6 +201,11 @@ function Notification:onCloseWidget()
UIManager:setDirty(nil, function()
return "ui", self.frame.dimen
end)
-- If we were closed early, drop the scheduled timeout
if self._timeout_func then
UIManager:unschedule(self._timeout_func)
self._timeout_func = nil
end
end
function Notification:onShow()
@@ -207,7 +213,11 @@ function Notification:onShow()
return "ui", self.frame.dimen
end)
if self.timeout then
UIManager:scheduleIn(self.timeout, function() UIManager:close(self) end)
self._timeout_func = function()
self._timeout_func = nil
UIManager:close(self)
end
UIManager:scheduleIn(self.timeout, self._timeout_func)
end
if #self._past_messages >= MAX_NB_PAST_MESSAGES then