notification: Prevent Lua errors from causing unlimited timer events.

It now runs user defined code, so it can happen. Extra safety is
required.
This commit is contained in:
Emmanuel Lepage Vallee 2019-01-03 01:17:22 -05:00
parent 9df77e5c76
commit c691a0842b
1 changed files with 17 additions and 6 deletions

View File

@ -244,12 +244,12 @@ end
function notification:reset_timeout(new_timeout) function notification:reset_timeout(new_timeout)
if self.timer then self.timer:stop() end if self.timer then self.timer:stop() end
local timeout = new_timeout or self.timeout self.timeout = new_timeout or self.timeout
self:set_timeout(self, timeout)
self.timeout = timeout
if not self.timer.started then
self.timer:start() self.timer:start()
end end
end
function notification:set_id(new_id) function notification:set_id(new_id)
assert(self._private.id == nil, "Notification identifier can only be set once") assert(self._private.id == nil, "Notification identifier can only be set once")
@ -264,10 +264,21 @@ function notification:set_timeout(timeout)
if self.timer and self._private.timeout == timeout then return end if self.timer and self._private.timeout == timeout then return end
-- 0 == never
if timeout > 0 then if timeout > 0 then
local timer_die = timer { timeout = timeout } local timer_die = timer { timeout = timeout }
timer_die:connect_signal("timeout", function() die(cst.notification_closed_reason.expired) end)
if not self.suspended then --FIXME there's still a dependency loop to fix before it works timer_die:connect_signal("timeout", function()
pcall(die, cst.notification_closed_reason.expired)
-- Prevent infinite timers events on errors.
if timer_die.started then
timer_die:stop()
end
end)
--FIXME there's still a dependency loop to fix before it works
if not self.suspended then
timer_die:start() timer_die:start()
end end