From 82bb7cfee9c11ccfe50078cd99a13565a5527d66 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 19 Aug 2026 07:55:42 -0400 Subject: [PATCH] Fix annotations pushed as empty arrays: merge defaults into stale settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- main.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.lua b/main.lua index a7839f5..ca277da 100644 --- a/main.lua +++ b/main.lua @@ -84,7 +84,28 @@ function Bookhoard:init() self:updateProgress(false, false) 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 and Device:hasSeamlessWifiToggle()