From eec956e6816589f23995b709a880a5ee178c9b16 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Thu, 20 Aug 2026 08:42:50 -0400 Subject: [PATCH] Serve web colors to the device: applied entries take the mapped palette name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Web colors now flow to KOReader instead of every synced highlight rendering in the device default. The server maps the web hex swatch to KOReader's named palette (#ce93d8→purple, #90caf9→blue, #a5d6a7→green, #ffd54f→yellow, pink→purple as the palette's closest); applyServerAnnotations uses the served name when it is a plain color name, falling back to the device default (view.highlight.saved_color) when absent or malformed (hex rejected as belt-and-braces). v1-model entries accept named colors too. Round-trip safety is unchanged: un-edited applied entries still suppress their color on echo (a pink→purple palette mismatch must not rewrite the stored web hex), and a device edit still pushes its color which the server lets win. Verified in the harness: purple applied from a served #ce93d8; unedited echo colorless; edited echo sends its color and updates the web row. --- main.lua | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/main.lua b/main.lua index ce6a066..cf7a6e5 100644 --- a/main.lua +++ b/main.lua @@ -1340,15 +1340,22 @@ function Bookhoard:applyServerAnnotations(annotations) entry.drawer = "lighten" entry.text = srv_text if srv_notes ~= "" then entry.note = srv_notes end - -- Match the device's native highlight look exactly: native - -- highlights carry view.highlight.saved_color ("yellow" on - -- color screens); a nil color renders grey (darkenRect). - -- Synced entries still never push this color back (see - -- collectAnnotations) — the web color only changes when the - -- highlight is edited here. - local default_color = (self.ui.view and self.ui.view.highlight - and self.ui.view.highlight.saved_color) or "yellow" - entry.color = default_color + -- Color: the server maps the web color into KOReader's + -- named palette — use it when it arrives as a plain name so + -- synced highlights keep their web color. Anything else + -- (absent, or a raw hex that slipped through) falls back to + -- the device default (view.highlight.saved_color, "yellow" + -- on color screens — nil would render grey via darkenRect). + -- Echoes of applied entries never push this color back + -- (collectAnnotations) unless the user edited them, so the + -- stored web color never drifts. + local srv_color = server_entry.color or "" + if srv_color ~= "" and not srv_color:find("^#") then + entry.color = srv_color + else + entry.color = (self.ui.view and self.ui.view.highlight + and self.ui.view.highlight.saved_color) or "yellow" + end else if srv_text ~= "" then entry.note = srv_text end -- bookmark label end @@ -1363,6 +1370,12 @@ function Bookhoard:applyServerAnnotations(annotations) notes = srv_text, text = srv_notes, } + if has_text then + local srv_color = server_entry.color or "" + if srv_color ~= "" and not srv_color:find("^#") then + entry.color = srv_color + end + end if server_entry.dedup_key and server_entry.dedup_key ~= "" then entry.bookhoard_dedup_key = server_entry.dedup_key end