mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[feat] Adds Document> Auto-save book metadata sub-menu (#5687)
Replaces DAUTO_SAVE_PAGING_COUNT in defaults.lua with a new option available in menu, that allows setting an interval in minutes instead of a page count.
This commit is contained in:
@@ -345,9 +345,76 @@ if Device:hasKeys() then
|
||||
}
|
||||
end
|
||||
|
||||
-- Auto-save settings: default value, info text and warning, and menu items
|
||||
if G_reader_settings:readSetting("auto_save_settings_interval_minutes") == nil then
|
||||
-- Default to auto save every 15 mn
|
||||
G_reader_settings:saveSetting("auto_save_settings_interval_minutes", 15)
|
||||
end
|
||||
|
||||
local auto_save_help_text = _([[
|
||||
This sets how often to rewrite to disk global settings and book metadata, including your current position and any highlights and bookmarks made, when you're reading a document.
|
||||
|
||||
The normal behavior is to save those only when the document is closed, or your device suspended, or when exiting KOReader.
|
||||
|
||||
Setting it to some interval may help prevent losing new settings/sidecar data after a software crash, but will cause more I/O writes the lower the interval is, and may slowly wear out your storage media in the long run.]])
|
||||
|
||||
-- Some devices with FAT32 storage may not like having settings rewritten too often,
|
||||
-- so let that be known. See https://github.com/koreader/koreader/pull/3625
|
||||
local warn_about_auto_save = Device:isKobo() or Device:isKindle() or Device:isCervantes() or Device:isPocketBook() or Device:isSonyPRSTUX()
|
||||
if warn_about_auto_save then
|
||||
local auto_save_help_warning = _([[Please be warned that on this device, setting a low interval may exacerbate the potential for filesystem corruption and complete data loss after a hardware crash.]])
|
||||
auto_save_help_text = auto_save_help_text .. "\n\n" .. auto_save_help_warning
|
||||
end
|
||||
|
||||
local function genAutoSaveMenuItem(value)
|
||||
local setting_name = "auto_save_settings_interval_minutes"
|
||||
local text
|
||||
if not value then
|
||||
text = _("Only on close, suspend and exit")
|
||||
else
|
||||
text = T(_("Every %1 mn"), value)
|
||||
end
|
||||
return {
|
||||
text = text,
|
||||
help_text = auto_save_help_text,
|
||||
checked_func = function()
|
||||
return G_reader_settings:readSetting(setting_name) == value
|
||||
end,
|
||||
callback = function()
|
||||
G_reader_settings:saveSetting(setting_name, value)
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
common_settings.document = {
|
||||
text = _("Document"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text_func = function()
|
||||
local interval = G_reader_settings:readSetting("auto_save_settings_interval_minutes")
|
||||
local s_interval
|
||||
if interval == false then
|
||||
s_interval = "only on close"
|
||||
else
|
||||
s_interval = T(_("every %1 mn"), interval)
|
||||
end
|
||||
return T(_("Auto-save book metadata: %1"), s_interval)
|
||||
end,
|
||||
help_text = auto_save_help_text,
|
||||
sub_item_table = {
|
||||
genAutoSaveMenuItem(false),
|
||||
genAutoSaveMenuItem(5),
|
||||
genAutoSaveMenuItem(15),
|
||||
genAutoSaveMenuItem(60),
|
||||
warn_about_auto_save and {
|
||||
text = _("Important info about this auto-save option"),
|
||||
keep_menu_open = true,
|
||||
callback = function()
|
||||
UIManager:show(InfoMessage:new{ text = auto_save_help_text, })
|
||||
end,
|
||||
} or nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
text = _("Save document (write highlights into PDF)"),
|
||||
sub_item_table = {
|
||||
|
||||
Reference in New Issue
Block a user