mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
80244ea4e2
Squash of feat/koreader-widget-board. KOReader plugin 2.0.0 gets the widget-board dashboard, redesigned book details, menus, lists and dialogs, Decor page and reading companions. Highlights, notes and bookmarks now stay in step across web, Kobo, KOReader and the phones (defects D-00 to D-20, migration 0121), and reading progress and narration hand off cleanly between devices.
33 lines
1.3 KiB
Lua
33 lines
1.3 KiB
Lua
--[[--
|
|
Dates note edits in the open book.
|
|
|
|
KOReader stamps datetime_updated only when a note save flips an item between
|
|
highlight and note, so rewriting an existing note's text leaves no edit time
|
|
and the next sync can only date it by when it ran: an older offline rewrite
|
|
then beats a later edit made elsewhere. Every note save, from the highlight
|
|
dialog or the bookmark list, ends in ReaderHighlight:writePdfAnnotation
|
|
("content", item, ...), for EPUBs too (it returns early there), so the open
|
|
book's ReaderHighlight is wrapped to stamp the item at that moment.
|
|
]]
|
|
|
|
local BookOrbitNoteStamp = {}
|
|
|
|
local INSTALLED = "_bookorbit_note_stamp"
|
|
|
|
function BookOrbitNoteStamp.install(ui)
|
|
local highlight = ui and ui.highlight
|
|
if type(highlight) ~= "table" or highlight[INSTALLED] then return false end
|
|
local original = highlight.writePdfAnnotation
|
|
if type(original) ~= "function" then return false end
|
|
highlight.writePdfAnnotation = function(self, action, item, content)
|
|
if action == "content" and type(item) == "table" and item.drawer then
|
|
item.datetime_updated = os.date("%Y-%m-%d %H:%M:%S")
|
|
end
|
|
return original(self, action, item, content)
|
|
end
|
|
highlight[INSTALLED] = true
|
|
return true
|
|
end
|
|
|
|
return BookOrbitNoteStamp
|