Fix annotations pushed as empty arrays: merge defaults into stale settings

A device log showed pushes carrying highlights:[] while the document
had highlights — progress synced fine, annotations never moved.

Root cause: G_reader_settings:readSetting(key, default) returns the
STORED table verbatim and does not merge defaults into it. A settings
file saved by an older plugin version has sync_progress=true but no
sync_bookmarks/sync_highlights/sync_notes keys, so all three read as
nil; the 'or' chain in _doUpdateProgress then fell to the else branch
that pushes empty annotation arrays — silently, since progress in the
same request succeeds.

init() now reads into a fresh table, merges any missing
default_settings keys, and persists once (so the settings file and
the menu checkboxes self-heal on first run). Verified in the KOReader
stub harness against the live server with the exact scenario: stale
settings shaped like the device's, one highlight, one local bookmark
list — after init sync_highlights=true, and the pushed request body
contains the highlight (previously empty).
This commit is contained in:
2026-08-19 07:55:42 -04:00
parent 1fe8c73d01
commit 82bb7cfee9
+22 -1
View File
@@ -84,7 +84,28 @@ function Bookhoard:init()
self:updateProgress(false, false) self:updateProgress(false, false)
end end
self.settings = G_reader_settings:readSetting(self.settings_key, self.default_settings) -- readSetting returns the STORED table verbatim when one exists — it
-- does not merge defaults. A settings file saved by an older plugin
-- version lacks the annotation toggles entirely, so sync_bookmarks/
-- highlights/notes read as nil, the "or" in _doUpdateProgress fell
-- through to the else branch, and every push carried EMPTY annotation
-- arrays while progress synced fine. Merge missing defaults (and
-- persist once so the file and the menu checkboxes self-heal).
self.settings = G_reader_settings:readSetting(self.settings_key, {})
if type(self.settings) ~= "table" then
self.settings = {}
end
local settings_merged = false
for key, value in pairs(self.default_settings) do
if self.settings[key] == nil then
self.settings[key] = value
settings_merged = true
end
end
if settings_merged then
G_reader_settings:saveSetting(self.settings_key, self.settings)
logger.info("Bookhoard: merged new default settings (older settings file)")
end
if self.settings.auto_sync if self.settings.auto_sync
and Device:hasSeamlessWifiToggle() and Device:hasSeamlessWifiToggle()