2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00
koreader/frontend/ui/elements/screensaver_menu.lua

169 lines
7.6 KiB
Lua
Raw Normal View History

local Screensaver = require("ui/screensaver")
local lfs = require("libs/libkoreader-lfs")
local _ = require("gettext")
local T = require("ffi/util").template
local function hasLastFile()
local last_file = G_reader_settings:readSetting("lastfile")
return last_file and lfs.attributes(last_file, "mode") == "file"
end
local function isReaderProgressEnabled()
return Screensaver.getReaderProgress ~= nil and hasLastFile()
end
local function genMenuItem(text, setting, value, enabled_func, separator)
return {
text = text,
enabled_func = enabled_func,
checked_func = function()
return G_reader_settings:readSetting(setting) == value
end,
callback = function()
G_reader_settings:saveSetting(setting, value)
end,
radio = true,
separator = separator,
}
end
return {
{
2024-04-08 20:47:17 +00:00
text = _("Wallpaper"),
sub_item_table = {
2024-04-08 20:47:17 +00:00
genMenuItem(_("Show book cover on sleep screen"), "screensaver_type", "cover", hasLastFile),
genMenuItem(_("Show custom image or cover on sleep screen"), "screensaver_type", "document_cover"),
genMenuItem(_("Show random image from folder on sleep screen"), "screensaver_type", "random_image"),
genMenuItem(_("Show reading progress on sleep screen"), "screensaver_type", "readingprogress", isReaderProgressEnabled),
genMenuItem(_("Show book status on sleep screen"), "screensaver_type", "bookstatus", hasLastFile),
genMenuItem(_("Leave screen as-is"), "screensaver_type", "disable", nil, true),
separator = true,
{
2024-04-08 20:47:17 +00:00
text = _("Border fill"),
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "cover"
or G_reader_settings:readSetting("screensaver_type") == "document_cover"
or G_reader_settings:readSetting("screensaver_type") == "random_image"
end,
sub_item_table = {
2024-04-08 20:47:17 +00:00
genMenuItem(_("Black fill"), "screensaver_img_background", "black"),
genMenuItem(_("White fill"), "screensaver_img_background", "white"),
2024-04-09 10:53:30 +00:00
genMenuItem(_("No fill"), "screensaver_img_background", "none", nil, true),
-- separator
{
text_func = function()
local percentage = G_reader_settings:readSetting("screensaver_stretch_limit_percentage")
if G_reader_settings:isTrue("screensaver_stretch_images") and percentage then
return T(_("Stretch to fit screen (with limit: %1 %)"), percentage)
end
2024-04-08 20:47:17 +00:00
return _("Stretch cover to fit screen")
end,
checked_func = function()
return G_reader_settings:isTrue("screensaver_stretch_images")
end,
callback = function(touchmenu_instance)
Screensaver:setStretchLimit(touchmenu_instance)
end,
},
},
},
{
2024-04-09 10:53:30 +00:00
text = _("Postpone screen update after wake-up"),
2024-04-08 20:47:17 +00:00
sub_item_table = {
genMenuItem(_("Never"), "screensaver_delay", "disable"),
2024-04-08 20:47:17 +00:00
genMenuItem(_("1 second"), "screensaver_delay", "1"),
genMenuItem(_("3 seconds"), "screensaver_delay", "3"),
genMenuItem(_("5 seconds"), "screensaver_delay", "5"),
genMenuItem(_("Until a tap"), "screensaver_delay", "tap"),
genMenuItem(_("Until 'exit sleep screen' gesture"), "screensaver_delay", "gesture"),
},
},
{
text = _("Custom images"),
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "random_image"
or G_reader_settings:readSetting("screensaver_type") == "document_cover"
end,
sub_item_table = {
{
text = _("Choose image or document cover"),
2024-04-08 20:47:17 +00:00
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "document_cover"
end,
2024-04-08 20:47:17 +00:00
keep_menu_open = true,
callback = function()
2024-04-08 20:47:17 +00:00
Screensaver:chooseFile()
end,
},
2024-04-08 20:47:17 +00:00
{
text = _("Choose random image folder"),
2024-04-08 20:47:17 +00:00
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "random_image"
end,
keep_menu_open = true,
callback = function()
Screensaver:chooseFolder()
end,
},
},
},
},
},
{
text = _("Sleep screen message"),
sub_item_table = {
{
text = _("Add custom message to sleep screen"),
checked_func = function()
return G_reader_settings:isTrue("screensaver_show_message")
end,
callback = function()
G_reader_settings:toggle("screensaver_show_message")
end,
separator = true,
},
{
text = _("Edit sleep screen message"),
enabled_func = function()
return G_reader_settings:isTrue("screensaver_show_message")
end,
keep_menu_open = true,
callback = function()
Screensaver:setMessage()
end,
},
{
text = _("Background fill"),
2024-04-09 10:53:30 +00:00
help_text = _("This option will only become available, if you have selected 'Leave screen as-is' as wallpaper and have 'Sleep screen message' on."),
2024-04-08 20:47:17 +00:00
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "disable" and G_reader_settings:isTrue("screensaver_show_message")
end,
sub_item_table = {
genMenuItem(_("Black fill"), "screensaver_msg_background", "black"),
genMenuItem(_("White fill"), "screensaver_msg_background", "white"),
2024-04-09 10:53:30 +00:00
genMenuItem(_("No fill"), "screensaver_msg_background", "none", nil, true),
},
},
{
2024-04-08 20:47:17 +00:00
text = _("Message position"),
enabled_func = function()
return G_reader_settings:isTrue("screensaver_show_message")
end,
sub_item_table = {
2024-04-08 20:47:17 +00:00
genMenuItem(_("Top"), "screensaver_message_position", "top"),
genMenuItem(_("Middle"), "screensaver_message_position", "middle"),
genMenuItem(_("Bottom"), "screensaver_message_position", "bottom", nil, true),
},
},
2024-04-08 20:47:17 +00:00
{
text = _("Hide reboot/poweroff message"),
checked_func = function()
return G_reader_settings:isTrue("screensaver_hide_fallback_msg")
end,
callback = function()
G_reader_settings:toggle("screensaver_hide_fallback_msg")
end,
},
},
},
}