Files
bookorbit/koreader-plugin/bookorbit.koplugin/bookorbit_highlight_diagnostics.lua
T
neon 1c27e5dd05 fix(koreader): keep manual links to a different copy matched and suggest links
Report a linked copy whose bytes differ from the library file as positionIncompatible instead of
unmatched, so the plugin keeps the match, skips highlights without a failure and still syncs progress.
Treat a position-less place within a page as the same place and jump to the nearest page.
Suggest library books with the same title and authors for books to review, with bulk linking.
See docs/KOREADER_HASH_MATCHING.md.

Closes #1872
Closes #1919
2026-10-26 15:06:04 +00:00

90 lines
2.8 KiB
Lua

local T = require("ffi/util").template
local _ = require("gettext")
local HighlightDiagnostics = {}
local function count(value)
value = tonumber(value)
if not value or value < 0 then return 0 end
return value
end
local function hasOpenBook(ctx)
return ctx and ctx.has_open_book == true
end
function HighlightDiagnostics.lastSyncText(summary, format_time)
if type(summary) ~= "table" then return _("never") end
local text = T(_("%1 uploaded, %2 applied, %3 deleted, %4 failed, %5 skipped"),
count(summary.uploaded), count(summary.applied), count(summary.deleted),
count(summary.failed), count(summary.skipped))
if count(summary.incompatible) > 0 then
text = T(_("%1, %2 not synced (different copy)"), text, count(summary.incompatible))
end
local at = tonumber(summary.at)
if at and at > 0 then
local when = format_time and format_time(at) or os.date("%H:%M", at)
text = T(_("%1 at %2"), text, when)
end
return text
end
function HighlightDiagnostics.lastBookmarkSyncText(summary, format_time)
if type(summary) ~= "table" then return _("never") end
local uploaded = count(summary.bm_uploaded)
local applied = count(summary.bm_applied)
local deleted = count(summary.bm_deleted)
local failed = count(summary.bm_failed)
if uploaded + applied + deleted + failed == 0 then return _("none") end
local text = T(_("%1 uploaded, %2 applied, %3 deleted, %4 failed"), uploaded, applied, deleted, failed)
local at = tonumber(summary.at)
if at and at > 0 then
local when = format_time and format_time(at) or os.date("%H:%M", at)
text = T(_("%1 at %2"), text, when)
end
return text
end
function HighlightDiagnostics.retryText(status)
if type(status) == "table" and status.pending then
return _("pending")
end
return _("none")
end
function HighlightDiagnostics.openHighlightsText(ctx)
ctx = ctx or {}
if not ctx.annotation_sync then
return _("two-way sync off")
end
if not hasOpenBook(ctx) then
return _("no reader book")
end
local pending = ctx.scheduler_status
local matched = ctx.matched == true
if matched and ctx.position_incompatible == true then
return _("not synced: this copy differs from BookOrbit's file")
end
if type(pending) == "table" then
if matched then
return _("matched, sync scheduled")
end
if pending.phase == "matching" then
return _("unmatched, retrying match")
end
return _("unmatched, sync scheduled")
end
if matched then
return _("matched, idle")
end
local last = ctx.last_highlight_sync
if type(last) == "table" and count(last.skipped) > 0 then
return _("unmatched, skipped")
end
return _("unmatched, idle")
end
return HighlightDiagnostics