LuaSettings: Add a method to initialize a setting properly (#7371)

* LuaSettings/DocSettings: Updated readSetting API to allow proper initialization to default.
Use it to initialize tables, e.g., fixing corner-cases in readerFooter that could prevent settings from being saved.
(Fixes an issue reported on Gitter).
* LuaSettings/DocSettings: Add simpler API than the the flip* ones to toggle boolean settings.
* Update LuaSettings/DocSettigns usage throughout the codebase to use the dedicated boolean methods wher appropriate, and clean up some of the more mind-bending uses.
* FileChooser: Implement an extended default exclusion list (fix #2360)
* ScreenSaver: Refactor to avoid the pile of kludges this was threatening to become. Code should be easier to follow and use, and fallbacks now behave as expected (fix #4418).
This commit is contained in:
NiLuJe
2021-03-06 22:44:18 +01:00
committed by GitHub
parent 15ef1a3a1b
commit bf6c0cdd6c
78 changed files with 1424 additions and 1218 deletions

View File

@@ -387,7 +387,7 @@ local ReaderFooter = WidgetContainer:extend{
}
function ReaderFooter:init()
self.settings = G_reader_settings:readSetting("footer") or {
self.settings = G_reader_settings:readSetting("footer", {
-- enable progress bar by default
-- disable_progress_bar = true,
disabled = false,
@@ -414,7 +414,7 @@ function ReaderFooter:init()
text_font_bold = false,
container_height = DMINIBAR_CONTAINER_HEIGHT,
container_bottom_padding = 1, -- unscaled_size_check: ignore
}
})
-- Remove items not supported by the current device
if not Device:hasFastWifiStatusQuery() then
@@ -889,7 +889,6 @@ function ReaderFooter:addToMainMenu(menu_items)
end,
callback = function()
self.settings[option] = not self.settings[option]
G_reader_settings:saveSetting("footer", self.settings)
-- We only need to send a SetPageBottomMargin event when we truly affect the margin
local should_signal = false
-- only case that we don't need a UI update is enable/disable
@@ -976,7 +975,6 @@ function ReaderFooter:addToMainMenu(menu_items)
self.mode_index[i] = sort_item.item_table[i].label
end
self.settings.order = self.mode_index
G_reader_settings:saveSetting("footer", self.settings)
self:updateFooterTextGenerator()
self:onUpdateFooter()
UIManager:setDirty(nil, "ui")
@@ -994,7 +992,6 @@ function ReaderFooter:addToMainMenu(menu_items)
end,
callback = function()
self.settings.auto_refresh_time = not self.settings.auto_refresh_time
G_reader_settings:saveSetting("footer", self.settings)
self:rescheduleFooterAutoRefreshIfNeeded()
end
},
@@ -1035,7 +1032,6 @@ function ReaderFooter:addToMainMenu(menu_items)
end,
callback = function()
self.settings.skim_widget_on_hold = not self.settings.skim_widget_on_hold
G_reader_settings:saveSetting("footer", self.settings)
end,
},
{
@@ -1857,7 +1853,7 @@ function ReaderFooter:getAvgTimePerPage()
end
function ReaderFooter:getDataFromStatistics(title, pages)
local sec = "N/A"
local sec = _("N/A")
local average_time_per_page = self:getAvgTimePerPage()
if average_time_per_page then
if self.settings.duration_format == "classic" then
@@ -2065,9 +2061,9 @@ end
function ReaderFooter:onReadSettings(config)
if not self.ui.document.info.has_pages then
local h_margins = config:readSetting("copt_h_page_margins") or
G_reader_settings:readSetting("copt_h_page_margins") or
DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
local h_margins = config:readSetting("copt_h_page_margins")
or G_reader_settings:readSetting("copt_h_page_margins")
or DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
self.book_margins_footer_width = math.floor((h_margins[1] + h_margins[2])/2)
end
end