Serve web colors to the device: applied entries take the mapped palette name

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.
This commit is contained in:
2026-08-20 08:42:50 -04:00
parent a0ab354763
commit eec956e681
+22 -9
View File
@@ -1340,15 +1340,22 @@ function Bookhoard:applyServerAnnotations(annotations)
entry.drawer = "lighten" entry.drawer = "lighten"
entry.text = srv_text entry.text = srv_text
if srv_notes ~= "" then entry.note = srv_notes end if srv_notes ~= "" then entry.note = srv_notes end
-- Match the device's native highlight look exactly: native -- Color: the server maps the web color into KOReader's
-- highlights carry view.highlight.saved_color ("yellow" on -- named palette — use it when it arrives as a plain name so
-- color screens); a nil color renders grey (darkenRect). -- synced highlights keep their web color. Anything else
-- Synced entries still never push this color back (see -- (absent, or a raw hex that slipped through) falls back to
-- collectAnnotations) — the web color only changes when the -- the device default (view.highlight.saved_color, "yellow"
-- highlight is edited here. -- on color screens — nil would render grey via darkenRect).
local default_color = (self.ui.view and self.ui.view.highlight -- Echoes of applied entries never push this color back
and self.ui.view.highlight.saved_color) or "yellow" -- (collectAnnotations) unless the user edited them, so the
entry.color = default_color -- 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 else
if srv_text ~= "" then entry.note = srv_text end -- bookmark label if srv_text ~= "" then entry.note = srv_text end -- bookmark label
end end
@@ -1363,6 +1370,12 @@ function Bookhoard:applyServerAnnotations(annotations)
notes = srv_text, notes = srv_text,
text = srv_notes, 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 if server_entry.dedup_key and server_entry.dedup_key ~= "" then
entry.bookhoard_dedup_key = server_entry.dedup_key entry.bookhoard_dedup_key = server_entry.dedup_key
end end