2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/frontend/ui/data/settings_migration.lua
NiLuJe 888d3591b2
Give more control over CRe margins (#4945)
Without having to resort to weird custom defaults.

* Split the current margins setting in three:
  * Horizontal margins (because you generally want those two to be balanced).
  * Top margin & Bottom margin (because you may want to tweak those separately to deal with quirky status bar/final line shenanigans).

* Also, add a "Reclaim bar height from bottom margin" toggle to the status bar menu, to optionally make sure the status bar won't eat into the bottom margin.

* Includes a free fix to diacritics popup refresh handling in the keyboard ;).
2019-05-01 02:09:01 +02:00

41 lines
1.5 KiB
Lua

--[[
Centralizes migration concerns for LuaSettings & DocSettings
--]]
local DocSettings = require("docsettings")
local LuaSettings = require("luasettings")
local logger = require("logger")
local SettingsMigration = {}
-- Shockingly, handles settings migration
-- NOTE: supports LuaSettings & DocSettings objects as input, as both implement the same API
function SettingsMigration:migrateSettings(config)
-- Figure out what kind of object we were passed, to make the logging more precise
local cfg_mt_idx = getmetatable(config).__index
local cfg_class
if cfg_mt_idx == DocSettings then
cfg_class = "book"
elseif cfg_mt_idx == LuaSettings then
cfg_class = "global"
else
-- Input object isn't a supported *Settings class, warn & abort instead of going kablooey.
logger.warn("Passed an unsupported object class to SettingsMigration!")
return
end
-- Fine-grained CRe margins (#4945)
local old_margins = config:readSetting("copt_page_margins")
if old_margins then
logger.info("Migrating old", cfg_class, "CRe margin settings: L", old_margins[1], "T", old_margins[2], "R", old_margins[3], "B", old_margins[4])
-- Format was: {left, top, right, bottom}
config:saveSetting("copt_h_page_margins", {old_margins[1], old_margins[3]})
config:saveSetting("copt_t_page_margin", old_margins[2])
config:saveSetting("copt_b_page_margin", old_margins[4])
-- Wipe it
config:delSetting("copt_page_margins")
end
end
return SettingsMigration