2024-07-19 22:55:31 +02:00
|
|
|
local CheckButton = require("ui/widget/checkbutton")
|
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2021-09-25 19:59:45 +02:00
|
|
|
local DateTimeWidget = require("ui/widget/datetimewidget")
|
2024-07-19 22:55:31 +02:00
|
|
|
local Event = require("ui/event")
|
2017-03-26 21:42:58 -07:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2021-08-22 00:34:09 +02:00
|
|
|
local logger = require("logger")
|
2022-11-17 05:53:35 +01:00
|
|
|
local datetime = require("datetime")
|
2024-07-19 22:55:31 +02:00
|
|
|
local time = require("ui/time")
|
2017-03-26 21:42:58 -07:00
|
|
|
local _ = require("gettext")
|
2019-09-04 15:36:13 +02:00
|
|
|
local T = require("ffi/util").template
|
2017-03-26 21:42:58 -07:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 02:14:48 +02:00
|
|
|
local ReadTimer = WidgetContainer:extend{
|
2017-03-26 21:42:58 -07:00
|
|
|
name = "readtimer",
|
|
|
|
|
time = 0, -- The expected time of alarm if enabled, or 0.
|
2022-12-11 16:51:16 +08:00
|
|
|
last_interval_time = 0,
|
2017-03-26 21:42:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ReadTimer:init()
|
2024-07-19 22:55:31 +02:00
|
|
|
self.timer_symbol = "\u{23F2}" -- ⏲ timer symbol
|
|
|
|
|
self.timer_letter = "T"
|
|
|
|
|
|
2017-03-26 21:42:58 -07:00
|
|
|
self.alarm_callback = function()
|
2021-08-19 18:56:34 +02:00
|
|
|
-- Don't do anything if we were unscheduled
|
|
|
|
|
if self.time == 0 then return end
|
|
|
|
|
|
2017-03-26 21:42:58 -07:00
|
|
|
self.time = 0
|
2022-12-11 16:51:16 +08:00
|
|
|
local tip_text = _("Time is up")
|
|
|
|
|
local confirm_box
|
|
|
|
|
-- only interval support repeat
|
|
|
|
|
if self.last_interval_time > 0 then
|
|
|
|
|
logger.dbg("can_repeat, show confirm_box")
|
|
|
|
|
confirm_box = ConfirmBox:new{
|
|
|
|
|
text = tip_text,
|
|
|
|
|
ok_text = _("Repeat"),
|
|
|
|
|
ok_callback = function()
|
|
|
|
|
logger.dbg("Schedule a new time:", self.last_interval_time)
|
|
|
|
|
UIManager:close(confirm_box)
|
|
|
|
|
self:rescheduleIn(self.last_interval_time)
|
|
|
|
|
end,
|
|
|
|
|
cancel_text = _("Done"),
|
|
|
|
|
cancel_callback = function ()
|
|
|
|
|
self.last_interval_time = 0
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
UIManager:show(confirm_box)
|
|
|
|
|
else
|
|
|
|
|
logger.dbg("can`t_repeat, show infomessage")
|
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
|
text = tip_text,
|
|
|
|
|
})
|
|
|
|
|
end
|
2017-03-26 21:42:58 -07:00
|
|
|
end
|
2024-07-19 22:55:31 +02:00
|
|
|
|
|
|
|
|
self.additional_header_content_func = function()
|
|
|
|
|
if self:scheduled() then
|
|
|
|
|
local hours, minutes, dummy = self:remainingTime(1)
|
|
|
|
|
local timer_info = string.format("%02d:%02d", hours, minutes)
|
|
|
|
|
return self.timer_symbol .. timer_info
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self.additional_footer_content_func = function()
|
|
|
|
|
if self:scheduled() then
|
|
|
|
|
local item_prefix = self.ui.view.footer.settings.item_prefix
|
|
|
|
|
local hours, minutes, dummy = self:remainingTime(1)
|
|
|
|
|
local timer_info = string.format("%02d:%02d", hours, minutes)
|
|
|
|
|
|
|
|
|
|
if item_prefix == "icons" then
|
|
|
|
|
return self.timer_symbol .. " " .. timer_info
|
|
|
|
|
elseif item_prefix == "compact_items" then
|
|
|
|
|
return self.timer_symbol .. timer_info
|
|
|
|
|
else
|
|
|
|
|
return self.timer_letter .. ": " .. timer_info
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self.show_value_in_header = G_reader_settings:readSetting("readtimer_show_value_in_header")
|
|
|
|
|
self.show_value_in_footer = G_reader_settings:readSetting("readtimer_show_value_in_footer")
|
|
|
|
|
|
|
|
|
|
if self.show_value_in_header then
|
|
|
|
|
self:addAdditionalHeaderContent()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if self.show_value_in_footer then
|
|
|
|
|
self:addAdditionalFooterContent()
|
|
|
|
|
end
|
|
|
|
|
|
2017-03-26 21:42:58 -07:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-19 22:55:31 +02:00
|
|
|
function ReadTimer:update_status_bars(seconds)
|
|
|
|
|
if self.show_value_in_header then
|
|
|
|
|
UIManager:broadcastEvent(Event:new("UpdateHeader"))
|
|
|
|
|
end
|
|
|
|
|
if self.show_value_in_footer then
|
2024-08-28 15:22:55 +02:00
|
|
|
UIManager:broadcastEvent(Event:new("RefreshAdditionalContent"))
|
2024-07-19 22:55:31 +02:00
|
|
|
end
|
|
|
|
|
-- if seconds schedule 1ms later
|
|
|
|
|
if seconds and seconds >= 0 then
|
|
|
|
|
UIManager:scheduleIn(math.max(math.floor(seconds)%60, 0.001), self.update_status_bars, self)
|
|
|
|
|
elseif seconds and seconds < 0 and self:scheduled() then
|
|
|
|
|
UIManager:scheduleIn(math.max(math.floor(self:remaining())%60, 0.001), self.update_status_bars, self)
|
|
|
|
|
else
|
|
|
|
|
UIManager:scheduleIn(60, self.update_status_bars, self)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-03-26 21:42:58 -07:00
|
|
|
function ReadTimer:scheduled()
|
|
|
|
|
return self.time ~= 0
|
|
|
|
|
end
|
|
|
|
|
|
2021-08-22 00:34:09 +02:00
|
|
|
function ReadTimer:remaining()
|
2017-03-26 21:42:58 -07:00
|
|
|
if self:scheduled() then
|
2024-07-19 22:55:31 +02:00
|
|
|
-- Resolution: time.now() subsecond, os.time() two seconds
|
|
|
|
|
local remaining_s = time.to_s(self.time - time.now())
|
|
|
|
|
if remaining_s > 0 then
|
|
|
|
|
return remaining_s
|
2021-08-19 18:56:34 +02:00
|
|
|
else
|
|
|
|
|
return 0
|
|
|
|
|
end
|
2017-03-26 21:42:58 -07:00
|
|
|
else
|
|
|
|
|
return math.huge
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-19 22:55:31 +02:00
|
|
|
-- can round
|
|
|
|
|
function ReadTimer:remainingTime(round)
|
2018-05-19 23:29:16 +02:00
|
|
|
if self:scheduled() then
|
2021-08-22 00:34:09 +02:00
|
|
|
local remainder = self:remaining()
|
2024-07-19 22:55:31 +02:00
|
|
|
if round then
|
|
|
|
|
if round < 0 then -- round down
|
|
|
|
|
remainder = remainder - 59
|
|
|
|
|
elseif round == 0 then
|
|
|
|
|
remainder = remainder + 30
|
|
|
|
|
else -- round up
|
|
|
|
|
remainder = remainder + 59
|
|
|
|
|
end
|
|
|
|
|
remainder = math.floor(remainder * (1/60)) * 60
|
|
|
|
|
end
|
|
|
|
|
|
2022-10-10 22:21:27 +02:00
|
|
|
local hours = math.floor(remainder * (1/3600))
|
|
|
|
|
local minutes = math.floor(remainder % 3600 * (1/60))
|
2021-08-22 00:34:09 +02:00
|
|
|
local seconds = math.floor(remainder % 60)
|
|
|
|
|
return hours, minutes, seconds
|
2018-05-19 23:29:16 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-19 22:55:31 +02:00
|
|
|
function ReadTimer:addAdditionalHeaderContent()
|
2024-08-03 16:38:56 +02:00
|
|
|
if self.ui.crelistener then
|
|
|
|
|
self.ui.crelistener:addAdditionalHeaderContent(self.additional_header_content_func)
|
|
|
|
|
self:update_status_bars(-1)
|
|
|
|
|
end
|
2024-07-19 22:55:31 +02:00
|
|
|
end
|
|
|
|
|
function ReadTimer:addAdditionalFooterContent()
|
2024-08-03 16:38:56 +02:00
|
|
|
if self.ui.view then
|
|
|
|
|
self.ui.view.footer:addAdditionalFooterContent(self.additional_footer_content_func)
|
|
|
|
|
self:update_status_bars(-1)
|
|
|
|
|
end
|
2024-07-19 22:55:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReadTimer:removeAdditionalHeaderContent()
|
2024-08-03 16:38:56 +02:00
|
|
|
if self.ui.crelistener then
|
|
|
|
|
self.ui.crelistener:removeAdditionalHeaderContent(self.additional_header_content_func)
|
|
|
|
|
self:update_status_bars(-1)
|
|
|
|
|
UIManager:broadcastEvent(Event:new("UpdateHeader"))
|
|
|
|
|
end
|
2024-07-19 22:55:31 +02:00
|
|
|
end
|
2024-08-03 16:38:56 +02:00
|
|
|
|
2024-07-19 22:55:31 +02:00
|
|
|
function ReadTimer:removeAdditionalFooterContent()
|
2024-08-03 16:38:56 +02:00
|
|
|
if self.ui.view then
|
|
|
|
|
self.ui.view.footer:removeAdditionalFooterContent(self.additional_footer_content_func)
|
|
|
|
|
self:update_status_bars(-1)
|
|
|
|
|
UIManager:broadcastEvent(Event:new("UpdateFooter", true))
|
|
|
|
|
end
|
2024-07-19 22:55:31 +02:00
|
|
|
end
|
|
|
|
|
|
2017-03-26 21:42:58 -07:00
|
|
|
function ReadTimer:unschedule()
|
|
|
|
|
if self:scheduled() then
|
|
|
|
|
UIManager:unschedule(self.alarm_callback)
|
|
|
|
|
self.time = 0
|
|
|
|
|
end
|
2024-07-19 22:55:31 +02:00
|
|
|
UIManager:unschedule(self.update_status_bars, self)
|
2017-03-26 21:42:58 -07:00
|
|
|
end
|
|
|
|
|
|
2021-08-22 00:34:09 +02:00
|
|
|
function ReadTimer:rescheduleIn(seconds)
|
2024-07-19 22:55:31 +02:00
|
|
|
-- Resolution: time.now() subsecond, os.time() two seconds
|
|
|
|
|
self.time = time.now() + time.s(seconds)
|
2021-08-22 00:34:09 +02:00
|
|
|
UIManager:scheduleIn(seconds, self.alarm_callback)
|
2024-07-19 22:55:31 +02:00
|
|
|
if self.show_value_in_header or self.show_value_in_footer then
|
|
|
|
|
self:update_status_bars(seconds)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReadTimer:addCheckboxes(widget)
|
|
|
|
|
local checkbox_header = CheckButton:new{
|
|
|
|
|
text = _("Show timer in alt status bar"),
|
|
|
|
|
checked = self.show_value_in_header,
|
|
|
|
|
parent = widget,
|
|
|
|
|
callback = function()
|
|
|
|
|
self.show_value_in_header = not self.show_value_in_header
|
|
|
|
|
G_reader_settings:saveSetting("readtimer_show_value_in_header", self.show_value_in_header)
|
|
|
|
|
if self.show_value_in_header then
|
|
|
|
|
self:addAdditionalHeaderContent()
|
|
|
|
|
else
|
|
|
|
|
self:removeAdditionalHeaderContent()
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
local checkbox_footer = CheckButton:new{
|
|
|
|
|
text = _("Show timer in status bar"),
|
|
|
|
|
checked = self.show_value_in_footer,
|
|
|
|
|
parent = widget,
|
|
|
|
|
callback = function()
|
|
|
|
|
self.show_value_in_footer = not self.show_value_in_footer
|
|
|
|
|
G_reader_settings:saveSetting("readtimer_show_value_in_footer", self.show_value_in_footer)
|
|
|
|
|
if self.show_value_in_footer then
|
|
|
|
|
self:addAdditionalFooterContent()
|
|
|
|
|
else
|
|
|
|
|
self:removeAdditionalFooterContent()
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
widget:addWidget(checkbox_header)
|
|
|
|
|
widget:addWidget(checkbox_footer)
|
2021-08-22 00:34:09 +02:00
|
|
|
end
|
|
|
|
|
|
2017-03-26 21:42:58 -07:00
|
|
|
function ReadTimer:addToMainMenu(menu_items)
|
|
|
|
|
menu_items.read_timer = {
|
2017-08-01 20:40:22 +02:00
|
|
|
text_func = function()
|
|
|
|
|
if self:scheduled() then
|
2021-08-22 00:34:09 +02:00
|
|
|
local user_duration_format = G_reader_settings:readSetting("duration_format")
|
|
|
|
|
return T(_("Read timer (%1)"),
|
2022-11-17 05:53:35 +01:00
|
|
|
datetime.secondsToClockDuration(user_duration_format, self:remaining(), false))
|
2017-08-01 20:40:22 +02:00
|
|
|
else
|
|
|
|
|
return _("Read timer")
|
|
|
|
|
end
|
|
|
|
|
end,
|
2017-03-26 21:42:58 -07:00
|
|
|
checked_func = function()
|
|
|
|
|
return self:scheduled()
|
|
|
|
|
end,
|
2017-10-01 18:15:59 +02:00
|
|
|
sub_item_table = {
|
|
|
|
|
{
|
2021-09-25 19:59:45 +02:00
|
|
|
text = _("Set time"),
|
2018-09-04 23:55:58 +02:00
|
|
|
keep_menu_open = true,
|
|
|
|
|
callback = function(touchmenu_instance)
|
2017-10-01 18:15:59 +02:00
|
|
|
local now_t = os.date("*t")
|
|
|
|
|
local curr_hour = now_t.hour
|
|
|
|
|
local curr_min = now_t.min
|
2021-09-25 19:59:45 +02:00
|
|
|
local time_widget = DateTimeWidget:new{
|
2017-10-01 18:15:59 +02:00
|
|
|
hour = curr_hour,
|
|
|
|
|
min = curr_min,
|
2021-09-25 19:59:45 +02:00
|
|
|
ok_text = _("Set alarm"),
|
|
|
|
|
title_text = _("New alarm"),
|
|
|
|
|
info_text = _("Enter a time in hours and minutes."),
|
2024-07-19 22:55:31 +02:00
|
|
|
callback = function(alarm_time)
|
2022-12-11 16:51:16 +08:00
|
|
|
self.last_interval_time = 0
|
2017-10-01 18:15:59 +02:00
|
|
|
self:unschedule()
|
2021-08-22 00:34:09 +02:00
|
|
|
local then_t = now_t
|
2024-07-19 22:55:31 +02:00
|
|
|
then_t.hour = alarm_time.hour
|
|
|
|
|
then_t.min = alarm_time.min
|
2021-08-22 00:34:09 +02:00
|
|
|
then_t.sec = 0
|
|
|
|
|
local seconds = os.difftime(os.time(then_t), os.time())
|
2025-01-05 17:04:10 +01:00
|
|
|
if seconds <= 0 then
|
|
|
|
|
then_t.day = then_t.day + 1
|
|
|
|
|
seconds = os.difftime(os.time(then_t), os.time())
|
2017-10-01 18:15:59 +02:00
|
|
|
end
|
2025-01-05 17:04:10 +01:00
|
|
|
self:rescheduleIn(seconds)
|
|
|
|
|
local user_duration_format = G_reader_settings:readSetting("duration_format")
|
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
|
-- @translators %1:%2 is a clock time (HH:MM), %3 is a duration
|
|
|
|
|
text = T(_("Timer set for %1:%2.\n\nThat's %3 from now."),
|
|
|
|
|
string.format("%02d", alarm_time.hour), string.format("%02d", alarm_time.min),
|
|
|
|
|
datetime.secondsToClockDuration(user_duration_format, seconds, false)),
|
|
|
|
|
timeout = 5,
|
|
|
|
|
})
|
|
|
|
|
if touchmenu_instance then touchmenu_instance:updateItems() end
|
2017-10-01 18:15:59 +02:00
|
|
|
end
|
|
|
|
|
}
|
2024-07-19 22:55:31 +02:00
|
|
|
self:addCheckboxes(time_widget)
|
2017-10-01 18:15:59 +02:00
|
|
|
UIManager:show(time_widget)
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-09-25 19:59:45 +02:00
|
|
|
text = _("Set interval"),
|
2018-09-04 23:55:58 +02:00
|
|
|
keep_menu_open = true,
|
|
|
|
|
callback = function(touchmenu_instance)
|
2018-05-19 23:29:16 +02:00
|
|
|
local remain_time = {}
|
|
|
|
|
local remain_hours, remain_minutes = self:remainingTime()
|
|
|
|
|
if not remain_hours and not remain_minutes then
|
|
|
|
|
remain_time = G_reader_settings:readSetting("reader_timer_remain_time")
|
|
|
|
|
if remain_time then
|
|
|
|
|
remain_hours = remain_time[1]
|
|
|
|
|
remain_minutes = remain_time[2]
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-09-25 19:59:45 +02:00
|
|
|
local time_widget = DateTimeWidget:new{
|
2018-05-19 23:29:16 +02:00
|
|
|
hour = remain_hours or 0,
|
|
|
|
|
min = remain_minutes or 0,
|
2017-10-01 18:15:59 +02:00
|
|
|
hour_max = 17,
|
|
|
|
|
ok_text = _("Set timer"),
|
2021-09-25 19:59:45 +02:00
|
|
|
title_text = _("Set reader timer"),
|
|
|
|
|
info_text = _("Enter a time in hours and minutes."),
|
2024-07-19 22:55:31 +02:00
|
|
|
callback = function(timer_time)
|
2017-10-01 18:15:59 +02:00
|
|
|
self:unschedule()
|
2024-07-19 22:55:31 +02:00
|
|
|
local seconds = timer_time.hour * 3600 + timer_time.min * 60
|
2017-10-01 18:15:59 +02:00
|
|
|
if seconds > 0 then
|
2022-12-11 16:51:16 +08:00
|
|
|
self.last_interval_time = seconds
|
2021-08-22 00:34:09 +02:00
|
|
|
self:rescheduleIn(seconds)
|
|
|
|
|
local user_duration_format = G_reader_settings:readSetting("duration_format")
|
2017-10-01 18:15:59 +02:00
|
|
|
UIManager:show(InfoMessage:new{
|
2021-08-22 00:34:09 +02:00
|
|
|
-- @translators This is a duration
|
|
|
|
|
text = T(_("Timer will expire in %1."),
|
2022-11-17 05:53:35 +01:00
|
|
|
datetime.secondsToClockDuration(user_duration_format, seconds, true)),
|
2017-10-07 16:19:40 +02:00
|
|
|
timeout = 5,
|
2017-10-01 18:15:59 +02:00
|
|
|
})
|
2024-07-19 22:55:31 +02:00
|
|
|
remain_time = {timer_time.hour, timer_time.min}
|
2018-05-19 23:29:16 +02:00
|
|
|
G_reader_settings:saveSetting("reader_timer_remain_time", remain_time)
|
2024-07-19 22:55:31 +02:00
|
|
|
if touchmenu_instance then touchmenu_instance:updateItems() end
|
2017-10-01 18:15:59 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
}
|
2024-07-19 22:55:31 +02:00
|
|
|
|
|
|
|
|
self:addCheckboxes(time_widget)
|
2017-10-01 18:15:59 +02:00
|
|
|
UIManager:show(time_widget)
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text = _("Stop timer"),
|
2018-09-04 23:55:58 +02:00
|
|
|
keep_menu_open = true,
|
2017-10-01 18:15:59 +02:00
|
|
|
enabled_func = function()
|
|
|
|
|
return self:scheduled()
|
2017-03-26 21:42:58 -07:00
|
|
|
end,
|
2018-09-04 23:55:58 +02:00
|
|
|
callback = function(touchmenu_instance)
|
2022-12-11 16:51:16 +08:00
|
|
|
self.last_interval_time = 0
|
2017-03-26 21:42:58 -07:00
|
|
|
self:unschedule()
|
2018-09-04 23:55:58 +02:00
|
|
|
touchmenu_instance:updateItems()
|
2017-03-26 21:42:58 -07:00
|
|
|
end,
|
2017-10-01 18:15:59 +02:00
|
|
|
},
|
|
|
|
|
},
|
2017-03-26 21:42:58 -07:00
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2021-08-22 00:34:09 +02:00
|
|
|
-- The UI ticks on a MONOTONIC time domain, while this plugin deals with REAL wall clock time.
|
2021-08-19 18:56:34 +02:00
|
|
|
function ReadTimer:onResume()
|
2021-08-22 00:34:09 +02:00
|
|
|
if self:scheduled() then
|
|
|
|
|
logger.dbg("ReadTimer: onResume with an active timer")
|
|
|
|
|
local remainder = self:remaining()
|
|
|
|
|
|
|
|
|
|
if remainder == 0 then
|
|
|
|
|
-- Make sure we fire the alarm right away if it expired during suspend...
|
|
|
|
|
self:alarm_callback()
|
|
|
|
|
self:unschedule()
|
|
|
|
|
else
|
|
|
|
|
-- ...and that we re-schedule the timer against the REAL time if it's still ticking.
|
|
|
|
|
logger.dbg("ReadTimer: Rescheduling in", remainder, "seconds")
|
|
|
|
|
self:unschedule()
|
|
|
|
|
self:rescheduleIn(remainder)
|
|
|
|
|
end
|
|
|
|
|
|
2021-08-19 18:56:34 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-03-26 21:42:58 -07:00
|
|
|
return ReadTimer
|