mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #13399 from hius07/profiles-auto-exec-time
Profiles: auto-exec time interval
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local DataStorage = require("datastorage")
|
||||
local DateTimeWidget = require("ui/widget/datetimewidget")
|
||||
local Device = require("device")
|
||||
local Dispatcher = require("dispatcher")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
@@ -157,6 +158,56 @@ function Profiles:getSubMenuItems()
|
||||
self.data[k].settings.auto_exec_ask = not v.settings.auto_exec_ask and true or nil
|
||||
self.updated = true
|
||||
end,
|
||||
},
|
||||
{
|
||||
text_func = function()
|
||||
local interval = v.settings.auto_exec_time_interval
|
||||
return _("Execute within time interval") ..
|
||||
(interval and ": " .. interval[1] .. " - " .. interval[2] or "")
|
||||
end,
|
||||
checked_func = function()
|
||||
return v.settings.auto_exec_time_interval and true
|
||||
end,
|
||||
sub_item_table_func = function()
|
||||
local sub_sub_item_table = {}
|
||||
local points = { _("start: "), _("end: ") }
|
||||
local titles = { _("Set start time"), _("Set end time") }
|
||||
for i, point in ipairs(points) do
|
||||
sub_sub_item_table[i] = {
|
||||
text_func = function()
|
||||
local interval = v.settings.auto_exec_time_interval
|
||||
return point .. (interval and interval[i] or "--:--")
|
||||
end,
|
||||
keep_menu_open = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local interval = v.settings.auto_exec_time_interval
|
||||
local time_str = interval and interval[i] or os.date("%H:%M")
|
||||
local h, m = time_str:match("(%d+):(%d+)")
|
||||
UIManager:show(DateTimeWidget:new{
|
||||
title_text = titles[i],
|
||||
info_text = _("Enter time in hours and minutes."),
|
||||
hour = tonumber(h),
|
||||
min = tonumber(m),
|
||||
ok_text = _("Set time"),
|
||||
callback = function(new_time)
|
||||
local str = string.format("%02d:%02d", new_time.hour, new_time.min)
|
||||
if interval then
|
||||
v.settings.auto_exec_time_interval[i] = str
|
||||
else
|
||||
v.settings.auto_exec_time_interval = { str, str }
|
||||
end
|
||||
touchmenu_instance:updateItems()
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
end
|
||||
return sub_sub_item_table
|
||||
end,
|
||||
hold_callback = function(touchmenu_instance)
|
||||
v.settings.auto_exec_time_interval = nil
|
||||
touchmenu_instance:updateItems()
|
||||
end,
|
||||
separator = true,
|
||||
},
|
||||
self:genAutoExecMenuItem(_("on KOReader start"), "Start", k),
|
||||
@@ -937,6 +988,17 @@ end
|
||||
function Profiles:executeAutoExec(profile_name, event)
|
||||
local profile = self.data[profile_name]
|
||||
if profile == nil then return end
|
||||
if profile.settings.auto_exec_time_interval then
|
||||
local now = os.date("%H:%M")
|
||||
local start_time, end_time = unpack(profile.settings.auto_exec_time_interval)
|
||||
local do_execute
|
||||
if start_time < end_time then
|
||||
do_execute = start_time <= now and now <= end_time
|
||||
else
|
||||
do_execute = (start_time <= now and now <= "23:59") or ("00:00" <= now and now <= end_time)
|
||||
end
|
||||
if not do_execute then return end
|
||||
end
|
||||
if profile.settings.auto_exec_ask then
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Do you want to execute profile?") .. "\n\n" .. profile_name .. "\n",
|
||||
|
||||
Reference in New Issue
Block a user