From 1c9e21389d88175f02c3203c459a3b96416d5fbe Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Tue, 23 Nov 2021 02:11:07 +0200 Subject: [PATCH] Backup and restore bookmarks/highlights: fix logic (#8473) --- frontend/apps/reader/modules/readerbookmark.lua | 13 +++++++++++-- frontend/apps/reader/modules/readerview.lua | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/frontend/apps/reader/modules/readerbookmark.lua b/frontend/apps/reader/modules/readerbookmark.lua index b99ffc1ac..759510f09 100644 --- a/frontend/apps/reader/modules/readerbookmark.lua +++ b/frontend/apps/reader/modules/readerbookmark.lua @@ -268,17 +268,26 @@ function ReaderBookmark:onReadSettings(config) -- Bookmark formats in crengine and mupdf are incompatible. -- Backup bookmarks when the document is opened with incompatible engine. if #self.bookmarks > 0 then - if self.ui.rolling and type(self.bookmarks[1].page) == "number" then + local bookmarks_type = type(self.bookmarks[1].page) + if self.ui.rolling and bookmarks_type == "number" then config:saveSetting("bookmarks_paging", self.bookmarks) self.bookmarks = config:readSetting("bookmarks_rolling", {}) config:saveSetting("bookmarks", self.bookmarks) config:delSetting("bookmarks_rolling") - elseif self.ui.paging and type(self.bookmarks[1].page) == "string" then + elseif self.ui.paging and bookmarks_type == "string" then config:saveSetting("bookmarks_rolling", self.bookmarks) self.bookmarks = config:readSetting("bookmarks_paging", {}) config:saveSetting("bookmarks", self.bookmarks) config:delSetting("bookmarks_paging") end + else + if self.ui.rolling and config:has("bookmarks_rolling") then + self.bookmarks = config:readSetting("bookmarks_rolling") + config:delSetting("bookmarks_rolling") + elseif self.ui.paging and config:has("bookmarks_paging") then + self.bookmarks = config:readSetting("bookmarks_paging") + config:delSetting("bookmarks_paging") + end end -- need to do this after initialization because checking xpointer -- may cause segfaults before credocuments are inited. diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 52e6f3689..1215ae135 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -792,18 +792,28 @@ function ReaderView:onReadSettings(config) self.highlight.saved = config:readSetting("highlight", {}) -- Highlight formats in crengine and mupdf are incompatible. -- Backup highlights when the document is opened with incompatible engine. - if #self.highlight.saved > 0 then - if self.ui.rolling and type(self.highlight.saved[1][1].pos0) == "table" then + local _page, page_highlights = next(self.highlight.saved) + if page_highlights then + local highlight_type = type(page_highlights[1].pos0) + if self.ui.rolling and highlight_type == "table" then config:saveSetting("highlight_paging", self.highlight.saved) self.highlight.saved = config:readSetting("highlight_rolling", {}) config:saveSetting("highlight", self.highlight.saved) config:delSetting("highlight_rolling") - elseif self.ui.paging and type(self.highlight.saved[1][1].pos0) == "string" then + elseif self.ui.paging and highlight_type == "string" then config:saveSetting("highlight_rolling", self.highlight.saved) self.highlight.saved = config:readSetting("highlight_paging", {}) config:saveSetting("highlight", self.highlight.saved) config:delSetting("highlight_paging") end + else + if self.ui.rolling and config:has("highlight_rolling") then + self.highlight.saved = config:readSetting("highlight_rolling") + config:delSetting("highlight_rolling") + elseif self.ui.paging and config:has("highlight_paging") then + self.highlight.saved = config:readSetting("highlight_paging") + config:delSetting("highlight_paging") + end end self.inverse_reading_order = config:isTrue("inverse_reading_order") or G_reader_settings:isTrue("inverse_reading_order") self.page_overlap_enable = config:isTrue("show_overlap_enable") or G_reader_settings:isTrue("page_overlap_enable") or DSHOWOVERLAP