From 6c2d5c66da087c82516c0fe4ca2a17fb6abf9001 Mon Sep 17 00:00:00 2001 From: melyux <10296053+melyux@users.noreply.github.com> Date: Mon, 12 Dec 2022 09:22:48 -0800 Subject: [PATCH] Add linear flow wisdom to screensaver message magic variables (#9905) If there are hidden flows, this calculates the current page, total pages, percent, time left in chapter, and time left in the magic variables used in screensaver message only for the current flow. If there are no hidden flows, the behavior is the same as before. --- frontend/ui/screensaver.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/ui/screensaver.lua b/frontend/ui/screensaver.lua index a23c5bd5c..95b95073c 100644 --- a/frontend/ui/screensaver.lua +++ b/frontend/ui/screensaver.lua @@ -170,8 +170,18 @@ function Screensaver:expandSpecial(message, fallback) if ui and ui.document then -- If we have a ReaderUI instance, use it. local doc = ui.document - currentpage = ui.view.state.page or currentpage - totalpages = doc:getPageCount() or totalpages + if doc:hasHiddenFlows() then + local currentpageAll = ui.view.state.page or currentpage + currentpage = doc:getPageNumberInFlow(ui.view.state.page or currentpageAll) + totalpages = doc:getTotalPagesInFlow(doc:getPageFlow(currentpageAll)) + time_left_chapter = self:_calcAverageTimeForPages(ui.toc:getChapterPagesLeft(currentpageAll) or (totalpages - currentpage)) + time_left_document = self:_calcAverageTimeForPages(totalpages - currentpage) + else + currentpage = ui.view.state.page or currentpage + totalpages = doc:getPageCount() or totalpages + time_left_chapter = self:_calcAverageTimeForPages(ui.toc:getChapterPagesLeft(currentpage) or doc:getTotalPagesLeft(currentpage)) + time_left_document = self:_calcAverageTimeForPages(doc:getTotalPagesLeft(currentpage)) + end percent = Math.round((currentpage * 100) / totalpages) local props = doc:getProps() if props then @@ -179,8 +189,6 @@ function Screensaver:expandSpecial(message, fallback) authors = props.authors and props.authors ~= "" and props.authors or authors series = props.series and props.series ~= "" and props.series or series end - time_left_chapter = self:_calcAverageTimeForPages(ui.toc:getChapterPagesLeft(currentpage) or doc:getTotalPagesLeft(currentpage)) - time_left_document = self:_calcAverageTimeForPages(doc:getTotalPagesLeft(currentpage)) elseif DocSettings:hasSidecarFile(lastfile) then -- If there's no ReaderUI instance, but the file has sidecar data, use that local docinfo = DocSettings:open(lastfile)