From 079418d3cddb3ef4db4e346183445a47bc0ada48 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Fri, 16 Apr 2021 23:05:06 +0200 Subject: [PATCH] ReaderFooter: Smarter hardware event handlers Make sure we don't repaint the footer over anything else than ReaderUI, as some events are fired without direct UI interaction, so we can't be assured of the actual state of the UI. Fix #7556 Exposed since #7379, but could arguably happen with other existing handlers before. --- frontend/apps/reader/modules/readerfooter.lua | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index ce52a4458..b58f4356e 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -1873,14 +1873,6 @@ function ReaderFooter:onUpdateFooter(force_repaint, force_recompute) end end -function ReaderFooter:onCharging() - self:onUpdateFooter(self.view.footer_visible) -end - -function ReaderFooter:onNotCharging() - self:onUpdateFooter(self.view.footer_visible) -end - function ReaderFooter:updateFooterPage(force_repaint, force_recompute) if type(self.pageno) ~= "number" then return end if self.ui.document:hasHiddenFlows() then @@ -2230,24 +2222,42 @@ function ReaderFooter:onCloseDocument() self:unscheduleFooterAutoRefresh() end +-- Used by event handlers that can trip without direct UI interaction... +function ReaderFooter:maybeUpdateFooter() + -- ...so we need to avoid stomping over unsuspecting widgets (usually, ScreenSaver). + if UIManager:getTopWidget() == "ReaderUI" then + self:onUpdateFooter(self.view.footer_visible) + else + self:onUpdateFooter() + end +end + function ReaderFooter:onFrontlightStateChanged() if self.settings.frontlight then - self:onUpdateFooter(true) + self:maybeUpdateFooter() end end function ReaderFooter:onNetworkConnected() if self.settings.wifi_status then - self:onUpdateFooter(true) + self:maybeUpdateFooter() end end function ReaderFooter:onNetworkDisconnected() if self.settings.wifi_status then - self:onUpdateFooter(true) + self:maybeUpdateFooter() end end +function ReaderFooter:onCharging() + self:maybeUpdateFooter() +end + +function ReaderFooter:onNotCharging() + self:maybeUpdateFooter() +end + function ReaderFooter:onSetRotationMode() self:updateFooterContainer() self:resetLayout(true)