PowerD: Prevent potential dependency loop in get*Capacity

Not currently happening in vanilla code, but, not entirely unlikely.
stateChanged already uses a similar guard.

Re https://github.com/koreader/koreader/pull/8672#discussion_r790126388
pull/8721/head
NiLuJe 2 years ago committed by Frans de Jonge
parent d7c00c586f
commit 689ec2a839

@ -150,10 +150,15 @@ function BasePowerD:setIntensity(intensity)
end
function BasePowerD:getCapacity()
-- NOTE: UIManager *should* be loaded at this point.
-- If that doesn't hold, c.f., :stateChanged below.
local UIManager = require("ui/uimanager")
local now_ts = UIManager:getTime()
-- BasePowerD is loaded before UIManager.
-- Nothing *currently* calls this before UIManager is actually loaded, but future-proof this anyway.
local now_ts
if package.loaded["ui/uimanager"] ~= nil then
local UIManager = require("ui/uimanager")
now_ts = UIManager:getTime()
else
now_ts = TimeVal:now()
end
if (now_ts - self.last_aux_capacity_pull_time):tonumber() >= 60 then
self.batt_capacity = self:getCapacityHW()
@ -167,8 +172,13 @@ function BasePowerD:isCharging()
end
function BasePowerD:getAuxCapacity()
local UIManager = require("ui/uimanager")
local now_ts = UIManager:getTime()
local now_ts
if package.loaded["ui/uimanager"] ~= nil then
local UIManager = require("ui/uimanager")
now_ts = UIManager:getTime()
else
now_ts = TimeVal:now()
end
if (now_ts - self.last_aux_capacity_pull_time):tonumber() >= 60 then
local aux_batt_capa = self:getAuxCapacityHW()

Loading…
Cancel
Save